Deprecation note: This class is deprecated since version 2.4 and is not compiled in by default in version 2.6 and will be removed in 2.8. Please use wxDynamicLibrary instead.

wxDllLoader is a class providing an interface similar to Unix's dlopen(). It is used by the wxLibrary framework and manages the actual loading of shared libraries and the resolving of symbols in them. There are no instances of this class, it simply serves as a namespace for its static member functions.

Please note that class wxDynamicLibrary provides alternative, friendlier interface to wxDllLoader.

The terms DLL and shared library/object will both be used in the documentation to refer to the same thing: a .dll file under Windows or .so or .sl one under Unix.

Example of using this class to dynamically load the strlen() function:

#if defined(__WXMSW__)
    static const wxChar *LIB_NAME = _T("kernel32");
    static const wxChar *FUNC_NAME = _T("lstrlenA");
#elif defined(__UNIX__)
    static const wxChar *LIB_NAME = _T("/lib/libc-2.0.7.so");
    static const wxChar *FUNC_NAME = _T("strlen");

    wxDllType dllHandle = wxDllLoader::LoadLibrary(LIB_NAME);
    if ( !dllHandle )
        ... error ...
        typedef int (*strlenType)(char *);
        strlenType pfnStrlen = (strlenType)wxDllLoader::GetSymbol(dllHandle, FUNC_NAME);
        if ( !pfnStrlen )
            ... error ...
            if ( pfnStrlen("foo") != 3 )
                ... error ...
                ... ok! ...


Derived from

No base class

Include files


Data structures

This header defines a platform-dependent wxDllType typedef which stores a handle to a loaded DLLs on the given platform.


static wxString GetDllExt(void)

Returns the string containing the usual extension for shared libraries for the given systems (including the leading dot if not empty).

For example, this function will return ".dll" under Windows or (usually) ".so" under Unix.


wxDllType GetProgramHandle(void)

This function returns a valid handle for the main program itself. Notice that the NULL return value is valid for some systems (i.e. doesn't mean that the function failed).

NB: This function is Unix specific. It will always fail under Windows or OS/2.


void * GetSymbol(wxDllType dllHandle, const wxString& name)

This function resolves a symbol in a loaded DLL, such as a variable or function name.

Returned value will be NULL if the symbol was not found in the DLL or if an error occurred.


Valid handle previously returned by LoadLibrary

Name of the symbol.


wxDllType LoadLibrary(const wxString & libname, bool* success = NULL)

This function loads a shared library into memory, with libname being the name of the library: it may be either the full name including path and (platform-dependent) extension, just the basename (no path and no extension) or a basename with extension. In the last two cases, the library will be searched in all standard locations.

Returns a handle to the loaded DLL. Use success parameter to test if it is valid. If the handle is valid, the library must be unloaded later with UnloadLibrary.


Name of the shared object to load.

May point to a bool variable which will be set to true or false; may also be NULL.


void UnloadLibrary(wxDllType dllhandle)

This function unloads the shared library. The handle dllhandle must have been returned by LoadLibrary previously.

ymasuda 平成17年11月19日