Use GlobalPtr instead of manual Global{Alloc,Free}() calls
No real changes, just use RAII wrapper instead of doing manual memory management in wxMSW printing code. We still use a raw pointer for m_devMode, but changing this would be more involved, so leave it be for now.
This commit is contained in:
@@ -417,27 +417,26 @@ void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, Wi
|
|||||||
// is overwritten. So add a bit of extra memory to work around this.
|
// is overwritten. So add a bit of extra memory to work around this.
|
||||||
dwNeeded += 1024;
|
dwNeeded += 1024;
|
||||||
|
|
||||||
LPDEVMODE tempDevMode = static_cast<LPDEVMODE>( GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, dwNeeded ) );
|
GlobalPtr tempDevMode(dwNeeded, GMEM_FIXED | GMEM_ZEROINIT);
|
||||||
|
HGLOBAL hDevMode = tempDevMode;
|
||||||
|
|
||||||
// Step 2:
|
// Step 2:
|
||||||
// Get the default DevMode for the printer
|
// Get the default DevMode for the printer
|
||||||
dwRet = DocumentProperties( NULL,
|
dwRet = DocumentProperties( NULL,
|
||||||
*printer,
|
*printer,
|
||||||
szPrinterName,
|
szPrinterName,
|
||||||
tempDevMode, // The address of the buffer to fill.
|
static_cast<LPDEVMODE>(hDevMode), // The buffer to fill.
|
||||||
NULL, // Not using the input buffer.
|
NULL, // Not using the input buffer.
|
||||||
DM_OUT_BUFFER ); // Have the output buffer filled.
|
DM_OUT_BUFFER ); // Have the output buffer filled.
|
||||||
|
|
||||||
if ( dwRet != IDOK )
|
if ( dwRet != IDOK )
|
||||||
{
|
{
|
||||||
// If failure, cleanup
|
// If failure, cleanup
|
||||||
GlobalFree( tempDevMode );
|
|
||||||
printer->Close();
|
printer->Close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_devMode = tempDevMode;
|
m_devMode = tempDevMode.Release();
|
||||||
tempDevMode = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user