// Created: 03/12/01
// RCS-ID: $Id$
// Copyright: (c) 2001 Ron Lee <ron@debian.org>
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DYNAMICLOADER_H__
#define _WX_DYNAMICLOADER_H__
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface "dynload.h"
#endif
#if wxUSE_DYNAMIC_LOADER
-#include "wx/hash.h"
+#include "wx/hashmap.h"
#include "wx/module.h"
// FIXME: can this go in private.h or something too??
#include "wx/msw/private.h"
#endif
-// Ugh, I'd much rather this was typesafe, but no time
-// to rewrite wxHashTable right now..
+class WXDLLIMPEXP_BASE wxPluginLibrary;
-typedef wxHashTable wxDLManifest;
-typedef wxHashTable wxDLImports;
+WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxPluginLibrary *, wxDLManifest);
+typedef wxDLManifest wxDLImports;
// ----------------------------------------------------------------------------
// conditional compilation
wxDL_VERBATIM = 0x00000008, // Attempt to load the supplied library
// name without appending the usual dll
// filename extension.
+
+ wxDL_NOSHARE = 0x00000010, // load new DLL, don't reuse already loaded
+
+ // FIXME: why? (VZ)
#ifdef __osf__
wxDL_DEFAULT = wxDL_LAZY
#else
};
-class WXDLLEXPORT wxDynamicLibrary
+class WXDLLIMPEXP_BASE wxDynamicLibrary
{
public:
// return the platform standard DLL extension (with leading dot)
- static const wxString &GetDllExt() { return ms_dllext; }
+ static const wxChar *GetDllExt() { return ms_dllext; }
wxDynamicLibrary() : m_handle(0) {}
- wxDynamicLibrary(wxString libname, wxDLFlags flags = wxDL_DEFAULT)
+ wxDynamicLibrary(wxString libname, int flags = wxDL_DEFAULT)
: m_handle(0)
{
Load(libname, flags);
// load the library with the given name
// (full or not), return TRUE on success
- bool Load(wxString libname, wxDLFlags flags = wxDL_DEFAULT);
+ bool Load(wxString libname, int flags = wxDL_DEFAULT);
+
+ // detach the library object from its handle, i.e. prevent the object
+ // from unloading the library in its dtor -- the caller is now
+ // responsible for doing this
+ wxDllType Detach() { wxDllType h = m_handle; m_handle = 0; return h; }
// unload the library, also done automatically in dtor
// Platform specific shared lib suffix.
- static const wxString ms_dllext;
+ static const wxChar *ms_dllext;
// the handle to DLL or NULL
// no copy ctor/assignment operators
// or we'd try to unload the library twice
-DECLARE_NO_COPY_CLASS(wxDynamicLibrary)
+ DECLARE_NO_COPY_CLASS(wxDynamicLibrary)
};
// instantiate this class directly anyway, use wxPluginManager
// instead.
-class WXDLLEXPORT wxPluginLibrary : public wxDynamicLibrary
+class WXDLLIMPEXP_BASE wxPluginLibrary : public wxDynamicLibrary
{
public:
- static wxDLImports ms_classes; // Static hash of all imported classes.
+ static wxDLImports* ms_classes; // Static hash of all imported classes.
- wxPluginLibrary( const wxString &libname, wxDLFlags flags = wxDL_DEFAULT );
+ wxPluginLibrary( const wxString &libname, int flags = wxDL_DEFAULT );
~wxPluginLibrary();
- wxPluginLibrary *RefLib() { ++m_linkcount; return this; }
+ wxPluginLibrary *RefLib();
bool UnrefLib();
// These two are called by the PluginSentinel on (PLUGGABLE) object
void RegisterModules(); // Init any wxModules in the lib.
void UnregisterModules(); // Cleanup any wxModules we installed.
-DECLARE_NO_COPY_CLASS(wxPluginLibrary)
+ DECLARE_NO_COPY_CLASS(wxPluginLibrary)
};
-class WXDLLEXPORT wxPluginManager
+class WXDLLIMPEXP_BASE wxPluginManager
{
public:
// Static accessors.
static wxPluginLibrary *LoadLibrary( const wxString &libname,
- wxDLFlags flags = wxDL_DEFAULT );
+ int flags = wxDL_DEFAULT );
static bool UnloadLibrary(const wxString &libname);
// This is used by wxDllLoader. It's wrapped in the compatibility
// Instance methods.
- wxPluginManager() : m_entry(0) {};
- wxPluginManager(const wxString &libname, wxDLFlags flags = wxDL_DEFAULT)
+ wxPluginManager() : m_entry(NULL) {};
+ wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT)
{
Load(libname, flags);
}
~wxPluginManager() { Unload(); }
- bool Load(const wxString &libname, wxDLFlags flags = wxDL_DEFAULT);
+ bool Load(const wxString &libname, int flags = wxDL_DEFAULT);
void Unload();
bool IsLoaded() const { return m_entry && m_entry->IsLoaded(); }
return m_entry->GetSymbol( symbol, success );
}
+ static void CreateManifest() { ms_manifest = new wxDLManifest(wxKEY_STRING); }
+ static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; }
+
private:
+ // return the pointer to the entry for the library with given name in
+ // ms_manifest or NULL if none
+ static wxPluginLibrary *FindByName(const wxString& name)
+ {
+ const wxDLManifest::iterator i = ms_manifest->find(name);
- static wxDLManifest ms_manifest; // Static hash of loaded libs.
- wxPluginLibrary *m_entry; // Cache our entry in the manifest.
+ return i == ms_manifest->end() ? NULL : i->second;
+ }
+
+ static wxDLManifest* ms_manifest; // Static hash of loaded libs.
+ wxPluginLibrary* m_entry; // Cache our entry in the manifest.
// We could allow this class to be copied if we really
// wanted to, but not without modification.
-
-DECLARE_NO_COPY_CLASS(wxPluginManager)
+ DECLARE_NO_COPY_CLASS(wxPluginManager)
};
// serves as a namespace for its static member functions.
#if WXWIN_COMPATIBILITY_2_2
-class WXDLLEXPORT wxDllLoader
+class WXDLLIMPEXP_BASE wxDllLoader
{
public:
- static wxDllType LoadLibrary(const wxString& name);
+ static wxDllType LoadLibrary(const wxString& name, bool *success = NULL);
static void UnloadLibrary(wxDllType dll);
static wxDllType GetProgramHandle() { return wxDynamicLibrary::GetProgramHandle(); }
static void *GetSymbol(wxDllType dllHandle, const wxString &name, bool *success = 0);
- static const wxString &GetDllExt() { return wxDynamicLibrary::GetDllExt(); }
+ static wxString GetDllExt() { return wxDynamicLibrary::GetDllExt(); }
private:
};
#endif
-
#endif // wxUSE_DYNAMIC_LOADER
#endif // _WX_DYNAMICLOADER_H__
-// vi:sts=4:sw=4:et