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
|
|
|
|
|
|
|
|
#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-22 15:34:06 -05:00
|
|
|
// TODO should be done by configure
|
|
|
|
#if defined(__UNIX__) && !(defined(HAVE_DLOPEN) || defined(HAVE_SHLLOAD))
|
|
|
|
#if defined(__LINUX__) || defined(__SOLARIS__) || defined(__SUNOS__) || defined(__FREEBSD__)
|
|
|
|
#define HAVE_DLOPEN
|
|
|
|
#elif defined(__HPUX__)
|
|
|
|
#define HAVE_SHLLOAD
|
|
|
|
#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;
|
|
|
|
#elif defined(HAVE_SHLLOAD)
|
|
|
|
#include <dl.h>
|
|
|
|
|
|
|
|
typedef void *wxDllType;
|
|
|
|
#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:
|
|
|
|
wxLibrary(void *handle);
|
|
|
|
~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-22 14:42:45 -05:00
|
|
|
#endif // _WX_DYNLIB_H__
|