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 #if defined(HAVE_DLOPEN)
38 typedef void *wxDllType
;
39 #elif defined(HAVE_SHL_LOAD)
41 typedef shl_t wxDllType
;
42 #elif defined(__WINDOWS__)
44 typedef HMODULE wxDllType
;
45 #elif defined(__OS2__)
48 typedef HMODULE wxDllType
;
49 #elif defined(__WXMAC__)
50 typedef CFragConnectionID wxDllType
;
52 # error "wxLibrary can't be compiled on this platform, sorry."
55 // LoadLibrary is defined in windows.h as LoadLibraryA, but wxDllLoader method
56 // should be called LoadLibrary, not LoadLibraryA or LoadLibraryW!
57 #if defined(__WIN32__) && defined(LoadLibrary)
58 # include "wx/msw/winundef.h"
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
64 /** wxDllLoader is a class providing an interface similar to unix's
65 dlopen(). It is used by the wxLibrary framework and manages the
66 actual loading of DLLs and the resolving of symbols in them.
67 There are no instances of this class, it simply serves as a
68 namespace for its static member functions.
73 /** This function loads a shared library into memory, with libname
74 being the basename of the library, without the filename
75 extension. No initialisation of the library will be done.
76 @param libname Name of the shared object to load.
77 @param success Must point to a bool variable which will be set to TRUE or FALSE.
78 @return A handle to the loaded DLL. Use success parameter to test if it is valid.
80 static wxDllType
LoadLibrary(const wxString
& libname
, bool *success
= NULL
);
81 /** This function unloads the shared library. */
82 static void UnloadLibrary(wxDllType dll
);
83 /** This function returns a valid handle for the main program
85 static wxDllType
GetProgramHandle(void);
86 /** This function resolves a symbol in a loaded DLL, such as a
87 variable or function name.
88 @param dllHandle Handle of the DLL, as returned by LoadDll().
89 @param name Name of the symbol.
90 @return A pointer to the symbol.
92 static void * GetSymbol(wxDllType dllHandle
, const wxString
&name
);
94 /// forbid construction of objects
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 class wxLibrary
: public wxObject
105 wxHashTable classTable
;
108 wxLibrary(wxDllType handle
);
111 // Get a symbol from the dynamic library
112 void *GetSymbol(const wxString
& symbname
);
114 // Create the object whose classname is "name"
115 wxObject
*CreateObject(const wxString
& name
);
118 void PrepareClasses(wxClassInfo
*first
);
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
135 // caller is responsible for deleting the returned pointer if !NULL
136 wxLibrary
*LoadLibrary(const wxString
& basename
);
138 wxObject
*CreateObject(const wxString
& name
);
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 extern wxLibraries wxTheLibraries
;
150 // ----------------------------------------------------------------------------
151 // Interesting defines
152 // ----------------------------------------------------------------------------
154 #define WXDLL_ENTRY_FUNCTION() \
155 extern "C" wxClassInfo *wxGetClassFirst(); \
156 wxClassInfo *wxGetClassFirst() { \
157 return wxClassInfo::GetFirst(); \
160 #endif // wxUSE_DYNLIB_CLASS
162 #endif // _WX_DYNLIB_H__