1999-02-22 14:42:45 -05: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-14 20:23:28 -04:00
|
|
|
#ifndef _WX_DYNLIB_H__
|
|
|
|
#define _WX_DYNLIB_H__
|
1998-08-04 13:49:26 -04:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1999-06-07 16:49:35 -04:00
|
|
|
# pragma interface
|
1998-08-04 13:49:26 -04:00
|
|
|
#endif
|
|
|
|
|
1999-02-23 12:51:46 -05:00
|
|
|
#include <wx/setup.h>
|
|
|
|
|
|
|
|
#if wxUSE_DYNLIB_CLASS
|
|
|
|
|
1998-08-04 13:49:26 -04:00
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/list.h>
|
1998-09-01 13:17:05 -04:00
|
|
|
#include <wx/hash.h>
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-23 12:51:46 -05: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 16:49:35 -04: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 15:34:06 -05:00
|
|
|
#endif // !Unix or already have some HAVE_xxx defined
|
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
#if defined(HAVE_DLOPEN)
|
1999-06-07 16:49:35 -04:00
|
|
|
# include <dlfcn.h>
|
1999-02-22 14:42:45 -05:00
|
|
|
typedef void *wxDllType;
|
1999-02-23 12:51:46 -05:00
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
1999-06-07 16:49:35 -04:00
|
|
|
# include <dl.h>
|
1999-02-23 12:51:46 -05:00
|
|
|
typedef shl_t wxDllType;
|
1999-02-22 14:42:45 -05:00
|
|
|
#elif defined(__WINDOWS__)
|
1999-06-07 16:49:35 -04:00
|
|
|
# include <windows.h>
|
1999-02-22 14:42:45 -05:00
|
|
|
typedef HMODULE wxDllType;
|
|
|
|
#elif defined(__WXMAC__)
|
|
|
|
typedef CFragConnectionID wxDllType;
|
|
|
|
#else
|
1999-06-07 16:49:35 -04:00
|
|
|
# error "wxLibrary can't be compiled on this platform, sorry."
|
1999-02-22 14:42:45 -05:00
|
|
|
#endif // OS
|
|
|
|
|
|
|
|
// defined in windows.h
|
1998-09-10 07:41:14 -04:00
|
|
|
#ifdef LoadLibrary
|
1999-06-07 16:49:35 -04:00
|
|
|
# undef LoadLibrary
|
1998-09-10 07:41:14 -04:00
|
|
|
#endif
|
|
|
|
|
1999-06-07 16:49:35 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDllLoader
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** 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.
|
|
|
|
*/
|
|
|
|
class wxDllLoader
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
1999-06-08 08:17:00 -04:00
|
|
|
static wxDllType LoadLibrary(const wxString & libname, bool *success);
|
1999-06-07 16:49:35 -04:00
|
|
|
/** 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);
|
|
|
|
private:
|
|
|
|
/// forbid construction of objects
|
1999-06-07 18:12:57 -04:00
|
|
|
wxDllLoader();
|
1999-06-07 16:49:35 -04:00
|
|
|
};
|
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:49:26 -04:00
|
|
|
// wxLibrary
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
class wxLibrary : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxHashTable classTable;
|
1998-09-01 13:17:05 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
public:
|
1999-02-23 12:51:46 -05:00
|
|
|
wxLibrary(wxDllType handle);
|
1999-02-22 14:42:45 -05:00
|
|
|
~wxLibrary();
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
// Get a symbol from the dynamic library
|
|
|
|
void *GetSymbol(const wxString& symbname);
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
// Create the object whose classname is "name"
|
|
|
|
wxObject *CreateObject(const wxString& name);
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
protected:
|
|
|
|
void PrepareClasses(wxClassInfo *first);
|
1998-09-01 13:17:05 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
wxDllType m_handle;
|
1998-08-04 13:49:26 -04:00
|
|
|
};
|
|
|
|
|
1999-06-07 16:49:35 -04:00
|
|
|
|
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:49:26 -04:00
|
|
|
// wxLibraries
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxLibraries
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxLibraries();
|
|
|
|
~wxLibraries();
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
// caller is responsible for deleting the returned pointer if !NULL
|
|
|
|
wxLibrary *LoadLibrary(const wxString& basename);
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
wxObject *CreateObject(const wxString& name);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxList m_loaded;
|
1998-08-04 13:49:26 -04:00
|
|
|
};
|
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:49:26 -04:00
|
|
|
// Global variables
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:49:26 -04:00
|
|
|
|
|
|
|
extern wxLibraries wxTheLibraries;
|
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:49:26 -04:00
|
|
|
// Interesting defines
|
1999-02-22 14:42:45 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1998-09-01 13:17:05 -04:00
|
|
|
#define WXDLL_ENTRY_FUNCTION() \
|
1998-09-17 13:30:13 -04:00
|
|
|
extern "C" wxClassInfo *wxGetClassFirst(); \
|
|
|
|
wxClassInfo *wxGetClassFirst() { \
|
|
|
|
return wxClassInfo::GetFirst(); \
|
1998-09-01 13:17:05 -04:00
|
|
|
}
|
1998-08-04 13:49:26 -04:00
|
|
|
|
1999-02-23 12:51:46 -05:00
|
|
|
#endif // wxUSE_DYNLIB_CLASS
|
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
#endif // _WX_DYNLIB_H__
|