here are my headers
Code: Select all
/******************
* file : IPlugin.h
******************/
#ifndef IPLUGIN_H_INCLUDED
#define IPLUGIN_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
class IPluginHost
{
public:
virtual wxEvtHandler* GetEvtHandler() = 0;
virtual wxMenuBar* GetMainMenuBar() = 0;
virtual wxToolBar* GetMainToolBar() = 0;
};
class IPlugin : public wxApp
{
public:
virtual void InitPlugin(IPluginHost *pHost) = 0;
virtual void ShutdownPlugin() = 0;
};
typedef void (*DLLFunctionPtr)(IPluginHost*, IPlugin**);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // IPLUGIN_H_INCLUDED
/********************
* file : PluginDll.h
********************/
#ifndef PLUGINDLL_H_INCLUDED
#define PLUGINDLL_H_INCLUDED
#ifdef MYDLL_EXPORTS
#define DLL_IMPORT_EXPORT __declspec(dllexport)
#else
#define DLL_IMPORT_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void DLL_IMPORT_EXPORT CreatePlugin(IPluginHost *pHost, IPlugin **ppInterface);
void DLL_IMPORT_EXPORT DestroyPlugin(IPluginHost *pHost, IPlugin **ppInterface = NULL);
class wxPlugin : public IPlugin
{
DECLARE_DYNAMIC_CLASS(wxPlugin)
public:
wxPlugin();
virtual ~wxPlugin();
virtual void InitPlugin(IPluginHost *pFrame);
virtual void ShutdownPlugin();
private:
enum
{
IDM_ABOUT = 100
};
void OnAbout(wxCommandEvent &event);
IPluginHost *m_pHost;
};
DECLARE_APP(wxPlugin);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // PLUGINDLL_H_INCLUDED
/********************
* file : PluginApp.h
********************/
#ifndef PLUGINAPP_H_INCLUDED
#define PLUGINAPP_H_INCLUDED
typedef std::map<wxDllType, IPlugin*> PLUGIN_MAP;
typedef PLUGIN_MAP::iterator PLUGIN_MAP_ITER;
class CMainFrame : public wxFrame, IPluginHost
{
public:
CMainFrame() { }
CMainFrame(const wxString& title);
~CMainFrame();
wxEvtHandler* GetEvtHandler() { return GetEventHandler(); }
wxMenuBar* GetMainMenuBar() { return GetMenuBar(); }
wxToolBar* GetMainToolBar() { return GetToolBar(); }
private:
enum
{
ID_MAIN = 10,
IDM_FILE_QUIT,
IDP_PANEL
};
void EnumPlugIns();
void LoadPlugin(const wxString &Filename);
void UnloadAllPlugins();
void OnQuit(wxCommandEvent &event);
PLUGIN_MAP m_PluginList;
};
class CPluginApp : public wxApp
{
public:
virtual bool OnInit();
virtual int OnExit();
private:
CMainFrame *m_pFrame;
};
#endif // PLUGINAPP_H_INCLUDED
Code: Select all
void CMainFrame::EnumPlugIns()
{
wxDir dir;
wxArrayString Files;
size_t num = dir.GetAllFiles(wxGetCwd() + wxT("\\DLL"), &Files, wxT("*.dll"), wxDIR_FILES);
for(size_t i = 0; i < num; i++)
{
wxString Filename = Files[i];
LoadPlugin(Filename);
}
}
void CMainFrame::LoadPlugin(const wxString &Filename)
{
wxString PluginName = wxT("CreatePlugin");
wxDynamicLibrary Loader;
if (!Loader.Load(Filename, wxDL_NOW) )
{
wxMessageBox(wxString::Format(wxT("Could not load Plugin\n'%s'"), Filename), wxT("Error"), wxOK, this);
return;
}
if(Loader.IsLoaded())
{
if(Loader.HasSymbol(PluginName) )
{
DLLFunctionPtr pFuncCreatePlugin = (DLLFunctionPtr)Loader.GetSymbol(PluginName);
if(pFuncCreatePlugin)
{
IPlugin *pPlugin = NULL;
pFuncCreatePlugin(this, &pPlugin);
wxDllType Handle = Loader.Detach();
m_PluginList.insert(std::make_pair(Handle, pPlugin) );
}
else
{
wxMessageBox(wxT("GetSymbol returned NULL"), wxT("Error"), wxOK, this);
}
}
else
{
wxMessageBox(wxString::Format(wxT("Symbol '%s' not found!"), PluginName), wxT("Error"), wxOK, this);
}
}
}
Code: Select all
void CMainFrame::OnQuit(wxCommandEvent& event)
{
UnloadAllPlugins();
Destroy();
}
void CMainFrame::UnloadAllPlugins()
{
PLUGIN_MAP_ITER iter;
for (iter = m_PluginList.begin(); iter != m_PluginList.end(); ++iter)
{
wxDllType t = iter->first;
IPlugin *pPlugin = iter->second;
if (pPlugin)
{
pPlugin->ShutdownPlugin();
}
wxDynamicLibrary::Unload(iter->first);
}
}
Code: Select all
wxMenuBarBase::~wxMenuBarBase()
{
WX_CLEAR_LIST(wxMenuList, m_menus);
}
Can anyone shed some light on this for me?