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(__WXMAC__)
46 typedef CFragConnectionID wxDllType
;
48 # error "wxLibrary can't be compiled on this platform, sorry."
51 // defined in windows.h
52 // This breaks app.cpp if RICHEDIT is included.
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
62 /** wxDllLoader is a class providing an interface similar to unix's
63 dlopen(). It is used by the wxLibrary framework and manages the
64 actual loading of DLLs and the resolving of symbols in them.
65 There are no instances of this class, it simply serves as a
66 namespace for its static member functions.
71 /** This function loads a shared library into memory, with libname
72 being the basename of the library, without the filename
73 extension. No initialisation of the library will be done.
74 @param libname Name of the shared object to load.
75 @param success Must point to a bool variable which will be set to TRUE or FALSE.
76 @return A handle to the loaded DLL. Use success parameter to test if it is valid.
78 static wxDllType
LoadLibrary(const wxString
& libname
, bool *success
);
79 /** This function resolves a symbol in a loaded DLL, such as a
80 variable or function name.
81 @param dllHandle Handle of the DLL, as returned by LoadDll().
82 @param name Name of the symbol.
83 @return A pointer to the symbol.
85 static void * GetSymbol(wxDllType dllHandle
, const wxString
&name
);
87 /// forbid construction of objects
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 class wxLibrary
: public wxObject
98 wxHashTable classTable
;
101 wxLibrary(wxDllType handle
);
104 // Get a symbol from the dynamic library
105 void *GetSymbol(const wxString
& symbname
);
107 // Create the object whose classname is "name"
108 wxObject
*CreateObject(const wxString
& name
);
111 void PrepareClasses(wxClassInfo
*first
);
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
128 // caller is responsible for deleting the returned pointer if !NULL
129 wxLibrary
*LoadLibrary(const wxString
& basename
);
131 wxObject
*CreateObject(const wxString
& name
);
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 extern wxLibraries wxTheLibraries
;
143 // ----------------------------------------------------------------------------
144 // Interesting defines
145 // ----------------------------------------------------------------------------
147 #define WXDLL_ENTRY_FUNCTION() \
148 extern "C" wxClassInfo *wxGetClassFirst(); \
149 wxClassInfo *wxGetClassFirst() { \
150 return wxClassInfo::GetFirst(); \
153 #endif // wxUSE_DYNLIB_CLASS
155 #endif // _WX_DYNLIB_H__