added wxDynamicLibrary::HasSymbol()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29957 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2004-10-17 23:20:51 +00:00
parent fd64de596c
commit a018a119bd
4 changed files with 45 additions and 7 deletions

View File

@ -205,6 +205,7 @@ OTHER CHANGES
All: All:
- Norvegian (Bokmål) translation added (Hans F. Nordhaug) - Norvegian (Bokmål) translation added (Hans F. Nordhaug)
- wxDynamicLibrary::HasSymbol() added
All (GUI): All (GUI):

View File

@ -23,6 +23,7 @@ done in the objects destructor automatically.
%\helpref{wxDllLoader}{wxdllloader} %\helpref{wxDllLoader}{wxdllloader}
\membersection{wxDynamicLibrary::wxDynamicLibrary}\label{wxdynamiclibrarywxdynamiclibrary} \membersection{wxDynamicLibrary::wxDynamicLibrary}\label{wxdynamiclibrarywxdynamiclibrary}
\func{}{wxDynamicLibrary}{\void} \func{}{wxDynamicLibrary}{\void}
@ -31,6 +32,7 @@ done in the objects destructor automatically.
Constructor. Second form calls \helpref{Load}{wxdynamiclibraryload}. Constructor. Second form calls \helpref{Load}{wxdynamiclibraryload}.
\membersection{wxDynamicLibrary::CanonicalizeName}\label{wxdynamiclibrarycanonicalizename} \membersection{wxDynamicLibrary::CanonicalizeName}\label{wxdynamiclibrarycanonicalizename}
\func{wxString}{CanonicalizeName}{\param{const wxString\& }{name}, \param{wxDynamicLibraryCategory}{ cat = wxDL\_LIBRARY}} \func{wxString}{CanonicalizeName}{\param{const wxString\& }{name}, \param{wxDynamicLibraryCategory}{ cat = wxDL\_LIBRARY}}
@ -51,6 +53,7 @@ The possible values for \arg{cat} are:
\helpref{CanonicalizePluginName}{wxdynamiclibrarycanonicalizepluginname} \helpref{CanonicalizePluginName}{wxdynamiclibrarycanonicalizepluginname}
\membersection{wxDynamicLibrary::CanonicalizePluginName}\label{wxdynamiclibrarycanonicalizepluginname} \membersection{wxDynamicLibrary::CanonicalizePluginName}\label{wxdynamiclibrarycanonicalizepluginname}
\func{wxString}{CanonicalizePluginName}{\param{const wxString\& }{name}, \param{wxPluginCategory}{ cat = wxDL\_PLUGIN\_GUI}} \func{wxString}{CanonicalizePluginName}{\param{const wxString\& }{name}, \param{wxPluginCategory}{ cat = wxDL\_PLUGIN\_GUI}}
@ -68,6 +71,7 @@ The possible values for \arg{cat} are:
\twocolitem{wxDL\_PLUGIN\_BASE}{plugin which only uses wxBase} \twocolitem{wxDL\_PLUGIN\_BASE}{plugin which only uses wxBase}
\end{twocollist} \end{twocollist}
\membersection{wxDynamicLibrary::Detach}\label{wxdynamiclibrarydetach} \membersection{wxDynamicLibrary::Detach}\label{wxdynamiclibrarydetach}
\func{wxDllType}{Detach}{\void} \func{wxDllType}{Detach}{\void}
@ -76,9 +80,10 @@ Detaches this object from its library handle, i.e. the object will not unload
the library any longer in its destructor but it is now the callers the library any longer in its destructor but it is now the callers
responsability to do this using \helpref{Unload}{wxdynamiclibraryunload}. responsability to do this using \helpref{Unload}{wxdynamiclibraryunload}.
\membersection{wxDynamicLibrary::GetSymbol}\label{wxdynamiclibrarygetsymbol} \membersection{wxDynamicLibrary::GetSymbol}\label{wxdynamiclibrarygetsymbol}
\constfunc{void*}{GetSymbol}{\param{const wxString\& }{name}} \constfunc{void *}{GetSymbol}{\param{const wxString\& }{name}}
Returns pointer to symbol {\it name} in the library or NULL if the library Returns pointer to symbol {\it name} in the library or NULL if the library
contains no such symbol. contains no such symbol.
@ -87,12 +92,25 @@ contains no such symbol.
\helpref{wxDYNLIB\_FUNCTION}{wxdynlibfunction} \helpref{wxDYNLIB\_FUNCTION}{wxdynlibfunction}
\membersection{wxDynamicLibrary::HasSymbol}\label{wxdynamiclibraryhassymbol}
\constfunc{bool}{HasSymbol}{\param{const wxString\& }{name}}
Returns \true if the symbol with the given \arg{name} is present in the dynamic
library, \false otherwise. Unlike \helpref{GetSymbol}{wxdynamiclibrarygetsymbol},
this function doesn't log an error message if the symbol is not found.
\newsince{2.5.4}
\membersection{wxDynamicLibrary::IsLoaded}\label{wxdynamiclibraryisloaded} \membersection{wxDynamicLibrary::IsLoaded}\label{wxdynamiclibraryisloaded}
\constfunc{bool}{IsLoaded}{\void} \constfunc{bool}{IsLoaded}{\void}
Returns \true if the library was successfully loaded, \false otherwise. Returns \true if the library was successfully loaded, \false otherwise.
\membersection{wxDynamicLibrary::Load}\label{wxdynamiclibraryload} \membersection{wxDynamicLibrary::Load}\label{wxdynamiclibraryload}
\func{bool}{Load}{\param{const wxString\& }{name}, \param{int }{flags = wxDL\_DEFAULT}} \func{bool}{Load}{\param{const wxString\& }{name}, \param{int }{flags = wxDL\_DEFAULT}}
@ -110,6 +128,7 @@ the library name (this is done by default).}
Returns \true if the library was successfully loaded, \false otherwise. Returns \true if the library was successfully loaded, \false otherwise.
\membersection{wxDynamicLibrary::Unload}\label{wxdynamiclibraryunload} \membersection{wxDynamicLibrary::Unload}\label{wxdynamiclibraryunload}
\func{void}{Unload}{\void} \func{void}{Unload}{\void}

