Contents Up Previous Next

wxDllLoader

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");
#endif

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

        wxDllLoader::UnloadLibrary(dllHandle);
    }
Derived from

No base class

Include files

<wx/dynlib.h>

Data structures

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

Members

wxDllLoader::GetDllExt
wxDllLoader::GetProgramHandle
wxDllLoader::GetSymbol
wxDllLoader::LoadLibrary
wxDllLoader::UnloadLibrary


wxDllLoader::GetDllExt

static wxString GetDllExt()

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.


wxDllLoader::GetProgramHandle

wxDllType GetProgramHandle()

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.


wxDllLoader::GetSymbol

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.

Parameters

dllHandle

name


wxDllLoader::LoadLibrary

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.

Parameters

libname

success


wxDllLoader::UnloadLibrary

void UnloadLibrary(wxDllType dllhandle)

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