SaveDefaultBlackIceDEVMODE

 

#include “BlackIceDEVMODE.h”

 

BOOL   SaveDefaultBlackIceDEVMODE(LPWSTR szPrinterName, BlackIceDEVMODE* pDevMode);

Description

Use this function to save the new printer driver settings for all users. You must call the ClearUserSettings function first to clear and define which user setting will be changed. The bAllUser parameter defines if the changing of the DEVMODE will be applied for all users or just for the current user.

 

NOTE:  The SaveDefaultBlackIceDEVMODE function overwrites the system default printer settings, however, the system default printer settings are only used if the user had not changed the printer settings yet. If the user has changed the printer settings, then the new printer driver settings will not be applied to the given user.

 

To change the settings for the current user, please also call the SaveBlackIceDEVMODE function.

Parameters

LPWSTR szPrinterName                          - Printer Name (string).

BlackIceDEVMODE* pDevMode                         - Pointer to the BlackIceDEVMODE structure.

Return value

TRUE if the DEVMODE was successfully updated, otherwise FALSE.

Programming Notes

None

Code Example

None

Using the BlackIceDEVMODE.dll with applications configured for “Multi-Byte Character Set” (ANSI)

The DEVMODE structure returned and used by the BlackIceDEVMODE.dll functions is always Unicode. Internally, the BlackIceDEVMODE.dll uses Unicode. The ANSI functions (functions with a name ending with ‘A’) in the DLL convert the string parameters to Unicode and call the Unicode version of the function, but the DEVMODE structure is kept Unicode for efficiency reasons and to prevent data loss. When passing a DEVMODE structure returned by one of the functions in BlackIceDEVMODE.dll to WinAPI functions, the Unicode version of the WinAPI functions must be used.  You can use the Unicode version of WinAPI functions even if your application is not compiled to Unicode, by appending a ‘W’ character to the end of the WinAPI function name. For example, to call the Unicode version of CreateDC , you can use the CreateDCW function. To convert the printer name or other strings to Unicode, you can use the MultiByteToWideChar WinAPI function.

 

Sample Code:

 

       charszPrinterName[256] = "Black Ice ColorPlus";

       WCHAR szPrinterNameUnicode[256];

       MultiByteToWideChar(CP_ACP, 0, szPrinterName, -1, szPrinterNameUnicode, 256);

 

       HANDLE hPrinter = NULL;

       PRINTER_DEFAULTSW pd = { NULL, NULL, PRINTER_ALL_ACCESS };

      

       if(OpenPrinterW(szPrinterNameUnicode, &hPrinter, &pd))

       {

              LPBlackIceDEVMODE lpDevMode = LoadBlackIceDEVMODE(szPrinterName);

              if(lpDevMode == NULL)

              {

                     ClosePrinter(hPrinter);

                     return FALSE;

              }

 

              // Setting TIFF Group 4, 1 bit output for example

              SetFileFormat(FFR_TIFF_G4, lpDevMode);   // FFR_TIFF_G4 = 7

              SetColorDepth(BITS_1, lpDevMode);        // BITS_1 = 0

 

              HDChDC = CreateDCW(L"WINSPOOL", szPrinterNameUnicode, NULL, (DEVMODEW*)lpDevMode);

              if(hDC == NULL)

              {

                     ClosePrinter(hPrinter);

                     return FALSE;

              }

 

              ...