/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/include/wx/dynlib.h
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/include/wx/dynlib.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 5 months ago) by william
File MIME type: text/plain
File size: 12657 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dynlib.h
3 // Purpose: Dynamic library loading classes
4 // Author: Guilhem Lavaux, Vadim Zeitlin, Vaclav Slavik
5 // Modified by:
6 // Created: 20/07/98
7 // RCS-ID: $Id: dynlib.h 58750 2009-02-08 10:01:03Z VZ $
8 // Copyright: (c) 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DYNLIB_H__
13 #define _WX_DYNLIB_H__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DYNLIB_CLASS
18
19 #include "wx/string.h"
20 #include "wx/dynarray.h"
21
22 #if defined(__OS2__) || defined(__EMX__)
23 #include "wx/os2/private.h"
24 #endif
25
26 #ifdef __WXMSW__
27 // PCSX2: Can we PLEASE not include windows.h into everything, just for HINSTANCE? >_< --air
28 //#include "wx/msw/private.h"
29 #endif
30
31 // note that we have our own dlerror() implementation under Darwin
32 #if (defined(HAVE_DLERROR) && !defined(__EMX__)) || defined(__DARWIN__)
33 #define wxHAVE_DYNLIB_ERROR
34 #endif
35
36 class WXDLLIMPEXP_FWD_BASE wxDynamicLibraryDetailsCreator;
37
38 // ----------------------------------------------------------------------------
39 // conditional compilation
40 // ----------------------------------------------------------------------------
41
42 // Note: __OS2__/EMX has to be tested first, since we want to use
43 // native version, even if configure detected presence of DLOPEN.
44 #if defined(__OS2__) || defined(__EMX__) || defined(__WINDOWS__)
45 typedef HINSTANCE HMODULE;
46 typedef HMODULE wxDllType;
47 #elif defined(__DARWIN__)
48 // Don't include dlfcn.h on Darwin, we may be using our own replacements.
49 typedef void *wxDllType;
50 #elif defined(HAVE_DLOPEN)
51 #include <dlfcn.h>
52 typedef void *wxDllType;
53 #elif defined(HAVE_SHL_LOAD)
54 #include <dl.h>
55 typedef shl_t wxDllType;
56 #elif defined(__WXMAC__)
57 #include <CodeFragments.h>
58 typedef CFragConnectionID wxDllType;
59 #else
60 #error "Dynamic Loading classes can't be compiled on this platform, sorry."
61 #endif
62
63 // ----------------------------------------------------------------------------
64 // constants
65 // ----------------------------------------------------------------------------
66
67 enum wxDLFlags
68 {
69 wxDL_LAZY = 0x00000001, // resolve undefined symbols at first use
70 // (only works on some Unix versions)
71 wxDL_NOW = 0x00000002, // resolve undefined symbols on load
72 // (default, always the case under Win32)
73 wxDL_GLOBAL = 0x00000004, // export extern symbols to subsequently
74 // loaded libs.
75 wxDL_VERBATIM = 0x00000008, // attempt to load the supplied library
76 // name without appending the usual dll
77 // filename extension.
78 wxDL_NOSHARE = 0x00000010, // load new DLL, don't reuse already loaded
79 // (only for wxPluginManager)
80
81 wxDL_QUIET = 0x00000020, // don't log an error if failed to load
82
83 #if wxABI_VERSION >= 20810
84 // this flag is dangerous, for internal use of wxMSW only, don't use at all
85 // and especially don't use directly, use wxLoadedDLL instead if you really
86 // do need it
87 wxDL_GET_LOADED = 0x00000040, // Win32 only: return handle of already
88 // loaded DLL or NULL otherwise; Unload()
89 // should not be called so don't forget to
90 // Detach() if you use this function
91 #endif // wx 2.8.10+
92
93 wxDL_DEFAULT = wxDL_NOW // default flags correspond to Win32
94 };
95
96 enum wxDynamicLibraryCategory
97 {
98 wxDL_LIBRARY, // standard library
99 wxDL_MODULE // loadable module/plugin
100 };
101
102 enum wxPluginCategory
103 {
104 wxDL_PLUGIN_GUI, // plugin that uses GUI classes
105 wxDL_PLUGIN_BASE // wxBase-only plugin
106 };
107
108 // ----------------------------------------------------------------------------
109 // macros
110 // ----------------------------------------------------------------------------
111
112 // when loading a function from a DLL you always have to cast the returned
113 // "void *" pointer to the correct type and, even more annoyingly, you have to
114 // repeat this type twice if you want to declare and define a function pointer
115 // all in one line
116 //
117 // this macro makes this slightly less painful by allowing you to specify the
118 // type only once, as the first parameter, and creating a variable of this type
119 // called "pfn<name>" initialized with the "name" from the "dynlib"
120 #define wxDYNLIB_FUNCTION(type, name, dynlib) \
121 type pfn ## name = (type)(dynlib).GetSymbol(_T(#name))
122
123 // ----------------------------------------------------------------------------
124 // wxDynamicLibraryDetails: contains details about a loaded wxDynamicLibrary
125 // ----------------------------------------------------------------------------
126
127 class WXDLLIMPEXP_BASE wxDynamicLibraryDetails
128 {
129 public:
130 // ctor, normally never used as these objects are only created by
131 // wxDynamicLibrary::ListLoaded()
132 wxDynamicLibraryDetails() { m_address = NULL; m_length = 0; }
133
134 // get the (base) name
135 wxString GetName() const { return m_name; }
136
137 // get the full path of this object
138 wxString GetPath() const { return m_path; }
139
140 // get the load address and the extent, return true if this information is
141 // available
142 bool GetAddress(void **addr, size_t *len) const
143 {
144 if ( !m_address )
145 return false;
146
147 if ( addr )
148 *addr = m_address;
149 if ( len )
150 *len = m_length;
151
152 return true;
153 }
154
155 // return the version of the DLL (may be empty if no version info)
156 wxString GetVersion() const
157 {
158 return m_version;
159 }
160
161 private:
162 wxString m_name,
163 m_path,
164 m_version;
165
166 void *m_address;
167 size_t m_length;
168
169 friend class wxDynamicLibraryDetailsCreator;
170 };
171
172 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxDynamicLibraryDetails,
173 wxDynamicLibraryDetailsArray,
174 WXDLLIMPEXP_BASE);
175
176 // ----------------------------------------------------------------------------
177 // wxDynamicLibrary: represents a handle to a DLL/shared object
178 // ----------------------------------------------------------------------------
179
180 class WXDLLIMPEXP_BASE wxDynamicLibrary
181 {
182 public:
183 // return a valid handle for the main program itself or NULL if back
184 // linking is not supported by the current platform (e.g. Win32)
185 static wxDllType GetProgramHandle();
186
187 // return the platform standard DLL extension (with leading dot)
188 static const wxChar *GetDllExt() { return ms_dllext; }
189
190 wxDynamicLibrary() : m_handle(0) { }
191 wxDynamicLibrary(const wxString& libname, int flags = wxDL_DEFAULT)
192 : m_handle(0)
193 {
194 Load(libname, flags);
195 }
196
197 // NOTE: this class is (deliberately) not virtual, do not attempt
198 // to use it polymorphically.
199 ~wxDynamicLibrary() { Unload(); }
200
201 // return true if the library was loaded successfully
202 bool IsLoaded() const { return m_handle != 0; }
203
204 // load the library with the given name (full or not), return true if ok
205 bool Load(const wxString& libname, int flags = wxDL_DEFAULT);
206
207 // raw function for loading dynamic libs: always behaves as if
208 // wxDL_VERBATIM were specified and doesn't log error message if the
209 // library couldn't be loaded but simply returns NULL
210 static wxDllType RawLoad(const wxString& libname, int flags = wxDL_DEFAULT);
211
212 // detach the library object from its handle, i.e. prevent the object from
213 // unloading the library in its dtor -- the caller is now responsible for
214 // doing this
215 wxDllType Detach() { wxDllType h = m_handle; m_handle = 0; return h; }
216
217 // unload the given library handle (presumably returned by Detach() before)
218 static void Unload(wxDllType handle);
219
220 // unload the library, also done automatically in dtor
221 void Unload() { if ( IsLoaded() ) { Unload(m_handle); m_handle = 0; } }
222
223 // Return the raw handle from dlopen and friends.
224 wxDllType GetLibHandle() const { return m_handle; }
225
226 // check if the given symbol is present in the library, useful to verify if
227 // a loadable module is our plugin, for example, without provoking error
228 // messages from GetSymbol()
229 bool HasSymbol(const wxString& name) const
230 {
231 bool ok;
232 DoGetSymbol(name, &ok);
233 return ok;
234 }
235
236 // resolve a symbol in a loaded DLL, such as a variable or function name.
237 // 'name' is the (possibly mangled) name of the symbol. (use extern "C" to
238 // export unmangled names)
239 //
240 // Since it is perfectly valid for the returned symbol to actually be NULL,
241 // that is not always indication of an error. Pass and test the parameter
242 // 'success' for a true indication of success or failure to load the
243 // symbol.
244 //
245 // Returns a pointer to the symbol on success, or NULL if an error occurred
246 // or the symbol wasn't found.
247 void *GetSymbol(const wxString& name, bool *success = NULL) const;
248
249 // low-level version of GetSymbol()
250 static void *RawGetSymbol(wxDllType handle, const wxString& name);
251 void *RawGetSymbol(const wxString& name) const
252 {
253 #if defined (__WXPM__) || defined(__EMX__)
254 return GetSymbol(name);
255 #else
256 return RawGetSymbol(m_handle, name);
257 #endif
258 }
259
260 #ifdef __WXMSW__
261 // this function is useful for loading functions from the standard Windows
262 // DLLs: such functions have an 'A' (in ANSI build) or 'W' (in Unicode, or
263 // wide character build) suffix if they take string parameters
264 static void *RawGetSymbolAorW(wxDllType handle, const wxString& name)
265 {
266 return RawGetSymbol
267 (
268 handle,
269 name +
270 #if wxUSE_UNICODE
271 L'W'
272 #else
273 'A'
274 #endif
275 );
276 }
277
278 void *GetSymbolAorW(const wxString& name) const
279 {
280 return RawGetSymbolAorW(m_handle, name);
281 }
282 #endif // __WXMSW__
283
284 // return all modules/shared libraries in the address space of this process
285 //
286 // returns an empty array if not implemented or an error occurred
287 static wxDynamicLibraryDetailsArray ListLoaded();
288
289 // return platform-specific name of dynamic library with proper extension
290 // and prefix (e.g. "foo.dll" on Windows or "libfoo.so" on Linux)
291 static wxString CanonicalizeName(const wxString& name,
292 wxDynamicLibraryCategory cat = wxDL_LIBRARY);
293
294 // return name of wxWidgets plugin (adds compiler and version info
295 // to the filename):
296 static wxString
297 CanonicalizePluginName(const wxString& name,
298 wxPluginCategory cat = wxDL_PLUGIN_GUI);
299
300 // return plugin directory on platforms where it makes sense and empty
301 // string on others:
302 static wxString GetPluginsDirectory();
303
304
305 protected:
306 // common part of GetSymbol() and HasSymbol()
307 void *DoGetSymbol(const wxString& name, bool *success = 0) const;
308
309 #ifdef wxHAVE_DYNLIB_ERROR
310 // log the error after a dlxxx() function failure
311 static void Error();
312 #endif // wxHAVE_DYNLIB_ERROR
313
314
315 // platform specific shared lib suffix.
316 static const wxChar *ms_dllext;
317
318 // the handle to DLL or NULL
319 wxDllType m_handle;
320
321 // no copy ctor/assignment operators (or we'd try to unload the library
322 // twice)
323 DECLARE_NO_COPY_CLASS(wxDynamicLibrary)
324 };
325
326 #if defined(__WXMSW__) && wxABI_VERSION >= 20810
327
328 // ----------------------------------------------------------------------------
329 // wxLoadedDLL is a MSW-only internal helper class allowing to dynamically bind
330 // to a DLL already loaded into the project address space
331 // ----------------------------------------------------------------------------
332
333 class wxLoadedDLL : public wxDynamicLibrary
334 {
335 public:
336 wxLoadedDLL(const wxString& dllname)
337 : wxDynamicLibrary(dllname, wxDL_GET_LOADED | wxDL_VERBATIM | wxDL_QUIET)
338 {
339 }
340
341 ~wxLoadedDLL()
342 {
343 Detach();
344 }
345 };
346
347 #endif // __WXMSW__
348
349 // ----------------------------------------------------------------------------
350 // Interesting defines
351 // ----------------------------------------------------------------------------
352
353 #define WXDLL_ENTRY_FUNCTION() \
354 extern "C" WXEXPORT const wxClassInfo *wxGetClassFirst(); \
355 const wxClassInfo *wxGetClassFirst() { \
356 return wxClassInfo::GetFirst(); \
357 }
358
359 #endif // wxUSE_DYNLIB_CLASS
360
361 #endif // _WX_DYNLIB_H__

  ViewVC Help
Powered by ViewVC 1.1.22