]>
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 | ||
ed58dbea | 19 | #include "wx/setup.h" |
8a0d4cf6 VZ |
20 | |
21 | #if wxUSE_DYNLIB_CLASS | |
22 | ||
ed58dbea RR |
23 | #include "wx/string.h" |
24 | #include "wx/list.h" | |
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 | ||
1a787c5d SN |
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__) | |
39 | # define INCL_DOS | |
40 | # include <os2.h> | |
41 | typedef HMODULE wxDllType; | |
42 | #elif defined(HAVE_DLOPEN) | |
a585ca5c | 43 | # include <dlfcn.h> |
7b0bfbb2 | 44 | typedef void *wxDllType; |
8a0d4cf6 | 45 | #elif defined(HAVE_SHL_LOAD) |
a585ca5c | 46 | # include <dl.h> |
8a0d4cf6 | 47 | typedef shl_t wxDllType; |
7b0bfbb2 | 48 | #elif defined(__WINDOWS__) |
3c1a88d8 | 49 | # include <windows.h> // needed to get HMODULE |
7b0bfbb2 VZ |
50 | typedef HMODULE wxDllType; |
51 | #elif defined(__WXMAC__) | |
52 | typedef CFragConnectionID wxDllType; | |
53 | #else | |
a585ca5c | 54 | # error "wxLibrary can't be compiled on this platform, sorry." |
7b0bfbb2 VZ |
55 | #endif // OS |
56 | ||
7cc98b3e VZ |
57 | // LoadLibrary is defined in windows.h as LoadLibraryA, but wxDllLoader method |
58 | // should be called LoadLibrary, not LoadLibraryA or LoadLibraryW! | |
59 | #if defined(__WIN32__) && defined(LoadLibrary) | |
60 | # include "wx/msw/winundef.h" | |
7c0f3a1e | 61 | #endif |
0c32066b | 62 | |
a585ca5c KB |
63 | // ---------------------------------------------------------------------------- |
64 | // wxDllLoader | |
65 | // ---------------------------------------------------------------------------- | |
3c1a88d8 | 66 | |
a585ca5c KB |
67 | /** wxDllLoader is a class providing an interface similar to unix's |
68 | dlopen(). It is used by the wxLibrary framework and manages the | |
69 | actual loading of DLLs and the resolving of symbols in them. | |
70 | There are no instances of this class, it simply serves as a | |
71 | namespace for its static member functions. | |
72 | */ | |
b97a2c53 | 73 | class WXDLLEXPORT wxDllLoader |
a585ca5c | 74 | { |
3c1a88d8 VZ |
75 | public: |
76 | /** This function loads a shared library into memory, with libname | |
77 | being the basename of the library, without the filename | |
78 | extension. No initialisation of the library will be done. | |
79 | @param libname Name of the shared object to load. | |
80 | @param success Must point to a bool variable which will be set to TRUE or FALSE. | |
81 | @return A handle to the loaded DLL. Use success parameter to test if it is valid. | |
82 | */ | |
83 | static wxDllType LoadLibrary(const wxString & libname, bool *success = NULL); | |
84 | /** This function unloads the shared library. */ | |
85 | static void UnloadLibrary(wxDllType dll); | |
86 | /** This function returns a valid handle for the main program | |
87 | itself. */ | |
88 | static wxDllType GetProgramHandle(void); | |
89 | /** This function resolves a symbol in a loaded DLL, such as a | |
90 | variable or function name. | |
91 | @param dllHandle Handle of the DLL, as returned by LoadDll(). | |
92 | @param name Name of the symbol. | |
93 | @return A pointer to the symbol. | |
94 | */ | |
95 | static void * GetSymbol(wxDllType dllHandle, const wxString &name); | |
96 | ||
f6bcfd97 BP |
97 | // return the standard DLL extension (with leading dot) for this platform |
98 | static wxString GetDllExt(); | |
99 | ||
3c1a88d8 VZ |
100 | private: |
101 | /// forbid construction of objects | |
102 | wxDllLoader(); | |
a585ca5c KB |
103 | }; |
104 | ||
7b0bfbb2 | 105 | // ---------------------------------------------------------------------------- |
7a4b9130 | 106 | // wxLibrary |
7b0bfbb2 | 107 | // ---------------------------------------------------------------------------- |
7a4b9130 | 108 | |
b97a2c53 | 109 | class WXDLLEXPORT wxLibrary : public wxObject |
7b0bfbb2 VZ |
110 | { |
111 | public: | |
112 | wxHashTable classTable; | |
f4a8c29f | 113 | |
7b0bfbb2 | 114 | public: |
8a0d4cf6 | 115 | wxLibrary(wxDllType handle); |
7b0bfbb2 | 116 | ~wxLibrary(); |
7a4b9130 | 117 | |
7b0bfbb2 VZ |
118 | // Get a symbol from the dynamic library |
119 | void *GetSymbol(const wxString& symbname); | |
7a4b9130 | 120 | |
7b0bfbb2 VZ |
121 | // Create the object whose classname is "name" |
122 | wxObject *CreateObject(const wxString& name); | |
7a4b9130 | 123 | |
7b0bfbb2 VZ |
124 | protected: |
125 | void PrepareClasses(wxClassInfo *first); | |
f4a8c29f | 126 | |
7b0bfbb2 | 127 | wxDllType m_handle; |
7a4b9130 GL |
128 | }; |
129 | ||
a585ca5c KB |
130 | |
131 | ||
7b0bfbb2 | 132 | // ---------------------------------------------------------------------------- |
7a4b9130 | 133 | // wxLibraries |
7b0bfbb2 VZ |
134 | // ---------------------------------------------------------------------------- |
135 | ||
b97a2c53 | 136 | class WXDLLEXPORT wxLibraries |
7b0bfbb2 VZ |
137 | { |
138 | public: | |
139 | wxLibraries(); | |
140 | ~wxLibraries(); | |
7a4b9130 | 141 | |
7b0bfbb2 VZ |
142 | // caller is responsible for deleting the returned pointer if !NULL |
143 | wxLibrary *LoadLibrary(const wxString& basename); | |
7a4b9130 | 144 | |
7b0bfbb2 VZ |
145 | wxObject *CreateObject(const wxString& name); |
146 | ||
147 | protected: | |
148 | wxList m_loaded; | |
7a4b9130 GL |
149 | }; |
150 | ||
7b0bfbb2 | 151 | // ---------------------------------------------------------------------------- |
7a4b9130 | 152 | // Global variables |
7b0bfbb2 | 153 | // ---------------------------------------------------------------------------- |
7a4b9130 GL |
154 | |
155 | extern wxLibraries wxTheLibraries; | |
156 | ||
7b0bfbb2 | 157 | // ---------------------------------------------------------------------------- |
7a4b9130 | 158 | // Interesting defines |
7b0bfbb2 | 159 | // ---------------------------------------------------------------------------- |
7a4b9130 | 160 | |
f4a8c29f | 161 | #define WXDLL_ENTRY_FUNCTION() \ |
856d2e52 GL |
162 | extern "C" wxClassInfo *wxGetClassFirst(); \ |
163 | wxClassInfo *wxGetClassFirst() { \ | |
164 | return wxClassInfo::GetFirst(); \ | |
f4a8c29f | 165 | } |
7a4b9130 | 166 | |
8a0d4cf6 VZ |
167 | #endif // wxUSE_DYNLIB_CLASS |
168 | ||
7b0bfbb2 | 169 | #endif // _WX_DYNLIB_H__ |