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-08-20 18:52:21 -04:00
|
|
|
#include "wx/setup.h"
|
1999-02-23 12:51:46 -05:00
|
|
|
|
|
|
|
#if wxUSE_DYNLIB_CLASS
|
|
|
|
|
1999-08-20 18:52:21 -04:00
|
|
|
#include "wx/string.h"
|
|
|
|
#include "wx/list.h"
|
|
|
|
#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
|
|
|
|
|
2000-01-26 17:35:48 -05: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 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__)
|
2000-01-24 15:19:39 -05:00
|
|
|
# include <windows.h> // needed to get HMODULE
|
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
|
|
|
|
|
1999-07-09 20:50:16 -04: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 04:41:07 -04:00
|
|
|
#endif
|
1998-09-10 07:41:14 -04:00
|
|
|
|
1999-06-07 16:49:35 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDllLoader
|
|
|
|
// ----------------------------------------------------------------------------
|
2000-01-24 15:19:39 -05:00
|
|
|
|
1999-06-07 16:49:35 -04: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 12:45:01 -04:00
|
|
|
class WXDLLEXPORT wxDllLoader
|
1999-06-07 16:49:35 -04:00
|
|
|
{
|
2000-01-24 15:19:39 -05: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 15:51:35 -04:00
|
|
|
// return the standard DLL extension (with leading dot) for this platform
|
|
|
|
static wxString GetDllExt();
|
|
|
|
|
2000-01-24 15:19:39 -05:00
|
|
|
private:
|
|
|
|
/// forbid construction of objects
|
|
|
|
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
|
|
|
|
2000-05-17 12:45:01 -04:00
|
|
|
class WXDLLEXPORT wxLibrary : public wxObject
|
1999-02-22 14:42:45 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-05-17 12:45:01 -04:00
|
|
|
class WXDLLEXPORT wxLibraries
|
1999-02-22 14:42:45 -05:00
|
|
|
{
|
|
|
|
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__
|