I am getting a system error when trying to display the printer dialog. The WxWdigets sample printing program works just fine.
System build environment:
Windows 10.
WxWidgets 3.1.3.
64 bit VS2019 build.
I basically copied the code from the sample program into my program.
This code is in my App Class OnInit function.
Code: Select all
wxInitAllImageHandlers();
// init global objects
g_printData = new wxPrintData;
// You could set an initial paper size here
#if 0
g_printData->SetPaperId(wxPAPER_LETTER); // for Americans
g_printData->SetPaperId(wxPAPER_A4); // for everyone else
#endif
g_pageSetupData = new wxPageSetupDialogData;
// copy over initial paper size from print record
(*g_pageSetupData) = *g_printData;
// Set some initial page margins in mm.
g_pageSetupData->SetMarginTopLeft(wxPoint(10, 10));
g_pageSetupData->SetMarginBottomRight(wxPoint(10, 10));
Code: Select all
wxPrintDialogData printDialogData(* g_printData);
wxPrinter printer(&printDialogData);
MyPrintout printout(this, "My printout");
// if (!printer.Print(this, &printout, false /*prompt*/))
if (!printer.Print(this, &printout, true /*prompt*/))
{
if (wxPrinter::GetLastError() == wxPRINTER_ERROR)
{
wxLogError("There was a problem printing. Perhaps your current printer is not set correctly?");
}
else
{
wxLogMessage("You canceled printing");
}
}
else
{
(*g_printData) = printer.GetPrintDialogData().GetPrintData();
}
wxPrinter::getLAstError() returns 1 and the "You Canceled Printing" message is displayed.
If I call printer.Print() with the prompt parameter set to false, the document prints to the default printer without a problem,
Interestingly, the dialog displays properly on a Windows 7 machine. I tested it on 4 Windows 10 machines and they all throw the system error.
I think I am not initializing something properly either in the code or in the project settings, but I have scoured each and cannot find a difference.
Any advice is greatly appreciated.
Thanks,
Al