1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dynamic library management
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DYNLIB_H__
13 #define _WX_DYNLIB_H__
21 #if wxUSE_DYNLIB_CLASS
23 #include "wx/string.h"
27 // this is normally done by configure, but I leave it here for now...
28 #if defined(__UNIX__) && !(defined(HAVE_DLOPEN) || defined(HAVE_SHL_LOAD))
29 # if defined(__LINUX__) || defined(__SOLARIS__) || defined(__SUNOS__) || defined(__FREEBSD__)
31 # elif defined(__HPUX__)
32 # define HAVE_SHL_LOAD
33 # endif // Unix flavour
34 #endif // !Unix or already have some HAVE_xxx defined
36 // Note: WXPM/EMX has to be tested first, since we want to use
37 // native version, even if configure detected presence of DLOPEN.
38 #if defined(__WXPM__) || defined(__EMX__)
41 typedef HMODULE wxDllType
;
42 #elif defined(HAVE_DLOPEN)
44 typedef void *wxDllType
;
45 #elif defined(HAVE_SHL_LOAD)
47 typedef shl_t wxDllType
;
48 #elif defined(__WINDOWS__)
49 # include <windows.h> // needed to get HMODULE
50 typedef HMODULE wxDllType
;
51 #elif defined(__APPLE__) && defined(__UNIX__)
52 typedef void *wxDllType
;
53 #elif defined(__WXMAC__)
54 typedef CFragConnectionID wxDllType
;
56 # error "wxLibrary can't be compiled on this platform, sorry."
59 // LoadLibrary is defined in windows.h as LoadLibraryA, but wxDllLoader method
60 // should be called LoadLibrary, not LoadLibraryA or LoadLibraryW!
61 #if defined(__WIN32__) && defined(LoadLibrary)
62 # include "wx/msw/winundef.h"
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 /** wxDllLoader is a class providing an interface similar to unix's
70 dlopen(). It is used by the wxLibrary framework and manages the
71 actual loading of DLLs and the resolving of symbols in them.
72 There are no instances of this class, it simply serves as a
73 namespace for its static member functions.
75 class WXDLLEXPORT wxDllLoader
78 /** This function loads a shared library into memory, with libname
79 being the basename of the library, without the filename
80 extension. No initialisation of the library will be done.
81 @param libname Name of the shared object to load.
82 @param success Must point to a bool variable which will be set to TRUE or FALSE.
83 @return A handle to the loaded DLL. Use success parameter to test if it is valid.
85 static wxDllType
LoadLibrary(const wxString
& libname
, bool *success
= NULL
);
86 /** This function unloads the shared library. */
87 static void UnloadLibrary(wxDllType dll
);
88 /** This function returns a valid handle for the main program
90 static wxDllType
GetProgramHandle(void);
91 /** This function resolves a symbol in a loaded DLL, such as a
92 variable or function name.
93 @param dllHandle Handle of the DLL, as returned by LoadDll().
94 @param name Name of the symbol.
95 @return A pointer to the symbol.
97 static void * GetSymbol(wxDllType dllHandle
, const wxString
&name
);
99 // return the standard DLL extension (with leading dot) for this platform
100 static wxString
GetDllExt();
103 /// forbid construction of objects
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 class WXDLLEXPORT wxLibrary
: public wxObject
114 wxHashTable classTable
;
117 wxLibrary(wxDllType handle
);
120 // Get a symbol from the dynamic library
121 void *GetSymbol(const wxString
& symbname
);
123 // Create the object whose classname is "name"
124 wxObject
*CreateObject(const wxString
& name
);
127 void PrepareClasses(wxClassInfo
*first
);
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 class WXDLLEXPORT wxLibraries
144 // caller is responsible for deleting the returned pointer if !NULL
145 wxLibrary
*LoadLibrary(const wxString
& basename
);
147 wxObject
*CreateObject(const wxString
& name
);
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 extern wxLibraries wxTheLibraries
;
159 // ----------------------------------------------------------------------------
160 // Interesting defines
161 // ----------------------------------------------------------------------------
163 #define WXDLL_ENTRY_FUNCTION() \
164 extern "C" wxClassInfo *wxGetClassFirst(); \
165 wxClassInfo *wxGetClassFirst() { \
166 return wxClassInfo::GetFirst(); \
169 #endif // wxUSE_DYNLIB_CLASS
171 #endif // _WX_DYNLIB_H__