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