From: Vadim Zeitlin Date: Thu, 20 Nov 2008 16:45:45 +0000 (+0000) Subject: don't load comctl32.dll, just get the handle of the already loaded instance of it... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e2d4ce7d3681c876f69126c0a63e5caebbab62dd don't load comctl32.dll, just get the handle of the already loaded instance of it instead, this avoids accidentally loading 2 different versions of this DLL in the same process (see #10203) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56863 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dynlib.h b/include/wx/dynlib.h index a6a45f74c1..3d31beeb80 100644 --- a/include/wx/dynlib.h +++ b/include/wx/dynlib.h @@ -73,11 +73,19 @@ enum wxDLFlags wxDL_VERBATIM = 0x00000008, // attempt to load the supplied library // name without appending the usual dll // filename extension. + + // this flag is obsolete, don't use wxDL_NOSHARE = 0x00000010, // load new DLL, don't reuse already loaded // (only for wxPluginManager) wxDL_QUIET = 0x00000020, // don't log an error if failed to load + // this flag is dangerous, for internal use of wxMSW only, don't use + wxDL_GET_LOADED = 0x00000040, // Win32 only: return handle of already + // loaded DLL or NULL otherwise; Unload() + // should not be called so don't forget to + // Detach() if you use this function + wxDL_DEFAULT = wxDL_NOW // default flags correspond to Win32 }; diff --git a/src/msw/app.cpp b/src/msw/app.cpp index ccac439ee7..fccf263409 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -966,8 +966,14 @@ int wxApp::GetComCtl32Version() // we're prepared to handle the errors wxLogNull noLog; - // the DLL should really be available - wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM); + // we don't want to load comctl32.dll, it should be already loaded but, + // depending on the OS version and the presence of the manifest, it can + // be either v5 or v6 and instead of trying to guess it just get the + // handle of the already loaded version + wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), + wxDL_VERBATIM | + wxDL_QUIET | + wxDL_GET_LOADED); if ( !dllComCtl32.IsLoaded() ) { s_verComCtl32 = 0; @@ -1005,6 +1011,9 @@ int wxApp::GetComCtl32Version() } } } + + // we shouldn't unload it here as we didn't really load it above + dllComCtl32.Detach(); } return s_verComCtl32; diff --git a/src/msw/datecontrols.cpp b/src/msw/datecontrols.cpp index 3af793ec52..6960f09aee 100644 --- a/src/msw/datecontrols.cpp +++ b/src/msw/datecontrols.cpp @@ -67,10 +67,17 @@ bool wxMSWDateControls::CheckInitialization() icex.dwSize = sizeof(icex); icex.dwICC = ICC_DATE_CLASSES; - wxDynamicLibrary dllComCtl32(_T("comctl32.dll") , wxDL_VERBATIM); + // see comment in wxApp::GetComCtl32Version() explaining the + // use of wxDL_GET_LOADED + wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), + wxDL_VERBATIM | + wxDL_QUIET | + wxDL_GET_LOADED); if ( dllComCtl32.IsLoaded() ) { + wxLogNull noLog; + typedef BOOL (WINAPI *ICCEx_t)(INITCOMMONCONTROLSEX *); wxDYNLIB_FUNCTION( ICCEx_t, InitCommonControlsEx, dllComCtl32 ); diff --git a/src/msw/dlmsw.cpp b/src/msw/dlmsw.cpp index 0b4d76de17..280dab0e28 100644 --- a/src/msw/dlmsw.cpp +++ b/src/msw/dlmsw.cpp @@ -282,9 +282,11 @@ wxDllType wxDynamicLibrary::GetProgramHandle() /* static */ wxDllType -wxDynamicLibrary::RawLoad(const wxString& libname, int WXUNUSED(flags)) +wxDynamicLibrary::RawLoad(const wxString& libname, int flags) { - return ::LoadLibrary(libname.t_str()); + return flags & wxDL_GET_LOADED + ? ::GetModuleHandle(libname.t_str()) + : ::LoadLibrary(libname.t_str()); } /* static */ diff --git a/src/msw/window.cpp b/src/msw/window.cpp index ea9a66c3c0..b5004af9d2 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -5306,20 +5306,23 @@ bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags) static bool s_initDone = false; if ( !s_initDone ) { - wxLogNull noLog; - - wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM); + // see comment in wxApp::GetComCtl32Version() explaining the + // use of wxDL_GET_LOADED + wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), + wxDL_VERBATIM | + wxDL_QUIET | + wxDL_GET_LOADED); if ( dllComCtl32.IsLoaded() ) { s_pfn_TrackMouseEvent = (_TrackMouseEvent_t) - dllComCtl32.GetSymbol(_T("_TrackMouseEvent")); + dllComCtl32.RawGetSymbol(_T("_TrackMouseEvent")); } s_initDone = true; - // notice that it's ok to unload comctl32.dll here as it won't - // be really unloaded, being still in use because we link to it - // statically too + // we shouldn't unload comctl32.dll here as we didn't really + // load it above + dllComCtl32.Detach(); } if ( s_pfn_TrackMouseEvent )