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 Printer, string Profile, IntPtr  Devmode);

 

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

private static extern bool SaveBlackIceDEVMODE(string Printer, IntPtr  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");

  True on Success load devmode

  False on Error load devmode

 

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 on Success saving the devmode

            False on Error saving the devmode

 

4: Release BlackIceDEVMODE

  bool result = ReleaseBlackIceDEVMODE(Devmode);

            True on Success unloading the devmode

            False on Error unloading the devmode