I've got an old app that I need to get to print in landscape mode. The documentation I've found says to get a DEVMODE structure, change a couple of fields, and put it back in. What I've got is:
HANDLE printer_handle;
LPHANDLE printer_handle_pointer(&printer_handle);
OpenPrinter(printer_name.get(), printer_handle_pointer, NULL);
size_t devmode_size = DocumentProperties(hWnd, printer_handle_pointer, printer_name.get(), NULL, NULL, 0);
DEVMODE * devmode = reinterpret_cast<DEVMODE *>(new char[devmode_size]);
DocumentProperties(NULL, printer_handle_pointer, printer_name.get(), devmode, NULL, DM_OUT_BUFFER);
devmode->dmSize = sizeof( DEVMODE);
devmode->dmFields |= DM_ORIENTATION;
devmode->dmOrientation = DMORIENT_LANDSCAPE;
DocumentProperties(NULL, printer_handle_pointer, printer_name.get(), devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER);
hdcPrint = CreateDC(NULL, printer_name.get(), NULL, devmode);
My current problem is that the first DocumentProperties (the one that returns the size of the DEVMODE structure) is returning a -1 (actually the unsigned equivalent), signifying an error condition. This happens in both Debug and Release mode (one report I saw on the web had this problem in Debug but not Release). The printer_name.get()
is valid, but I don't know how to check the hWnd
or printer_handle_pointer
for correctness in the debugger.
So, I'd like it if somebody could tell me what I'm doing wrong, or how to diagnose it better, or how to tell if the handles are valid and point to valid information, I'd appreciate it.
I'm using VS 2008SP1 on Vista Business SP1, if that makes any difference. The original app was written with an earlier version of VS on some version of XP.