2000-07-15 19:51:35 +00:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% Name: dllload.tex
|
|
|
|
%% Purpose: wxDllLoader documentation
|
|
|
|
%% Author: Vadim Zeitlin
|
|
|
|
%% Modified by:
|
|
|
|
%% Created: 02.04.00
|
|
|
|
%% RCS-ID: $Id$
|
|
|
|
%% Copyright: (c) Vadim Zeitlin
|
2005-02-22 15:09:56 +00:00
|
|
|
%% License: wxWindows license
|
2000-07-15 19:51:35 +00:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
\section{\class{wxDllLoader}}\label{wxdllloader}
|
|
|
|
|
2005-03-26 16:34:29 +00:00
|
|
|
\textbf{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 \helpref{wxDynamicLibrary}{wxdynamiclibrary} instead.
|
|
|
|
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDllLoader is a class providing an interface similar to Unix's {\tt
|
|
|
|
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.
|
|
|
|
|
2001-06-15 22:05:31 +00:00
|
|
|
Please note that class \helpref{wxDynamicLibrary}{wxdynamiclibrary} provides
|
|
|
|
alternative, friendlier interface to wxDllLoader.
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
The terms {\it DLL} and {\it shared library/object} will both be used in the
|
|
|
|
documentation to refer to the same thing: a {\tt .dll} file under Windows or
|
|
|
|
{\tt .so} or {\tt .sl} one under Unix.
|
|
|
|
|
2001-09-06 15:04:23 +00:00
|
|
|
Example of using this class to dynamically load the {\tt strlen()} function:
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
\wxheading{Derived from}
|
|
|
|
|
|
|
|
No base class
|
|
|
|
|
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/dynlib.h>
|
|
|
|
|
|
|
|
\wxheading{Data structures}
|
|
|
|
|
2002-06-07 20:15:28 +00:00
|
|
|
This header defines a platform-dependent {\tt wxDllType} typedef which stores
|
2000-07-15 19:51:35 +00:00
|
|
|
a handle to a loaded DLLs on the given platform.
|
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
|
|
|
\membersection{wxDllLoader::GetDllExt}\label{wxdllloadergetdllext}
|
|
|
|
|
|
|
|
\func{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 {\tt ".dll"} under Windows or (usually)
|
|
|
|
{\tt ".so"} under Unix.
|
|
|
|
|
|
|
|
\membersection{wxDllLoader::GetProgramHandle}\label{wxdllloadergetprogramhandle}
|
|
|
|
|
|
|
|
\func{wxDllType}{GetProgramHandle}{\void}
|
|
|
|
|
|
|
|
This function returns a valid handle for the main program itself. Notice that
|
|
|
|
the {\tt NULL} return value is valid for some systems (i.e. doesn't mean that
|
|
|
|
the function failed).
|
|
|
|
|
|
|
|
{\bf NB:} This function is Unix specific. It will always fail under Windows
|
|
|
|
or OS/2.
|
|
|
|
|
|
|
|
\membersection{wxDllLoader::GetSymbol}\label{wxdllloadergetsymbol}
|
|
|
|
|
|
|
|
\func{void *}{GetSymbol}{\param{wxDllType }{dllHandle}, \param{const wxString\& }{name}}
|
|
|
|
|
|
|
|
This function resolves a symbol in a loaded DLL, such as a variable or
|
|
|
|
function name.
|
|
|
|
|
|
|
|
Returned value will be {\tt NULL} if the symbol was not found in the DLL or if
|
2005-04-08 14:34:30 +00:00
|
|
|
an error occurred.
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
\wxheading{Parameters}
|
|
|
|
|
|
|
|
\docparam{dllHandle}{Valid handle previously returned by
|
|
|
|
\helpref{LoadLibrary}{wxdllloaderloadlibrary}}
|
|
|
|
|
|
|
|
\docparam{name}{Name of the symbol.}
|
|
|
|
|
|
|
|
\membersection{wxDllLoader::LoadLibrary}\label{wxdllloaderloadlibrary}
|
|
|
|
|
|
|
|
\func{wxDllType}{LoadLibrary}{\param{const wxString \& }{libname}, \param{bool* }{success = NULL}}
|
|
|
|
|
|
|
|
This function loads a shared library into memory, with {\it libname} being the
|
|
|
|
name of the library: it may be either the full name including path and
|
2002-06-07 20:15:28 +00:00
|
|
|
(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
|
2000-07-15 19:51:35 +00:00
|
|
|
searched in all standard locations.
|
|
|
|
|
|
|
|
Returns a handle to the loaded DLL. Use {\it success} parameter to test if it
|
|
|
|
is valid. If the handle is valid, the library must be unloaded later with
|
|
|
|
\helpref{UnloadLibrary}{wxdllloaderunloadlibrary}.
|
|
|
|
|
|
|
|
\wxheading{Parameters}
|
|
|
|
|
|
|
|
\docparam{libname}{Name of the shared object to load.}
|
|
|
|
|
2003-01-18 00:16:34 +00:00
|
|
|
\docparam{success}{May point to a bool variable which will be set to true or
|
|
|
|
false; may also be {\tt NULL}.}
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
\membersection{wxDllLoader::UnloadLibrary}\label{wxdllloaderunloadlibrary}
|
|
|
|
|
|
|
|
\func{void}{UnloadLibrary}{\param{wxDllType }{dllhandle}}
|
|
|
|
|
|
|
|
This function unloads the shared library. The handle {\it dllhandle} must have
|
|
|
|
been returned by \helpref{LoadLibrary}{wxdllloaderloadlibrary} previously.
|
|
|
|
|