How to use the BlackIceDEVMODE.dll

 

The BlackIceDEVMODE.DLL can be linked statically or dynamically.

For a static link, use the BlackIceDEVMODE.lib file. For a dynamic link, load the library with the LoadLibrary() API function and then use the GetProcAddress() API function to load the required functions from the BlackIceDEVMODE.DLL. There is a C++ and a C# example available below how to us the BlackIceDEVMODE.dll.

 

How to use the BlackIceDEVMODE.dll in general

 

- Load Black Ice Devmode with Black Ice Printer Name Return function Devmode

            Example Devmode = LoadBlackIceDEVMODE(Black Ice Printer Name)

 

- Use other Black Ice Devmode function with this Devmode

            Example: - GetBarCodeAlign(Devmode)

             - GetDRatio(Devmode)

             - GetPagePhysicalOffsetY(Devmode)

              ….

 

- Save Black Ice Devmode with Black Ice Printer Name and Devmode

            Example SaveBlackIceDEVMODE(Black Ice Printer Name, Devmode)

 

- Unload Black Ice Devmode

            Example ReleaseBlackIceDEVMODE(Devmode)

 

 

How to use the BlackIceDEVMODE.dll in C++

 

/* retrieve a function address from the DLL */

BOOL InitDll()

{

 HMODULE hDLL;

 hDLL = LoadLibrary( DLL_PATH);

 if (hDLL)

 {

            GetOrientation = (_GetOrientation)GetProcAddress(hDLL,szGetOrientation);

            if (!GetOrientation)

{

                        AfxMessageBox(TEXT("Error loading function"),MB_OK,0);

                        return FALSE;

            }

}

 

/* declare a pointer to the BlackIceDEVMODE structure. The LoadBlackIceDEVMODE() function will allocate the required amount of memory for the pointer. */

 

BlackIceDEVMODE* pDevMode;

 

/* Before using other functions, load the DevMode from the printer with the  LoadBlackIceDEVMODE() function. */

 

pDevMode = LoadBlackIceDEVMODE(TEXT(“Black Ice Color”));

 

if (!pDevMode) {

            wsprintf(szMessage, TEXT(

                        "Error loading the devmode. Error no.: %d ),

                        BlackIce_GetLastError());

            AfxMessageBox(szMessage,MB_OK,0);

            return(0);

}

if (!GetOrientation)

{

            AfxMessageBox(TEXT("Function not loaded from the DLL"),MB_OK,0);

}

else

{

            if( GetOrientation(pDevMode) == 1)

{

                        // Portrait

}

            else

            {

if( GetOrientation(pDevMode) == 2)

{

                        // Landscape

)

else

{

// wrong value;

}

            }

}

 

/* To save the printer settings call SaveBlackIceDEVMODE function. */

 

bSuccess = SaveBlackIceDEVMODE(TEXT(“Black Ice Color”), pDevMode);

if (!bSuccess)

{

wsprintf(szMessage, TEXT("Error saving the devmode. Error no.: %d"), BlackIce_GetLastError());

            AfxMessageBox(szMessage,MB_OK,0);

}

 

/* At the end you should release the DEVMODE buffer allocated by the LoadBlackIceDEVMODE() function. You can use the ReleaseBlackIceDEVMODE function */

 

ReleaseBlackIceDEVMODE(pDevMode);

How to use the BlackIceDEVMODE.dll in C#

IMPORT BlackIceDEVMODE.dll function in your C# code:

Example:

 

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

private static extern IntPtr LoadBlackIceDEVMODE(string Printer);

 

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

private static extern bool ApplyProfileFile(string Printerstring ProfileIntPtr  Devmode);

 

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

private static extern bool SaveBlackIceDEVMODE(string PrinterIntPtr  Devmode);

 

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

private static extern bool ReleaseBlackIceDEVMODE(IntPtr  Devmode);

 

USE BlackIceDEVMODE.dll function in your C# code

 

1: Load BlackIceDEVMODE

    IntPtr  Devmode = LoadBlackIceDEVMODE("Printer Name");

    Pointer to the BlackIceDEVMODE structure or NULL if loading the DEVMODE has failed. 

 

2: One BlackIceDEVMODE

   Example:

            bool result = ApplyProfileFile("Printer Name""Path to the profile file"Devmode);

       True on Success, otherwise false

 

3: Save BlackIceDEVMODE

  bool result = SaveBlackIceDEVMODE(("Printer Name"Devmode);

            TRUE if the DEVMODE was successfully updated, otherwise FALSE. 

 

4: Release BlackIceDEVMODE

  bool result = ReleaseBlackIceDEVMODE(Devmode);

            True on Success unloading the devmode

            False on Error unloading the devmode

 

 

IMPORT BlackIceDEVMODE.dll function in your VB.net code:

Example:

 

<DllImport("BlackIceDEVMODE.dll", EntryPoint := "LoadBlackIceDEVMODE", CharSet := CharSet.Unicode)> _

Private Shared Function LoadBlackIceDEVMODE(ByVal Printer As String) As IntPtr

End Function

 

<DllImport("BlackIceDEVMODE.dll", EntryPoint := "ApplyProfileFile", CharSet := CharSet.Unicode)> _

Private Shared Function ApplyProfileFile(ByVal Printer As String, ByVal Profile As String, ByVal Devmode As IntPtr) As Boolean

End Function

 

<DllImport("BlackIceDEVMODE.dll", EntryPoint := "SaveBlackIceDEVMODE", CharSet := CharSet.Unicode)> _

Private Shared Function SaveBlackIceDEVMODE(ByVal Printer As String, ByVal Devmode As IntPtr) As Boolean

End Function

 

<DllImport("BlackIceDEVMODE.dll", EntryPoint := "ReleaseBlackIceDEVMODE", CharSet := CharSet.Unicode)> _

Private Shared Function ReleaseBlackIceDEVMODE(ByVal Devmode As IntPtr) As Boolean

End Function

 

USE BlackIceDEVMODE.dll function in your VB.NET code

 

1: Load BlackIceDEVMODE

    Dim Devmode As IntPtr = LoadBlackIceDEVMODE("Printer Name")

    Pointer to the BlackIceDEVMODE structure or NULL if loading the DEVMODE has failed. 

 

2: One BlackIceDEVMODE

   Example:

            Dim result As Boolean = ApplyProfileFile("Printer Name", "Path to the profile file", Devmode)

                        True on Success, otherwise false

 

3: Save BlackIceDEVMODE

  Dim result As Boolean = SaveBlackIceDEVMODE("Printer Name", Devmode)

            True on Success saving the devmode

            False on Error saving the devmode

 

4: Release BlackIceDEVMODE

  Dim result As Boolean = ReleaseBlackIceDEVMODE(Devmode)

            True on Success unloading the devmode

            False on Error unloading the devmode