View File

@ -151,6 +151,16 @@ public:
// Return the raw handle from dlopen and friends. // Return the raw handle from dlopen and friends.
wxDllType GetLibHandle() const { return m_handle; } wxDllType GetLibHandle() const { return m_handle; }
// check if the given symbol is present in the library, useful to verify if
// a loadable module is our plugin, for example, without provoking error
// messages from GetSymbol()
bool HasSymbol(const wxString& name) const
{
bool ok;
DoGetSymbol(name, &ok);
return ok;
}
// resolve a symbol in a loaded DLL, such as a variable or function name. // resolve a symbol in a loaded DLL, such as a variable or function name.
// 'name' is the (possibly mangled) name of the symbol. (use extern "C" to // 'name' is the (possibly mangled) name of the symbol. (use extern "C" to
// export unmangled names) // export unmangled names)
@ -186,6 +196,10 @@ public:
#endif #endif
protected: protected:
// the real implementation of GetSymbol()
void *DoGetSymbol(const wxString& name, bool *success = 0) const;
// platform specific shared lib suffix. // platform specific shared lib suffix.
static const wxChar *ms_dllext; static const wxChar *ms_dllext;

View File

@ -314,12 +314,11 @@ void wxDynamicLibrary::Unload(wxDllType handle)
#endif #endif
} }
void *wxDynamicLibrary::GetSymbol(const wxString &name, bool *success) const void *wxDynamicLibrary::DoGetSymbol(const wxString &name, bool *success) const
{ {
wxCHECK_MSG( IsLoaded(), NULL, wxCHECK_MSG( IsLoaded(), NULL,
_T("Can't load symbol from unloaded library") ); _T("Can't load symbol from unloaded library") );
bool failed = false;
void *symbol = 0; void *symbol = 0;
wxUnusedVar(symbol); wxUnusedVar(symbol);
@ -360,6 +359,15 @@ void *wxDynamicLibrary::GetSymbol(const wxString &name, bool *success) const
#error "runtime shared lib support not implemented" #error "runtime shared lib support not implemented"
#endif #endif
if ( success )
*success = symbol != NULL;
return symbol;
}
void *wxDynamicLibrary::GetSymbol(const wxString& name, bool *success) const
{
void *symbol = DoGetSymbol(name, success);
if ( !symbol ) if ( !symbol )
{ {
#if defined(HAVE_DLERROR) && !defined(__EMX__) #if defined(HAVE_DLERROR) && !defined(__EMX__)
@ -376,18 +384,14 @@ void *wxDynamicLibrary::GetSymbol(const wxString &name, bool *success) const
wxLogError(wxT("%s"), err); wxLogError(wxT("%s"), err);
} }
#else #else
failed = true;
wxLogSysError(_("Couldn't find symbol '%s' in a dynamic library"), wxLogSysError(_("Couldn't find symbol '%s' in a dynamic library"),
name.c_str()); name.c_str());
#endif #endif
} }
if( success )
*success = !failed;
return symbol; return symbol;
} }
/*static*/ /*static*/
wxString wxString
wxDynamicLibrary::CanonicalizeName(const wxString& name, wxDynamicLibrary::CanonicalizeName(const wxString& name,