diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-15 07:30:39 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-15 07:30:39 +0300 |
commit | 076c9cfcf33e06218805ad0412a806005c3c63f7 (patch) | |
tree | a2038b043736beee85e012bce34f960d70ad6d74 | |
parent | bd197c2ad7e360fb8008c50f8d423072926428dd (diff) |
lord_evil, i was made plugin example for you, coz i know, you are to lazy to read docs ;)
-rw-r--r-- | core/main.cpp | 5 | ||||
-rw-r--r-- | core/modules.cpp | 18 | ||||
-rw-r--r-- | plugins/example/main.cpp | 21 |
3 files changed, 40 insertions, 4 deletions
diff --git a/core/main.cpp b/core/main.cpp index 5d324e0..20b8501 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -1,6 +1,9 @@ #include "commonheaders.h" + +PLUGINLINK pluglink; + class EvilCore: public wxApp { public: @@ -10,7 +13,9 @@ public: bool EvilCore::OnInit() { void load_modules(); + void run_plugins(); load_modules(); + run_plugins(); while(true) sleep(10); return 0; diff --git a/core/modules.cpp b/core/modules.cpp index d094311..b509c6f 100644 --- a/core/modules.cpp +++ b/core/modules.cpp @@ -2,6 +2,8 @@ std::list<plugin*> plugins; +extern PLUGINLINK pluglink; + void load_modules() { wxStandardPaths *pth = new wxStandardPaths; @@ -50,7 +52,10 @@ void load_modules() lib_path += filename; wxDynamicLibrary *plug = new wxDynamicLibrary(lib_path); if(!plug->IsLoaded()) + { wxMessageBox(_T("Failed to load plugin") ,_T("Error"), wxOK | wxICON_ERROR); + wxLogDebug(_T("Failed to load plugin\n")); + } bool is_plugin = true; plugin::exported_functions_s *funcs = new plugin::exported_functions_s; if((funcs->Load = (load)plug->GetSymbol(_T("load"))) == NULL) @@ -74,6 +79,15 @@ void load_modules() while(dir.GetNext(&filename)); } +void run_plugins() +{ + if(!plugins.empty()) + for(std::list<plugin*>::iterator i = plugins.begin(); i != plugins.end(); i++) + { + (*i)->get_exported_functions()->Load(&pluglink); + (*i)->get_exported_functions()->OnModulesLoaded(); + } +} plugin::plugin(wxDynamicLibrary *lib, PLUGININFO *info, exported_functions_s *funcs) { @@ -84,3 +98,7 @@ plugin::plugin(wxDynamicLibrary *lib, PLUGININFO *info, exported_functions_s *fu if(funcs) exported_funcs = funcs; } +const plugin::exported_functions_s* plugin::get_exported_functions() +{ + return exported_funcs; +} diff --git a/plugins/example/main.cpp b/plugins/example/main.cpp index edeb9e3..8c51548 100644 --- a/plugins/example/main.cpp +++ b/plugins/example/main.cpp @@ -1,5 +1,6 @@ #include <wx/wx.h> +#include <wx/stdpaths.h> #include <pluginapi.h> //this is necessary, PLUGININFO structure, other related to load/unload plugin code @@ -15,16 +16,18 @@ PLUGINLINK *pluginLink; bool wxPluginForEvilCore::OnInit() { + wxMessageBox(_T("I am a plugin example") ,_T("Info"), wxOK | wxICON_INFORMATION); return true; } - -/*HINSTANCE hInst; +#ifdef _WIN32 +HINSTANCE hInst; BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) //default dll entry point { hInst = hinstDLL; return TRUE; -}*/ //windows specific, does not needed ? +} //windows specific, does not needed ? +#endif PLUGININFO pluginInfo = { @@ -51,7 +54,17 @@ extern "C" int load(PLUGINLINK *link) //basic initialisation, registering new f extern "C" int on_modules_loaded() //load main code from here, all services from other plugins must be avaible here { wxApp::SetInstance(new wxPluginForEvilCore()); //create instance, i think here is right place, not in load where we do only basic initialisation -// wxEntry(GetModuleHandle(NULL),NULL,NULL,SW_SHOW); //here we need to get module handle somehow, commented string is for windows only +#ifdef _WIN32 + wxEntry(GetModuleHandle(NULL),NULL,NULL,SW_SHOW); +#else + int i = 0; + char **params = (char**)malloc(2); + params[0] = (char*)malloc(2); + strcpy(params[0], ""); + wxEntry(i, params); + free(params[0]); + free(params); +#endif return 0; } |