From e2fc2bd51c2351f3cb7e289bb397efbb60b8cbc5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Jan 2008 01:30:58 +0000 Subject: [PATCH] add wxDL_QUIET flag; use RawGetSymbol() instead of GetSymbol() in wxDL_INIT_FUNC to avoid error messages for missing functions (this is also consistent with wxDL_INIT_FUNC_AW) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51032 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/dynlib.tex | 2 ++ include/wx/dynlib.h | 7 ++++++- src/common/dynlib.cpp | 2 +- src/msw/display.cpp | 18 ++++-------------- src/msw/textentry.cpp | 4 +--- src/msw/window.cpp | 4 +--- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/docs/latex/wx/dynlib.tex b/docs/latex/wx/dynlib.tex index 8c15876b0c..967416a24c 100644 --- a/docs/latex/wx/dynlib.tex +++ b/docs/latex/wx/dynlib.tex @@ -167,6 +167,8 @@ be a combination of the following bits: \twocolitem{wxDL\_VERBATIM}{don't try to append the appropriate extension to the library name (this is done by default).} \twocolitem{wxDL\_DEFAULT}{default flags, same as wxDL\_NOW currently} +\twocolitem{wxDL\_QUIET}{don't log an error message if the library couldn't be +loaded.} \end{twocollist} Returns \true if the library was successfully loaded, \false otherwise. diff --git a/include/wx/dynlib.h b/include/wx/dynlib.h index 6f842edb17..0fabb058bf 100644 --- a/include/wx/dynlib.h +++ b/include/wx/dynlib.h @@ -75,6 +75,8 @@ enum wxDLFlags 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 + wxDL_DEFAULT = wxDL_NOW // default flags correspond to Win32 }; @@ -112,8 +114,11 @@ enum wxPluginCategory // with "_t" but it doesn't define a variable but just assigns the loaded value // to it and also allows to pass it the prefix to be used instead of hardcoding // "pfn" (the prefix can be "m_" or "gs_pfn" or whatever) +// +// notice that this function doesn't generate error messages if the symbol +// couldn't be loaded, the caller should generate the appropriate message #define wxDL_INIT_FUNC(pfx, name, dynlib) \ - pfx ## name = (name ## _t)(dynlib).GetSymbol(#name) + pfx ## name = (name ## _t)(dynlib).RawGetSymbol(#name) #ifdef __WXMSW__ diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 11808003ab..0334bf749e 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -101,7 +101,7 @@ bool wxDynamicLibrary::Load(const wxString& libnameOrig, int flags) m_handle = RawLoad(libname, flags); #endif - if ( m_handle == 0 ) + if ( m_handle == 0 && !(flags & wxDL_QUIET) ) { #ifdef wxHAVE_DYNLIB_ERROR Error(); diff --git a/src/msw/display.cpp b/src/msw/display.cpp index e5d3247e08..afa4b3ea5b 100644 --- a/src/msw/display.cpp +++ b/src/msw/display.cpp @@ -513,9 +513,7 @@ wxDisplayFactoryWin32Base::wxDisplayFactoryWin32Base() { ms_supportsMultimon = 0; - wxDynamicLibrary dllUser32(_T("user32.dll")); - - wxLogNull noLog; + wxDynamicLibrary dllUser32(_T("user32.dll"), wxDL_VERBATIM | wxDL_QUIET); if ( (wxDL_INIT_FUNC(gs_, MonitorFromPoint, dllUser32)) == NULL || (wxDL_INIT_FUNC(gs_, MonitorFromWindow, dllUser32)) == NULL || @@ -588,9 +586,7 @@ wxDisplayFactoryMultimon::wxDisplayFactoryMultimon() // implementation EnumDisplayMonitors_t pfnEnumDisplayMonitors; { - wxLogNull noLog; - - wxDynamicLibrary dllUser32(_T("user32.dll")); + wxDynamicLibrary dllUser32(_T("user32.dll"), wxDL_VERBATIM | wxDL_QUIET); if ( (wxDL_INIT_FUNC(pfn, EnumDisplayMonitors, dllUser32)) == NULL ) return; } @@ -735,7 +731,7 @@ bool wxDisplayImplMultimon::ChangeMode(const wxVideoMode& mode) static ChangeDisplaySettingsEx_t pfnChangeDisplaySettingsEx = NULL; if ( !pfnChangeDisplaySettingsEx ) { - wxDynamicLibrary dllUser32(_T("user32.dll")); + wxDynamicLibrary dllUser32(_T("user32.dll"), wxDL_VERBATIM | wxDL_QUIET); if ( dllUser32.IsLoaded() ) { wxDL_INIT_FUNC_AW(pfn, ChangeDisplaySettingsEx, dllUser32); @@ -805,13 +801,7 @@ wxDisplayFactoryDirectDraw::wxDisplayFactoryDirectDraw() if ( !ms_supportsMultimon ) return; -#if wxUSE_LOG - // suppress the errors if ddraw.dll is not found, we're prepared to handle - // this - wxLogNull noLog; -#endif - - m_dllDDraw.Load(_T("ddraw.dll")); + m_dllDDraw.Load(_T("ddraw.dll"), wxDL_VERBATIM | wxDL_QUIET); if ( !m_dllDDraw.IsLoaded() ) return; diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index 346791506e..b763b5de8e 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -295,9 +295,7 @@ bool wxTextEntry::AutoCompleteFileNames() static wxDynamicLibrary s_dllShlwapi; if ( s_pfnSHAutoComplete == (SHAutoComplete_t)-1 ) { - wxLogNull noLog; - - if ( !s_dllShlwapi.Load(_T("shlwapi.dll"), wxDL_VERBATIM) ) + if ( !s_dllShlwapi.Load(_T("shlwapi.dll"), wxDL_VERBATIM | wxDL_QUIET) ) { s_pfnSHAutoComplete = NULL; } diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 418d1eb848..d035da942b 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -725,9 +725,7 @@ wxWindowMSW::MSWShowWithEffect(bool show, static bool s_initDone = false; if ( !s_initDone ) { - wxLogNull noLog; - - wxDynamicLibrary dllUser32(_T("user32.dll"), wxDL_VERBATIM); + wxDynamicLibrary dllUser32(_T("user32.dll"), wxDL_VERBATIM | wxDL_QUIET); wxDL_INIT_FUNC(s_pfn, AnimateWindow, dllUser32); s_initDone = true; -- 2.45.2