]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dynlib.h
Added UpdateAttrRows/Cols to change the row/column info in attributes as
[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/setup.h"
20
21 #if wxUSE_DYNLIB_CLASS
22
23 #include "wx/string.h"
24 #include "wx/list.h"
25 #include "wx/hash.h"
26
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__)
30 # define HAVE_DLOPEN
31 # elif defined(__HPUX__)
32 # define HAVE_SHL_LOAD
33 # endif // Unix flavour
34 #endif // !Unix or already have some HAVE_xxx defined
35
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)
43 # include <dlfcn.h>
44 typedef void *wxDllType;
45 #elif defined(HAVE_SHL_LOAD)
46 # include <dl.h>
47 typedef shl_t wxDllType;
48 #elif defined(__WINDOWS__)
49 # include <windows.h> // needed to get HMODULE
50 typedef HMODULE wxDllType;
51 #elif defined(__WXMAC__)
52 typedef CFragConnectionID wxDllType;
53 #else
54 # error "wxLibrary can't be compiled on this platform, sorry."
55 #endif // OS
56
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"
61 #endif
62
63 // ----------------------------------------------------------------------------
64 // wxDllLoader
65 // ----------------------------------------------------------------------------
66
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 */
73 class wxDllLoader
74 {
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
97 private:
98 /// forbid construction of objects
99 wxDllLoader();
100 };
101
102 // ----------------------------------------------------------------------------
103 // wxLibrary
104 // ----------------------------------------------------------------------------
105
106 class wxLibrary : public wxObject
107 {
108 public:
109 wxHashTable classTable;
110
111 public:
112 wxLibrary(wxDllType handle);
113 ~wxLibrary();
114
115 // Get a symbol from the dynamic library
116 void *GetSymbol(const wxString& symbname);
117
118 // Create the object whose classname is "name"
119 wxObject *CreateObject(const wxString& name);
120
121 protected:
122 void PrepareClasses(wxClassInfo *first);
123
124 wxDllType m_handle;
125 };
126
127
128
129 // ----------------------------------------------------------------------------
130 // wxLibraries
131 // ----------------------------------------------------------------------------
132
133 class wxLibraries
134 {
135 public:
136 wxLibraries();
137 ~wxLibraries();
138
139 // caller is responsible for deleting the returned pointer if !NULL
140 wxLibrary *LoadLibrary(const wxString& basename);
141
142 wxObject *CreateObject(const wxString& name);
143
144 protected:
145 wxList m_loaded;
146 };
147
148 // ----------------------------------------------------------------------------
149 // Global variables
150 // ----------------------------------------------------------------------------
151
152 extern wxLibraries wxTheLibraries;
153
154 // ----------------------------------------------------------------------------
155 // Interesting defines
156 // ----------------------------------------------------------------------------
157
158 #define WXDLL_ENTRY_FUNCTION() \
159 extern "C" wxClassInfo *wxGetClassFirst(); \
160 wxClassInfo *wxGetClassFirst() { \
161 return wxClassInfo::GetFirst(); \
162 }
163
164 #endif // wxUSE_DYNLIB_CLASS
165
166 #endif // _WX_DYNLIB_H__