From 3b8c02374400b4db8021c2d504b44b4cf316cc1a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 13 Jul 2021 23:48:35 +0100 Subject: [PATCH] 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. --- src/msw/printdlg.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/msw/printdlg.cpp b/src/msw/printdlg.cpp index e192c31ffb..22ae152b24 100644 --- a/src/msw/printdlg.cpp +++ b/src/msw/printdlg.cpp @@ -417,27 +417,26 @@ void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, Wi // is overwritten. So add a bit of extra memory to work around this. dwNeeded += 1024; - LPDEVMODE tempDevMode = static_cast( GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, dwNeeded ) ); + GlobalPtr tempDevMode(dwNeeded, GMEM_FIXED | GMEM_ZEROINIT); + HGLOBAL hDevMode = tempDevMode; // Step 2: // Get the default DevMode for the printer dwRet = DocumentProperties( NULL, *printer, szPrinterName, - tempDevMode, // The address of the buffer to fill. + static_cast(hDevMode), // 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; + m_devMode = tempDevMode.Release(); } } }