Fix possible crash in wxWindowsPrintNativeData initialization
If the printer name is specified, avoid fall back to the default printer via the use of PRINTDLG, as the default printer DEVMODE may be incompatible with that of the printer we're actually going to use and could possible result in a crash if their size differs. Use a temporary printer if necessary to retrieve the correct DEVMODE for the given printer name. Closes #23685.
This commit is contained in:
parent
590cd0bd18
commit
e35257d2b6
1 changed files with 7 additions and 2 deletions
|
|
@ -423,8 +423,13 @@ void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, Wi
|
|||
// this replaces the PrintDlg function which creates the DEVMODE filled only with data from default printer.
|
||||
if ( !m_devMode && !printerName.IsEmpty() )
|
||||
{
|
||||
// ensure that we have a printer object here, otherwise we are unable to determine m_devMode
|
||||
WinPrinter fallbackPrinter;
|
||||
if (!printer)
|
||||
printer = &fallbackPrinter;
|
||||
|
||||
// Open printer
|
||||
if ( printer && printer->Open( printerName ) == TRUE )
|
||||
if ( printer->Open( printerName ) == TRUE )
|
||||
{
|
||||
DWORD dwNeeded, dwRet;
|
||||
|
||||
|
|
@ -468,7 +473,7 @@ void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, Wi
|
|||
}
|
||||
}
|
||||
|
||||
if ( !m_devMode )
|
||||
if ( !m_devMode && printerName.IsEmpty() )
|
||||
{
|
||||
// Use PRINTDLG as a way of creating a DEVMODE object
|
||||
PRINTDLG pd;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue