Saving printer properties in XE4 c++ VCL application

157 views Asked by At

I am trying to save some of the printer properties (ie page size) to an ini file in the following way:

    Printer()->PrinterIndex = Printer()->PrinterIndex;    

    wchar_t printerDevice[256], printerDriver[256], printerPort[256];
    THandle printerDeviceModeHandle = 0;
    DEVMODE *printerDeviceMode;

    Printer()->GetPrinter(printerDevice, printerDriver, printerPort, printerDeviceModeHandle);

    if (printerDeviceModeHandle != 0)
    {

        DEVMODE *printerDeviceMode = (DEVMODE *) GlobalLock((void *)printerDeviceModeHandle);

        if ((printerDeviceMode != NULL) && (printerDeviceMode->dmFields & DM_PAPERSIZE))                
            ini->WriteInteger("PrintingPage", "PaperSize", printerDeviceMode->dmPaperSize);

        GlobalUnlock((void *)printerDeviceModeHandle);
    }

The code gets within the inner if statement but When I inspect the printerDeviceMode variable only the dmDeviceName appears to be correct. Many of the other settings appear to be garbage (including dmPaperSize):

Image of debug inspector window for printerDeviceMode

Note that dmSize is 0.

I have tried changing the page size for the printer using a TPrinterSetupDialog components but the value of dmPaperSize stays the same.

Have I missed a step somewhere?

This is a XE4 c++ builder VCL project.

0

There are 0 answers