diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-03 13:22:34 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-03 13:22:34 +0300 |
commit | 9a44caeb992e365d747fa9f6900310f72785836a (patch) | |
tree | 60fbf9aaa3cf18e033906880cbb6d2493a1939e9 | |
parent | 6f01f33a040b6a4f078332dc9056e7efea29a5ee (diff) |
starting plugins in threads
-rw-r--r-- | core/main.cpp | 17 | ||||
-rw-r--r-- | modules/example/main.cpp | 4 |
2 files changed, 18 insertions, 3 deletions
diff --git a/core/main.cpp b/core/main.cpp index ae1dbf0..aa6a7fc 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -16,6 +16,7 @@ list<service*> services; int LoadModules(); INT_PTR CallService(const char *name, WPARAM w, LPARAM l); HANDLE CreateServiceFunction(const char *name, SERVICE pService); +DWORD WINAPI OnModulesLoadedThread( LPVOID lpParam ); int ServiceExists(const char *name); SERVICE GetPluginInfoList(WPARAM, LPARAM); SERVICE Test(WPARAM, LPARAM); @@ -35,7 +36,10 @@ int main(int argc, char *argv[]) for(list<plugin*>::iterator p = plugins.begin(); p != plugins.end(); p++) { if((*p)->getFuncs().loaded) - (*p)->getFuncs().loaded(); + { + CreateThread(NULL, 0, OnModulesLoadedThread, (LPVOID)(*p)->getFuncs().loaded, 0, 0); +// (*p)->getFuncs().loaded(); + } } CallService("GetPluginInfoList", 0, 0); for(;;) @@ -146,7 +150,8 @@ INT_PTR CallService(const char *name, WPARAM w, LPARAM l) } HANDLE CreateServiceFunction(const char *name, SERVICE pService) { - services.push_back(new service(name, pService)); + if(!ServiceExists(name)) + services.push_back(new service(name, pService)); } int ServiceExists(const char *name) { @@ -168,3 +173,11 @@ SERVICE Test(WPARAM, LPARAM) MessageBoxA(0, "Test service working", "INFO", MB_OK); return 0; } + +DWORD WINAPI OnModulesLoadedThread( LPVOID lpParam ) +{ + OnModulesLoaded &l = (OnModulesLoaded&)lpParam; + l(); + return 0; +} + diff --git a/modules/example/main.cpp b/modules/example/main.cpp index 1df2774..2e15520 100644 --- a/modules/example/main.cpp +++ b/modules/example/main.cpp @@ -1,4 +1,5 @@ #include <windows.h> +#include <list> #include <pluginapi.h> //this is necessary, PLUGININFO structure, other related to load/unload plugin code #include <plugin_helper.h> //just helper, not necessary @@ -28,7 +29,7 @@ extern "C" __declspec(dllexport) PLUGININFO* SetPluginInfo() return &pluginInfo; } -extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) //basic initialisation, registering new functions, do other basic initialisation +extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) //basic initialisation, registering new functions, do other basic initialisation, you can create infinite loop, or other code which use many time here, only fast basic initialisation { pluginLink = link; //necessary MessageBoxA(0, "Simple plugin initialisation done", "INFO", MB_OK); @@ -39,5 +40,6 @@ extern "C" int __declspec(dllexport) OnModulesLoaded() //load main code from her { MessageBoxA(0, "Advanced plugin features needed services from other plugins are working from now", "INFO", MB_OK); CallService("Test", 0, 0); //usage example of service registered in core + std::list<PLUGININFO> *pluglist = (std::list<PLUGININFO>*)CallService("GetPluginInfoList", 0, 0); //get list with info for all plugins return 0; } |