]>
Commit | Line | Data |
---|---|---|
7b0bfbb2 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dynlib.cpp | |
3 | // Purpose: Dynamic library management | |
4 | // Author: Guilhem Lavaux | |
5 | // Modified by: | |
6 | // Created: 20/07/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Guilhem Lavaux | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_DYNLIB_H__ |
13 | #define _WX_DYNLIB_H__ | |
7a4b9130 GL |
14 | |
15 | #ifdef __GNUG__ | |
a585ca5c | 16 | # pragma interface |
7a4b9130 GL |
17 | #endif |
18 | ||
8a0d4cf6 VZ |
19 | #include <wx/setup.h> |
20 | ||
21 | #if wxUSE_DYNLIB_CLASS | |
22 | ||
7a4b9130 GL |
23 | #include <wx/string.h> |
24 | #include <wx/list.h> | |
f4a8c29f | 25 | #include <wx/hash.h> |
7a4b9130 | 26 | |
8a0d4cf6 VZ |
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)) | |
a585ca5c KB |
29 | # if defined(__LINUX__) || defined(__SOLARIS__) || defined(__SUNOS__) || defined(__FREEBSD__) |
30 | # define HAVE_DLOPEN | |
31 | # elif defined(__HPUX__) | |
32 | # define HAVE_SHL_LOAD | |
33 | # endif // Unix flavour | |
3e4efd7c VZ |
34 | #endif // !Unix or already have some HAVE_xxx defined |
35 | ||
7b0bfbb2 | 36 | #if defined(HAVE_DLOPEN) |
a585ca5c | 37 | # include <dlfcn.h> |
7b0bfbb2 | 38 | typedef void *wxDllType; |
8a0d4cf6 | 39 | #elif defined(HAVE_SHL_LOAD) |
a585ca5c | 40 | # include <dl.h> |
8a0d4cf6 | 41 | typedef shl_t wxDllType; |
7b0bfbb2 | 42 | #elif defined(__WINDOWS__) |
a585ca5c | 43 | # include <windows.h> |
7b0bfbb2 VZ |
44 | typedef HMODULE wxDllType; |
45 | #elif defined(__WXMAC__) | |
46 | typedef CFragConnectionID wxDllType; | |
47 | #else | |
a585ca5c | 48 | # error "wxLibrary can't be compiled on this platform, sorry." |
7b0bfbb2 VZ |
49 | #endif // OS |
50 | ||
51 | // defined in windows.h | |
7c0f3a1e UU |
52 | // This breaks app.cpp if RICHEDIT is included. |
53 | #if 0 | |
0c32066b | 54 | #ifdef LoadLibrary |
a585ca5c | 55 | # undef LoadLibrary |
0c32066b | 56 | #endif |
7c0f3a1e | 57 | #endif |
0c32066b | 58 | |
a585ca5c KB |
59 | // ---------------------------------------------------------------------------- |
60 | // wxDllLoader | |
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. | |
67 | */ | |
68 | class wxDllLoader | |
69 | { | |
70 | public: | |
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. | |
77 | */ | |
4dc2c3bb | 78 | static wxDllType LoadLibrary(const wxString & libname, bool *success); |
752c7d6b KB |
79 | /** This function unloads the shared library. */ |
80 | static void UnloadLibrary(wxDllType dll); | |
0868079c KB |
81 | /** This function returns a valid handle for the main program |
82 | itself. */ | |
83 | static wxDllType GetProgramHandle(void); | |
a585ca5c KB |
84 | /** This function resolves a symbol in a loaded DLL, such as a |
85 | variable or function name. | |
86 | @param dllHandle Handle of the DLL, as returned by LoadDll(). | |
87 | @param name Name of the symbol. | |
88 | @return A pointer to the symbol. | |
89 | */ | |
90 | static void * GetSymbol(wxDllType dllHandle, const wxString &name); | |
91 | private: | |
92 | /// forbid construction of objects | |
3d2afb7a | 93 | wxDllLoader(); |
a585ca5c KB |
94 | }; |
95 | ||
7b0bfbb2 | 96 | // ---------------------------------------------------------------------------- |
7a4b9130 | 97 | // wxLibrary |
7b0bfbb2 | 98 | // ---------------------------------------------------------------------------- |
7a4b9130 | 99 | |
7b0bfbb2 VZ |
100 | class wxLibrary : public wxObject |
101 | { | |
102 | public: | |
103 | wxHashTable classTable; | |
f4a8c29f | 104 | |
7b0bfbb2 | 105 | public: |
8a0d4cf6 | 106 | wxLibrary(wxDllType handle); |
7b0bfbb2 | 107 | ~wxLibrary(); |
7a4b9130 | 108 | |
7b0bfbb2 VZ |
109 | // Get a symbol from the dynamic library |
110 | void *GetSymbol(const wxString& symbname); | |
7a4b9130 | 111 | |
7b0bfbb2 VZ |
112 | // Create the object whose classname is "name" |
113 | wxObject *CreateObject(const wxString& name); | |
7a4b9130 | 114 | |
7b0bfbb2 VZ |
115 | protected: |
116 | void PrepareClasses(wxClassInfo *first); | |
f4a8c29f | 117 | |
7b0bfbb2 | 118 | wxDllType m_handle; |
7a4b9130 GL |
119 | }; |
120 | ||
a585ca5c KB |
121 | |
122 | ||
7b0bfbb2 | 123 | // ---------------------------------------------------------------------------- |
7a4b9130 | 124 | // wxLibraries |
7b0bfbb2 VZ |
125 | // ---------------------------------------------------------------------------- |
126 | ||
127 | class wxLibraries | |
128 | { | |
129 | public: | |
130 | wxLibraries(); | |
131 | ~wxLibraries(); | |
7a4b9130 | 132 | |
7b0bfbb2 VZ |
133 | // caller is responsible for deleting the returned pointer if !NULL |
134 | wxLibrary *LoadLibrary(const wxString& basename); | |
7a4b9130 | 135 | |
7b0bfbb2 VZ |
136 | wxObject *CreateObject(const wxString& name); |
137 | ||
138 | protected: | |
139 | wxList m_loaded; | |
7a4b9130 GL |
140 | }; |
141 | ||
7b0bfbb2 | 142 | // ---------------------------------------------------------------------------- |
7a4b9130 | 143 | // Global variables |
7b0bfbb2 | 144 | // ---------------------------------------------------------------------------- |
7a4b9130 GL |
145 | |
146 | extern wxLibraries wxTheLibraries; | |
147 | ||
7b0bfbb2 | 148 | // ---------------------------------------------------------------------------- |
7a4b9130 | 149 | // Interesting defines |
7b0bfbb2 | 150 | // ---------------------------------------------------------------------------- |
7a4b9130 | 151 | |
f4a8c29f | 152 | #define WXDLL_ENTRY_FUNCTION() \ |
856d2e52 GL |
153 | extern "C" wxClassInfo *wxGetClassFirst(); \ |
154 | wxClassInfo *wxGetClassFirst() { \ | |
155 | return wxClassInfo::GetFirst(); \ | |
f4a8c29f | 156 | } |
7a4b9130 | 157 | |
8a0d4cf6 VZ |
158 | #endif // wxUSE_DYNLIB_CLASS |
159 | ||
7b0bfbb2 | 160 | #endif // _WX_DYNLIB_H__ |