1

I am working on a project where I need to program for print operations from device. It has WIN CE 6.0. I am using Visual Studio 2005 (MFC). The printer can be any PCL-compatible printer.

Currently, to get printer DC, I am using CreateDC().

hPrinterDC = CreateDC(L"PCL.DLL", L"Any Name", L"LPT1", NULL);

Using this call I am able to print successfully. Here I am passing DEVMODE specific input parameter as NULL. But for having finer control over these print operations, I need to pass DEVMODE information to CreateDC().

For that I am planning to make a call to CreateDC() as specified above to generate DEVMODE specific information in the registry. I can then read this DEVMODE data from registry into local variable, modify only necessary fields of this variable, and pass this variable to CreateDC() to get printer DC for actual print operations to follow.

I am avoiding direct initialization of DEVMODE struct, as I don't have enough information about certain fields of DEVMODE e.g. dmDriverExtra.

I need to know how can I safely read a struct like DEVMODE from registry? Any relative example will be really helpful.

Kind Regards, Aftab

Aftab
  • 53
  • 5
  • Any direct DEVMODE initialization related information can also be of great help. I am particularly interested in dmDriverExtra field (and the Driver-specific data that follows DEVMODE, if required). – Aftab Jul 01 '12 at 05:16

1 Answers1

0

This is ancient, but just in case someone finds this still useful.

The DEVMODE contains private and public area, so allocating it with size equal to sizeof(DEVMODE) will exclude some settings. Proper way to initialize the DEVMODE is to query its default state using DocumentProperties() function. It returns number of bytes required when last parameter is set to zero.