X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d0edb9da6028587c8c17158172a95dcdb2de96f5..33f3e2b31ed781ba1446b49ec6d3e226c0a5c652:/include/wx/dynlib.h?ds=sidebyside diff --git a/include/wx/dynlib.h b/include/wx/dynlib.h index 6f842edb17..6a704d7eb6 100644 --- a/include/wx/dynlib.h +++ b/include/wx/dynlib.h @@ -19,14 +19,6 @@ #include "wx/string.h" #include "wx/dynarray.h" -#if defined(__OS2__) || defined(__EMX__) -#include "wx/os2/private.h" -#endif - -#ifdef __WXMSW__ -#include "wx/msw/private.h" -#endif - // note that we have our own dlerror() implementation under Darwin #if (defined(HAVE_DLERROR) && !defined(__EMX__)) || defined(__DARWIN__) #define wxHAVE_DYNLIB_ERROR @@ -41,15 +33,16 @@ class WXDLLIMPEXP_FWD_BASE wxDynamicLibraryDetailsCreator; // Note: __OS2__/EMX has to be tested first, since we want to use // native version, even if configure detected presence of DLOPEN. #if defined(__OS2__) || defined(__EMX__) || defined(__WINDOWS__) - typedef HMODULE wxDllType; + typedef WXHMODULE wxDllType; +#elif defined(__DARWIN__) + // Don't include dlfcn.h on Darwin, we may be using our own replacements. + typedef void *wxDllType; #elif defined(HAVE_DLOPEN) #include typedef void *wxDllType; #elif defined(HAVE_SHL_LOAD) #include typedef shl_t wxDllType; -#elif defined(__DARWIN__) - typedef void *wxDllType; #elif defined(__WXMAC__) #include typedef CFragConnectionID wxDllType; @@ -72,9 +65,21 @@ 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 at all + // and especially don't use directly, use wxLoadedDLL instead if you really + // do need it + 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 }; @@ -103,7 +108,7 @@ enum wxPluginCategory // type only once, as the first parameter, and creating a variable of this type // called "pfn" initialized with the "name" from the "dynlib" #define wxDYNLIB_FUNCTION(type, name, dynlib) \ - type pfn ## name = (type)(dynlib).GetSymbol(_T(#name)) + type pfn ## name = (type)(dynlib).GetSymbol(wxT(#name)) // a more convenient function replacing wxDYNLIB_FUNCTION above @@ -112,17 +117,20 @@ 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__ +#ifdef __WINDOWS__ // same as wxDL_INIT_FUNC() but appends 'A' or 'W' to the function name, see // wxDynamicLibrary::GetSymbolAorW() #define wxDL_INIT_FUNC_AW(pfx, name, dynlib) \ pfx ## name = (name ## _t)(dynlib).GetSymbolAorW(#name) -#endif // __WXMSW__ +#endif // __WINDOWS__ // the following macros can be used to redirect a whole library to a class and // check at run-time if the library is present and contains all required @@ -296,7 +304,7 @@ public: #endif } -#ifdef __WXMSW__ +#ifdef __WINDOWS__ // this function is useful for loading functions from the standard Windows // DLLs: such functions have an 'A' (in ANSI build) or 'W' (in Unicode, or // wide character build) suffix if they take string parameters @@ -318,7 +326,7 @@ public: { return RawGetSymbolAorW(m_handle, name); } -#endif // __WXMSW__ +#endif // __WINDOWS__ // return all modules/shared libraries in the address space of this process // @@ -341,6 +349,19 @@ public: static wxString GetPluginsDirectory(); +#ifdef __WINDOWS__ + // return the handle (HMODULE/HINSTANCE) of the DLL with the given name + // and/or containing the specified address: for XP and later systems only + // the address is used and the name is ignored but for the previous systems + // only the name (which may be either a full path to the DLL or just its + // base name, possibly even without extension) is used + // + // the returned handle reference count is not incremented so it doesn't + // need to be freed using FreeLibrary() but it also means that it can + // become invalid if the DLL is unloaded + static WXHMODULE MSWGetModuleHandle(const char *name, void *addr); +#endif // __WINDOWS__ + protected: // common part of GetSymbol() and HasSymbol() void *DoGetSymbol(const wxString& name, bool *success = 0) const; @@ -359,9 +380,31 @@ protected: // no copy ctor/assignment operators (or we'd try to unload the library // twice) - DECLARE_NO_COPY_CLASS(wxDynamicLibrary) + wxDECLARE_NO_COPY_CLASS(wxDynamicLibrary); +}; + +#ifdef __WINDOWS__ + +// ---------------------------------------------------------------------------- +// wxLoadedDLL is a MSW-only internal helper class allowing to dynamically bind +// to a DLL already loaded into the project address space +// ---------------------------------------------------------------------------- + +class wxLoadedDLL : public wxDynamicLibrary +{ +public: + wxLoadedDLL(const wxString& dllname) + : wxDynamicLibrary(dllname, wxDL_GET_LOADED | wxDL_VERBATIM | wxDL_QUIET) + { + } + + ~wxLoadedDLL() + { + Detach(); + } }; +#endif // __WINDOWS__ // ---------------------------------------------------------------------------- // Interesting defines