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-02-22 14:42:45 -05: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-02-22 15:34:06 -05:00
|
|
|
#if defined(__LINUX__) || defined(__SOLARIS__) || defined(__SUNOS__) || defined(__FREEBSD__)
|
|
|
|
#define HAVE_DLOPEN
|
|
|
|
#elif defined(__HPUX__)
|
1999-02-23 12:51:46 -05:00
|
|
|
#define HAVE_SHL_LOAD
|
1999-02-22 15:34:06 -05:00
|
|
|
#endif // Unix flavour
|
|
|
|
#endif // !Unix or already have some HAVE_xxx defined
|
|
|
|
|
1999-02-22 14:42:45 -05:00
|
|
|
#if defined(HAVE_DLOPEN)
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
typedef void *wxDllType;
|
1999-02-23 12:51:46 -05:00
|
|
|
#elif defined(HAVE_SHL_LOAD)
|
1999-02-22 14:42:45 -05: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__)
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
typedef HMODULE wxDllType;
|
|
|
|
#elif defined(__WXMAC__)
|
|
|
|
typedef CFragConnectionID wxDllType;
|
|
|
|
#else
|
|
|
|
#error "wxLibrary can't be compiled on this platform, sorry."
|
|
|
|
#endif // OS
|
|
|
|
|
|
|
|
// defined in windows.h
|
1998-09-10 07:41:14 -04:00
|
|
|
#ifdef LoadLibrary
|
1999-02-22 14:42:45 -05:00
|
|
|
#undef LoadLibrary
|
1998-09-10 07:41:14 -04:00
|
|
|
#endif
|
|
|
|
|
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-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__
|