Creating Web Application using the BlackIceDEVMODE.dll

 

Using the BlackIceDEVMODE.dll components in a web application provides full control over Black Ice Printer Drivers and gives the capability to change printer settings using the Black Ice Printer Driver API function calls.

 

An Administrator account or user account with administrative privileges is recommended.

 

To ensure that the web application runs under an Administrator account in IIS Manager, follow the steps below:

 

Open Internet Information Service (IIS) Manager from Start menu.

Click on the Application pools in the left side of the IIS Manager.

Select the Application pool which is used for the service

Select Advanced Settings… options on the right side.

 

 

Locate the Identity, and make sure it’s configured to the Administrator, or an account with administrative privileges.

Locate the Load User Profile and change it to True.

 

 

Save the settings and restart the Application Pool to apply the changes.

 

Configuring the webpage

 

To create and configure an ASP.NET webpage with C# code to use the BlackIceDEVMODE.dll, please perform the following steps:

 

1.    Copy the 64 bit version of BlackIceDEVMODE.dll to C:\Windows\System32

2.    Copy the 32 bit version of BlackIceDEVMODE.dll to C:\Windows\SysWOW64

3.    Create a new ASP.NET webpage in the wwwroot directory.

 

The website must include the following components in the website’s directory:

 

Print.aspx.cs

Print.aspx

index.html

web.config

 

The index.html file must include the following content:

 

<html>

<body>

<form method="GET" enctype="multipart/form-data" action = "Print.aspx" >

<input name="action" type="hidden" value="print">

<input type="submit" value="Print">

</form>

</body>

</html>

 

Print.aspx.cs file must include the following code:

Make sure that in the Print.aspx.cs file the printer name is correct (it is set to “Black Ice PDF X1 (Demo)” by default).

 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Collections.Specialized;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using Microsoft.Win32;

using System.Runtime.InteropServices;

 

public partial class Print : System.Web.UI.Page

{

    [DllImport("BlackIceDEVMODE.dll", EntryPoint = "LoadBlackIceDEVMODE", CharSet = CharSet.Unicode)]

    private static extern IntPtr LoadBlackIceDEVMODE(string szPrinter);

 

    [DllImport("BlackIceDEVMODE.dll", EntryPoint = "BlackIce_GetLastError")]

    private static extern uint BlackIce_GetLastError();

 

    protected void Page_Load(object sender, EventArgs e)

    {

        //Defining return string variable.

        string result = "";

 

        string action = Request.Form["action"];

 

        if (action == "print")

        {

            IntPtr pDevMode = LoadBlackIceDEVMODE("Black Ice PDF X1 (Demo)");

            result += "pDevMode: " + pDevMode.ToString() + "<br>\n";

           

            uint err = BlackIce_GetLastError();

            result += "error: " + err.ToString() + "<br>\n";

        }

 

        //Displaying the HTML on the client with the return string.

        divContent.InnerHtml = result;

    }

}

 

Print.aspx must include the following code:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Print.aspx.cs" Inherits="Print" %>

      

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Print Sample</title>

</head>

<body>

      

    <div id="divContent" runat="server">>

Print Test.

    </div>

      

</body>

</html>

 

Web.config file must include the following content:

 

<!-- Web.Config Configuration File -->

 

<configuration>

    <system.web>

        <customErrors mode="Off"/>

    </system.web>

</configuration>

 

4.    Restart the server, load the webpage from a browser, print on the Print button and see if it is able to load the BlackIceDEVMODE.dll correctly.

 

The page shows the values returned by the LoadBlackiceDEVMODE and the BlackIce_GetLastError functions. LoadBlackiceDEVMODE should return a non-zero value and BlackIce_GetLastError should return 0.