1999-02-22 19:42:45 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dynlib.cpp
|
|
|
|
// Purpose: Dynamic library management
|
|
|
|
// Author: Guilhem Lavaux
|
|
|
|
// Modified by:
|
|
|
|
// Created: 20/07/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Guilhem Lavaux
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-15 00:23:28 +00:00
|
|
|
#ifndef _WX_DYNLIB_H__
|
|
|
|
#define _WX_DYNLIB_H__
|
1998-08-04 17:49:26 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1999-06-07 20:49:35 +00:00
|
|
|
# pragma interface
|
1998-08-04 17:49:26 +00:00
|
|
|
#endif
|
|
|
|
|
1999-08-20 22:52:21 +00:00
|
|
|
#include "wx/setup.h"
|
1999-02-23 17:51:46 +00:00
|
|
|
|
|
|
|
#if wxUSE_DYNLIB_CLASS
|
|
|
|
|
1999-08-20 22:52:21 +00:00
|
|
|
#include "wx/string.h"
|
|
|
|
#include "wx/list.h"
|
|
|
|
#include "wx/hash.h"
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1999-02-23 17:51:46 +00:00
|
|
|
// this is normally done by configure, but I leave it here for now...
|
|
|
|
#if defined(__UNIX__) && !(defined(HAVE_DLOPEN) || defined(HAVE_SHL_LOAD))
|
1999-06-07 20:49:35 +00:00
|
|
|
# if defined(__LINUX__) || defined(__SOLARIS__) || defined(__SUNOS__) || defined(__FREEBSD__)
|
|
|
|
# define HAVE_DLOPEN
|
|
|
|
# elif defined(__HPUX__)
|
|
|
|
# define HAVE_SHL_LOAD
|
|
|
|
# endif // Unix flavour
|
1999-02-22 20:34:06 +00:00
|
|
|
#endif // !Unix or already have some HAVE_xxx defined
|
|
|
|
|
2000-01-26 22:35:48 +00:00
|
|
|
// Note: WXPM/EMX has to be tested first, since we want to use
|
|
|
|
// native version, even if configure detected presence of DLOPEN.
|
|
|
|
#if defined(__WXPM__) || defined(__EMX__)
|
|
|
|
# define INCL_DOS
|
|
|
|
# include <os2.h>
|
|
|
|
typedef HMODULE wxDllType;
|
|
|
|
#elif defined(HAVE_DLOPEN)
|
1999-06-07 20:49:35 +00:00
|
|
|
# include <dlfcn.h>
|
1999-02-22 19:42:45 +00:00
|
|
|
typedef void *wxDllType;
|
1999-02-23 17:51:46 +00:00
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
1999-06-07 20:49:35 +00:00
|
|
|
# include <dl.h>
|
1999-02-23 17:51:46 +00:00
|
|
|
typedef shl_t wxDllType;
|
1999-02-22 19:42:45 +00:00
|
|
|
#elif defined(__WINDOWS__)
|
2000-01-24 20:19:39 +00:00
|
|
|
# include <windows.h> // needed to get HMODULE
|
1999-02-22 19:42:45 +00:00
|
|
|
typedef HMODULE wxDllType;
|
2001-02-15 21:51:14 +00:00
|
|
|
#elif defined(__APPLE__) && defined(__UNIX__)
|
|
|
|
typedef void *wxDllType;
|
1999-02-22 19:42:45 +00:00
|
|
|
#elif defined(__WXMAC__)
|
|
|
|
typedef CFragConnectionID wxDllType;
|
|
|
|
#else
|
1999-06-07 20:49:35 +00:00
|
|
|
# error "wxLibrary can't be compiled on this platform, sorry."
|
1999-02-22 19:42:45 +00:00
|
|
|
#endif // OS
|
|
|
|
|
1999-07-10 00:50:16 +00:00
|
|
|
// LoadLibrary is defined in windows.h as LoadLibraryA, but wxDllLoader method
|
|
|
|
// should be called LoadLibrary, not LoadLibraryA or LoadLibraryW!
|
|
|
|
#if defined(__WIN32__) && defined(LoadLibrary)
|
|
|
|
# include "wx/msw/winundef.h"
|
1999-06-29 08:41:07 +00:00
|
|
|
#endif
|
1998-09-10 11:41:14 +00:00
|
|
|
|
1999-06-07 20:49:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDllLoader
|
|
|
|
// ----------------------------------------------------------------------------
|
2000-01-24 20:19:39 +00:00
|
|
|
|
1999-06-07 20:49:35 +00:00
|
|
|
/** wxDllLoader is a class providing an interface similar to unix's
|
|
|
|
dlopen(). It is used by the wxLibrary framework and manages the
|
|
|
|
actual loading of DLLs and the resolving of symbols in them.
|
|
|
|
There are no instances of this class, it simply serves as a
|
|
|
|
namespace for its static member functions.
|
|
|
|
*/
|
2000-05-17 16:45:01 +00:00
|
|
|
class WXDLLEXPORT wxDllLoader
|
1999-06-07 20:49:35 +00:00
|
|
|
{
|
2000-01-24 20:19:39 +00:00
|
|
|
public:
|
|
|
|
/** This function loads a shared library into memory, with libname
|
|
|
|
being the basename of the library, without the filename
|
|
|
|
extension. No initialisation of the library will be done.
|
|
|
|
@param libname Name of the shared object to load.
|
|
|
|
@param success Must point to a bool variable which will be set to TRUE or FALSE.
|
|
|
|
@return A handle to the loaded DLL. Use success parameter to test if it is valid.
|
|
|
|
*/
|
|
|
|
static wxDllType LoadLibrary(const wxString & libname, bool *success = NULL);
|
|
|
|
/** This function unloads the shared library. */
|
|
|
|
static void UnloadLibrary(wxDllType dll);
|
|
|
|
/** This function returns a valid handle for the main program
|
|
|
|
itself. */
|
|
|
|
static wxDllType GetProgramHandle(void);
|
|
|
|
/** This function resolves a symbol in a loaded DLL, such as a
|
|
|
|
variable or function name.
|
|
|
|
@param dllHandle Handle of the DLL, as returned by LoadDll().
|
|
|
|
@param name Name of the symbol.
|
|
|
|
@return A pointer to the symbol.
|
|
|
|
*/
|
|
|
|
static void * GetSymbol(wxDllType dllHandle, const wxString &name);
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// return the standard DLL extension (with leading dot) for this platform
|
|
|
|
static wxString GetDllExt();
|
|
|
|
|
2000-01-24 20:19:39 +00:00
|
|
|
private:
|
|
|
|
/// forbid construction of objects
|
|
|
|
wxDllLoader();
|
1999-06-07 20:49:35 +00:00
|
|
|
};
|
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 17:49:26 +00:00
|
|
|
// wxLibrary
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 17:49:26 +00:00
|
|
|
|
2000-05-17 16:45:01 +00:00
|
|
|
class WXDLLEXPORT wxLibrary : public wxObject
|
1999-02-22 19:42:45 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxHashTable classTable;
|
1998-09-01 17:17:05 +00:00
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
public:
|
1999-02-23 17:51:46 +00:00
|
|
|
wxLibrary(wxDllType handle);
|
1999-02-22 19:42:45 +00:00
|
|
|
~wxLibrary();
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
// Get a symbol from the dynamic library
|
|
|
|
void *GetSymbol(const wxString& symbname);
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
// Create the object whose classname is "name"
|
|
|
|
wxObject *CreateObject(const wxString& name);
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
protected:
|
|
|
|
void PrepareClasses(wxClassInfo *first);
|
1998-09-01 17:17:05 +00:00
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
wxDllType m_handle;
|
1998-08-04 17:49:26 +00:00
|
|
|
};
|
|
|
|
|
1999-06-07 20:49:35 +00:00
|
|
|
|
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 17:49:26 +00:00
|
|
|
// wxLibraries
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-05-17 16:45:01 +00:00
|
|
|
class WXDLLEXPORT wxLibraries
|
1999-02-22 19:42:45 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxLibraries();
|
|
|
|
~wxLibraries();
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
// caller is responsible for deleting the returned pointer if !NULL
|
|
|
|
wxLibrary *LoadLibrary(const wxString& basename);
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
wxObject *CreateObject(const wxString& name);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxList m_loaded;
|
1998-08-04 17:49:26 +00:00
|
|
|
};
|
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 17:49:26 +00:00
|
|
|
// Global variables
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 17:49:26 +00:00
|
|
|
|
|
|
|
extern wxLibraries wxTheLibraries;
|
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 17:49:26 +00:00
|
|
|
// Interesting defines
|
1999-02-22 19:42:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1998-09-01 17:17:05 +00:00
|
|
|
#define WXDLL_ENTRY_FUNCTION() \
|
1998-09-17 17:30:13 +00:00
|
|
|
extern "C" wxClassInfo *wxGetClassFirst(); \
|
|
|
|
wxClassInfo *wxGetClassFirst() { \
|
|
|
|
return wxClassInfo::GetFirst(); \
|
1998-09-01 17:17:05 +00:00
|
|
|
}
|
1998-08-04 17:49:26 +00:00
|
|
|
|
1999-02-23 17:51:46 +00:00
|
|
|
#endif // wxUSE_DYNLIB_CLASS
|
|
|
|
|
1999-02-22 19:42:45 +00:00
|
|
|
#endif // _WX_DYNLIB_H__
|