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