2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dynlib.h
|
2008-04-21 21:38:12 -04:00
|
|
|
// Purpose: interface of wxDynamicLibrary and wxDynamicLibraryDetails
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxDynamicLibraryDetails
|
|
|
|
@wxheader{dynlib.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-21 21:38:12 -04:00
|
|
|
This class is used for the objects returned by the
|
|
|
|
wxDynamicLibrary::ListLoaded() method and contains the information about a
|
|
|
|
single module loaded into the address space of the current process. A
|
|
|
|
module in this context may be either a dynamic library or the main program
|
|
|
|
itself.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-04-21 21:38:12 -04:00
|
|
|
@category{appmanagement}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxDynamicLibraryDetails
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Retrieves the load address and the size of this module.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param addr
|
2008-04-21 21:38:12 -04:00
|
|
|
The pointer to the location to return load address in, may be
|
|
|
|
@NULL.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param len
|
2008-04-21 21:38:12 -04:00
|
|
|
Pointer to the location to return the size of this module in
|
|
|
|
memory in, may be @NULL.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if the load address and module size were retrieved,
|
2008-04-21 21:38:12 -04:00
|
|
|
@false if this information is not available.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool GetAddress(void** addr, size_t len) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Returns the base name of this module, e.g. @c "kernel32.dll" or
|
|
|
|
@c "libc-2.3.2.so".
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetName() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Returns the full path of this module if available, e.g.
|
2008-04-21 21:38:12 -04:00
|
|
|
@c "c:\windows\system32\kernel32.dll" or @c "/lib/libc-2.3.2.so".
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetPath() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Returns the version of this module, e.g. @c "5.2.3790.0" or @c "2.3.2".
|
|
|
|
The returned string is empty if the version information is not
|
2008-03-08 08:52:38 -05:00
|
|
|
available.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetVersion() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Dynamic library category used with wxDynamicLibrary::CanonicalizeName().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-04-21 21:38:12 -04:00
|
|
|
enum wxDynamicLibraryCategory
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
2008-04-21 21:38:12 -04:00
|
|
|
wxDL_LIBRARY, ///< Standard library.
|
|
|
|
wxDL_MODULE ///< Loadable module/plugin.
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
2008-04-21 21:38:12 -04:00
|
|
|
/**
|
|
|
|
Dynamic library plugin category used with
|
|
|
|
wxDynamicLibrary::CanonicalizePluginName().
|
|
|
|
*/
|
|
|
|
enum wxPluginCategory
|
|
|
|
{
|
|
|
|
wxDL_PLUGIN_GUI, ///< Plugin that uses GUI classes.
|
|
|
|
wxDL_PLUGIN_BASE ///< wxBase-only plugin.
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxDynamicLibrary
|
|
|
|
@wxheader{dynlib.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDynamicLibrary is a class representing dynamically loadable library
|
|
|
|
(Windows DLL, shared library under Unix etc.). Just create an object of
|
2008-04-21 21:38:12 -04:00
|
|
|
this class to load a library and don't worry about unloading it -- it will
|
|
|
|
be done in the objects destructor automatically.
|
|
|
|
|
|
|
|
The following flags can be used with wxDynamicLibrary() or Load():
|
|
|
|
|
|
|
|
@beginStyleTable
|
|
|
|
@style{wxDL_LAZY}
|
|
|
|
Equivalent of RTLD_LAZY under Unix, ignored elsewhere.
|
|
|
|
@style{wxDL_NOW}
|
|
|
|
Equivalent of RTLD_NOW under Unix, ignored elsewhere.
|
|
|
|
@style{wxDL_GLOBAL}
|
|
|
|
Equivalent of RTLD_GLOBAL under Unix, ignored elsewhere.
|
|
|
|
@style{wxDL_VERBATIM}
|
|
|
|
Don't try to append the appropriate extension to the library name
|
|
|
|
(this is done by default).
|
|
|
|
@style{wxDL_DEFAULT}
|
|
|
|
Default flags, same as wxDL_NOW currently.
|
|
|
|
@style{wxDL_QUIET}
|
|
|
|
Don't log an error message if the library couldn't be loaded.
|
|
|
|
@endStyleTable
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-04-21 21:38:12 -04:00
|
|
|
@category{appmanagement}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxDynamicLibrary
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Default constructor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxDynamicLibrary();
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Constructor. Calls Load() with the given @a name.
|
|
|
|
*/
|
|
|
|
wxDynamicLibrary(const wxString& name, int flags = wxDL_DEFAULT);
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-04-21 21:38:12 -04:00
|
|
|
/**
|
|
|
|
Returns the platform-specific full name for the library called @a name.
|
|
|
|
E.g. it adds a @c ".dll" extension under Windows and @c "lib" prefix
|
|
|
|
and @c ".so", @c ".sl" or @c ".dylib" extension under Unix.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see CanonicalizePluginName()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
static wxString CanonicalizeName(const wxString& name,
|
|
|
|
wxDynamicLibraryCategory cat = wxDL_LIBRARY);
|
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
This function does the same thing as CanonicalizeName() but for
|
|
|
|
wxWidgets plugins. The only difference is that compiler and version
|
|
|
|
information are added to the name to ensure that the plugin which is
|
|
|
|
going to be loaded will be compatible with the main program.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
static wxString CanonicalizePluginName(const wxString& name,
|
|
|
|
wxPluginCategory cat = wxDL_PLUGIN_GUI);
|
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
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 responsibility to do this using Unload().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxDllType Detach();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return a valid handle for the main program itself or @NULL if symbols
|
|
|
|
from the main program can't be loaded on this platform.
|
|
|
|
*/
|
|
|
|
static wxDllType GetProgramHandle();
|
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Returns pointer to symbol @a name in the library or @NULL if the
|
|
|
|
library contains no such symbol.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxDYNLIB_FUNCTION()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetSymbol(const wxString& name) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
This function is available only under Windows as it is only useful when
|
2008-04-21 21:38:12 -04:00
|
|
|
dynamically loading symbols from standard Windows DLLs. Such functions
|
|
|
|
have either @c 'A' (in ANSI build) or @c 'W' (in Unicode, or wide
|
|
|
|
character build) suffix if they take string parameters. Using this
|
|
|
|
function, you can use just the base name of the function and the
|
|
|
|
correct suffix is appended automatically depending on the current
|
|
|
|
build. Otherwise, this method is identical to GetSymbol().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetSymbolAorW(const wxString& name) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Returns @true if the symbol with the given @a name is present in the
|
|
|
|
dynamic library, @false otherwise. Unlike GetSymbol(), this function
|
|
|
|
doesn't log an error message if the symbol is not found.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-04-21 06:34:23 -04:00
|
|
|
@since 2.5.4
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool HasSymbol(const wxString& name) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the library was successfully loaded, @false otherwise.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsLoaded() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
This static method returns a wxArray containing the details of all
|
|
|
|
modules loaded into the address space of the current project. The array
|
|
|
|
elements are objects of the type: wxDynamicLibraryDetails. The array
|
|
|
|
will be empty if an error occurred.
|
|
|
|
|
|
|
|
This method is currently implemented only under Win32 and Linux and is
|
|
|
|
useful mostly for diagnostics purposes.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
static wxDynamicLibraryDetailsArray ListLoaded();
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Loads DLL with the given @a name into memory. The @a flags argument can
|
2008-04-21 21:38:12 -04:00
|
|
|
be a combination of the styles outlined in the class description.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Returns @true if the library was successfully loaded, @false otherwise.
|
|
|
|
*/
|
|
|
|
bool Load(const wxString& name, int flags = wxDL_DEFAULT);
|
|
|
|
|
|
|
|
/**
|
2008-04-21 21:38:12 -04:00
|
|
|
Unloads the library from memory. wxDynamicLibrary object automatically
|
|
|
|
calls this method from its destructor if it had been successfully
|
|
|
|
loaded.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Unload();
|
2008-04-21 21:38:12 -04:00
|
|
|
/**
|
|
|
|
Unloads the library from memory. wxDynamicLibrary object automatically
|
|
|
|
calls this method from its destructor if it had been successfully
|
|
|
|
loaded.
|
|
|
|
|
|
|
|
This version of Unload() is only used if you need to keep the library
|
|
|
|
in memory during a longer period of time than the scope of the
|
|
|
|
wxDynamicLibrary object. In this case you may call Detach() and store
|
|
|
|
the handle somewhere and call this static method later to unload it.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
static void Unload(wxDllType handle);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
2008-03-23 14:24:32 -04:00
|
|
|
/** @ingroup group_funcmacro_misc */
|
|
|
|
//@{
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
When loading a function from a DLL you always have to cast the returned
|
2008-03-23 14:24:32 -04:00
|
|
|
<tt>void *</tt> pointer to the correct type and, even more annoyingly, you
|
|
|
|
have to repeat this type twice if you want to declare and define a function
|
|
|
|
pointer all in one line.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This macro makes this slightly less painful by allowing you to specify the
|
2008-03-23 14:24:32 -04:00
|
|
|
type only once, as the first parameter, and creating a variable of this
|
|
|
|
type named after the function but with @c pfn prefix and initialized with
|
|
|
|
the function @a name from the wxDynamicLibrary @a dynlib.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
@param type
|
2008-03-23 14:24:32 -04:00
|
|
|
The type of the function.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param name
|
2008-03-23 14:24:32 -04:00
|
|
|
The name of the function to load, not a string (without quotes, it is
|
|
|
|
quoted automatically by the macro).
|
2008-03-08 09:43:31 -05:00
|
|
|
@param dynlib
|
2008-03-23 14:24:32 -04:00
|
|
|
The library to load the function from.
|
|
|
|
|
|
|
|
@header{wx/dynlib.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-23 14:24:32 -04:00
|
|
|
#define wxDYNLIB_FUNCTION(type, name, dynlib)
|
|
|
|
|
|
|
|
//@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|