]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dynlib.h
Added wxWindowBase::CentreOnParent to allow top level windows to be
[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
51// defined in windows.h
0c32066b 52#ifdef LoadLibrary
a585ca5c 53# undef LoadLibrary
0c32066b
JS
54#endif
55
a585ca5c
KB
56// ----------------------------------------------------------------------------
57// wxDllLoader
58// ----------------------------------------------------------------------------
59/** wxDllLoader is a class providing an interface similar to unix's
60 dlopen(). It is used by the wxLibrary framework and manages the
61 actual loading of DLLs and the resolving of symbols in them.
62 There are no instances of this class, it simply serves as a
63 namespace for its static member functions.
64*/
65class wxDllLoader
66{
67 public:
68 /** This function loads a shared library into memory, with libname
69 being the basename of the library, without the filename
70 extension. No initialisation of the library will be done.
71 @param libname Name of the shared object to load.
72 @param success Must point to a bool variable which will be set to TRUE or FALSE.
73 @return A handle to the loaded DLL. Use success parameter to test if it is valid.
74 */
4dc2c3bb 75 static wxDllType LoadLibrary(const wxString & libname, bool *success);
a585ca5c
KB
76 /** This function resolves a symbol in a loaded DLL, such as a
77 variable or function name.
78 @param dllHandle Handle of the DLL, as returned by LoadDll().
79 @param name Name of the symbol.
80 @return A pointer to the symbol.
81 */
82 static void * GetSymbol(wxDllType dllHandle, const wxString &name);
83 private:
84 /// forbid construction of objects
3d2afb7a 85 wxDllLoader();
a585ca5c
KB
86};
87
7b0bfbb2 88// ----------------------------------------------------------------------------
7a4b9130 89// wxLibrary
7b0bfbb2 90// ----------------------------------------------------------------------------
7a4b9130 91
7b0bfbb2
VZ
92class wxLibrary : public wxObject
93{
94public:
95 wxHashTable classTable;
f4a8c29f 96
7b0bfbb2 97public:
8a0d4cf6 98 wxLibrary(wxDllType handle);
7b0bfbb2 99 ~wxLibrary();
7a4b9130 100
7b0bfbb2
VZ
101 // Get a symbol from the dynamic library
102 void *GetSymbol(const wxString& symbname);
7a4b9130 103
7b0bfbb2
VZ
104 // Create the object whose classname is "name"
105 wxObject *CreateObject(const wxString& name);
7a4b9130 106
7b0bfbb2
VZ
107protected:
108 void PrepareClasses(wxClassInfo *first);
f4a8c29f 109
7b0bfbb2 110 wxDllType m_handle;
7a4b9130
GL
111};
112
a585ca5c
KB
113
114
7b0bfbb2 115// ----------------------------------------------------------------------------
7a4b9130 116// wxLibraries
7b0bfbb2
VZ
117// ----------------------------------------------------------------------------
118
119class wxLibraries
120{
121public:
122 wxLibraries();
123 ~wxLibraries();
7a4b9130 124
7b0bfbb2
VZ
125 // caller is responsible for deleting the returned pointer if !NULL
126 wxLibrary *LoadLibrary(const wxString& basename);
7a4b9130 127
7b0bfbb2
VZ
128 wxObject *CreateObject(const wxString& name);
129
130protected:
131 wxList m_loaded;
7a4b9130
GL
132};
133
7b0bfbb2 134// ----------------------------------------------------------------------------
7a4b9130 135// Global variables
7b0bfbb2 136// ----------------------------------------------------------------------------
7a4b9130
GL
137
138extern wxLibraries wxTheLibraries;
139
7b0bfbb2 140// ----------------------------------------------------------------------------
7a4b9130 141// Interesting defines
7b0bfbb2 142// ----------------------------------------------------------------------------
7a4b9130 143
f4a8c29f 144#define WXDLL_ENTRY_FUNCTION() \
856d2e52
GL
145extern "C" wxClassInfo *wxGetClassFirst(); \
146wxClassInfo *wxGetClassFirst() { \
147 return wxClassInfo::GetFirst(); \
f4a8c29f 148}
7a4b9130 149
8a0d4cf6
VZ
150#endif // wxUSE_DYNLIB_CLASS
151
7b0bfbb2 152#endif // _WX_DYNLIB_H__