+ if (m_devMode)
+ return;
+
+ LPTSTR szPrinterName = wxMSW_CONV_LPTSTR(printerName);
+
+ // From MSDN: How To Modify Printer Settings with the DocumentProperties() Function
+ // The purpose of this is to fill the DEVMODE with privdata from printer driver.
+ // If we have a printer name and OpenPrinter successfully returns
+ // this replaces the PrintDlg function which creates the DEVMODE filled only with data from default printer.
+ if ( !m_devMode && !printerName.IsEmpty() )
+ {
+ // Open printer
+ if ( printer && printer->Open( printerName ) == TRUE )
+ {
+ DWORD dwNeeded, dwRet;
+
+ // Step 1:
+ // Allocate a buffer of the correct size.
+ dwNeeded = DocumentProperties( NULL,
+ *printer, // Handle to our printer.
+ szPrinterName, // Name of the printer.
+ NULL, // Asking for size, so
+ NULL, // these are not used.
+ 0 ); // Zero returns buffer size.
+
+ LPDEVMODE tempDevMode = static_cast<LPDEVMODE>( GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, dwNeeded ) );
+
+ // Step 2:
+ // Get the default DevMode for the printer
+ dwRet = DocumentProperties( NULL,
+ *printer,
+ szPrinterName,
+ tempDevMode, // The address of the buffer to fill.
+ NULL, // Not using the input buffer.
+ DM_OUT_BUFFER ); // Have the output buffer filled.
+
+ if ( dwRet != IDOK )
+ {
+ // If failure, cleanup
+ GlobalFree( tempDevMode );
+ printer->Close();
+ }
+ else
+ {
+ m_devMode = tempDevMode;
+ tempDevMode = NULL;
+ }
+ }
+ }
+
+ if ( !m_devMode )