dlopen fixes
[wxWidgets.git] / include / wx / dynlib.h
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
12 #ifndef _WX_DYNLIB_H__
13 #define _WX_DYNLIB_H__
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <wx/string.h>
20 #include <wx/list.h>
21 #include <wx/hash.h>
22
23 // TODO should be done by configure
24 #if defined(__UNIX__) && !(defined(HAVE_DLOPEN) || defined(HAVE_SHLLOAD))
25 #if defined(__LINUX__) || defined(__SOLARIS__) || defined(__SUNOS__) || defined(__FREEBSD__)
26 #define HAVE_DLOPEN
27 #elif defined(__HPUX__)
28 #define HAVE_SHLLOAD
29 #endif // Unix flavour
30 #endif // !Unix or already have some HAVE_xxx defined
31
32 #if defined(HAVE_DLOPEN)
33 #include <dlfcn.h>
34
35 typedef void *wxDllType;
36 #elif defined(HAVE_SHLLOAD)
37 #include <dl.h>
38
39 typedef void *wxDllType;
40 #elif defined(__WINDOWS__)
41 #include <windows.h>
42
43 typedef HMODULE wxDllType;
44 #elif defined(__WXMAC__)
45 typedef CFragConnectionID wxDllType;
46 #else
47 #error "wxLibrary can't be compiled on this platform, sorry."
48 #endif // OS
49
50 // defined in windows.h
51 #ifdef LoadLibrary
52 #undef LoadLibrary
53 #endif
54
55 // ----------------------------------------------------------------------------
56 // wxLibrary
57 // ----------------------------------------------------------------------------
58
59 class wxLibrary : public wxObject
60 {
61 public:
62 wxHashTable classTable;
63
64 public:
65 wxLibrary(void *handle);
66 ~wxLibrary();
67
68 // Get a symbol from the dynamic library
69 void *GetSymbol(const wxString& symbname);
70
71 // Create the object whose classname is "name"
72 wxObject *CreateObject(const wxString& name);
73
74 protected:
75 void PrepareClasses(wxClassInfo *first);
76
77 wxDllType m_handle;
78 };
79
80 // ----------------------------------------------------------------------------
81 // wxLibraries
82 // ----------------------------------------------------------------------------
83
84 class wxLibraries
85 {
86 public:
87 wxLibraries();
88 ~wxLibraries();
89
90 // caller is responsible for deleting the returned pointer if !NULL
91 wxLibrary *LoadLibrary(const wxString& basename);
92
93 wxObject *CreateObject(const wxString& name);
94
95 protected:
96 wxList m_loaded;
97 };
98
99 // ----------------------------------------------------------------------------
100 // Global variables
101 // ----------------------------------------------------------------------------
102
103 extern wxLibraries wxTheLibraries;
104
105 // ----------------------------------------------------------------------------
106 // Interesting defines
107 // ----------------------------------------------------------------------------
108
109 #define WXDLL_ENTRY_FUNCTION() \
110 extern "C" wxClassInfo *wxGetClassFirst(); \
111 wxClassInfo *wxGetClassFirst() { \
112 return wxClassInfo::GetFirst(); \
113 }
114
115 #endif // _WX_DYNLIB_H__