]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/dllload.tex
mention Watcom makefile for wxBase
[wxWidgets.git] / docs / latex / wx / dllload.tex
CommitLineData
f6bcfd97
BP
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: dllload.tex
3%% Purpose: wxDllLoader documentation
4%% Author: Vadim Zeitlin
5%% Modified by:
6%% Created: 02.04.00
7%% RCS-ID: $Id$
8%% Copyright: (c) Vadim Zeitlin
9%% License: wxWindows license
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12\section{\class{wxDllLoader}}\label{wxdllloader}
13
14wxDllLoader is a class providing an interface similar to Unix's {\tt
15dlopen()}. It is used by the wxLibrary framework and manages the actual
16loading of shared libraries and the resolving of symbols in them. There are no
17instances of this class, it simply serves as a namespace for its static member
18functions.
19
181b4068
VS
20Please note that class \helpref{wxDynamicLibrary}{wxdynamiclibrary} provides
21alternative, friendlier interface to wxDllLoader.
22
f6bcfd97
BP
23The terms {\it DLL} and {\it shared library/object} will both be used in the
24documentation to refer to the same thing: a {\tt .dll} file under Windows or
25{\tt .so} or {\tt .sl} one under Unix.
26
567f21d2 27Example of using this class to dynamically load the {\tt strlen()} function:
f6bcfd97
BP
28
29\begin{verbatim}
30#if defined(__WXMSW__)
31 static const wxChar *LIB_NAME = _T("kernel32");
32 static const wxChar *FUNC_NAME = _T("lstrlenA");
33#elif defined(__UNIX__)
34 static const wxChar *LIB_NAME = _T("/lib/libc-2.0.7.so");
35 static const wxChar *FUNC_NAME = _T("strlen");
36#endif
37
38 wxDllType dllHandle = wxDllLoader::LoadLibrary(LIB_NAME);
39 if ( !dllHandle )
40 {
41 ... error ...
42 }
43 else
44 {
45 typedef int (*strlenType)(char *);
46 strlenType pfnStrlen = (strlenType)wxDllLoader::GetSymbol(dllHandle, FUNC_NAME);
47 if ( !pfnStrlen )
48 {
49 ... error ...
50 }
51 else
52 {
53 if ( pfnStrlen("foo") != 3 )
54 {
55 ... error ...
56 }
57 else
58 {
59 ... ok! ...
60 }
61 }
62
63 wxDllLoader::UnloadLibrary(dllHandle);
64 }
65\end{verbatim}
66
67\wxheading{Derived from}
68
69No base class
70
71\wxheading{Include files}
72
73<wx/dynlib.h>
74
75\wxheading{Data structures}
76
2edb0bde 77This header defines a platform-dependent {\tt wxDllType} typedef which stores
f6bcfd97
BP
78a handle to a loaded DLLs on the given platform.
79
80\latexignore{\rtfignore{\wxheading{Members}}}
81
82\membersection{wxDllLoader::GetDllExt}\label{wxdllloadergetdllext}
83
84\func{static wxString}{GetDllExt}{\void}
85
86Returns the string containing the usual extension for shared libraries for the
87given systems (including the leading dot if not empty).
88
89For example, this function will return {\tt ".dll"} under Windows or (usually)
90{\tt ".so"} under Unix.
91
92\membersection{wxDllLoader::GetProgramHandle}\label{wxdllloadergetprogramhandle}
93
94\func{wxDllType}{GetProgramHandle}{\void}
95
96This function returns a valid handle for the main program itself. Notice that
97the {\tt NULL} return value is valid for some systems (i.e. doesn't mean that
98the function failed).
99
100{\bf NB:} This function is Unix specific. It will always fail under Windows
101or OS/2.
102
103\membersection{wxDllLoader::GetSymbol}\label{wxdllloadergetsymbol}
104
105\func{void *}{GetSymbol}{\param{wxDllType }{dllHandle}, \param{const wxString\& }{name}}
106
107This function resolves a symbol in a loaded DLL, such as a variable or
108function name.
109
110Returned value will be {\tt NULL} if the symbol was not found in the DLL or if
111an error occured.
112
113\wxheading{Parameters}
114
115\docparam{dllHandle}{Valid handle previously returned by
116\helpref{LoadLibrary}{wxdllloaderloadlibrary}}
117
118\docparam{name}{Name of the symbol.}
119
120\membersection{wxDllLoader::LoadLibrary}\label{wxdllloaderloadlibrary}
121
122\func{wxDllType}{LoadLibrary}{\param{const wxString \& }{libname}, \param{bool* }{success = NULL}}
123
124This function loads a shared library into memory, with {\it libname} being the
125name of the library: it may be either the full name including path and
2edb0bde
VZ
126(platform-dependent) extension, just the basename (no path and no extension)
127or a basename with extension. In the last two cases, the library will be
f6bcfd97
BP
128searched in all standard locations.
129
130Returns a handle to the loaded DLL. Use {\it success} parameter to test if it
131is valid. If the handle is valid, the library must be unloaded later with
132\helpref{UnloadLibrary}{wxdllloaderunloadlibrary}.
133
134\wxheading{Parameters}
135
136\docparam{libname}{Name of the shared object to load.}
137
cc81d32f
VS
138\docparam{success}{May point to a bool variable which will be set to true or
139false; may also be {\tt NULL}.}
f6bcfd97
BP
140
141\membersection{wxDllLoader::UnloadLibrary}\label{wxdllloaderunloadlibrary}
142
143\func{void}{UnloadLibrary}{\param{wxDllType }{dllhandle}}
144
145This function unloads the shared library. The handle {\it dllhandle} must have
146been returned by \helpref{LoadLibrary}{wxdllloaderloadlibrary} previously.
147