diff options
-rw-r--r-- | core/main.cpp | 45 | ||||
-rw-r--r-- | core/plugin.h | 14 | ||||
-rw-r--r-- | modules/example/Makefile | 4 | ||||
-rw-r--r-- | modules/example/main.cpp | 2 |
4 files changed, 41 insertions, 24 deletions
diff --git a/core/main.cpp b/core/main.cpp index 44be9a6..96d47a2 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -10,7 +10,7 @@ using namespace std; -list<plugin> plugins; +list<plugin*> plugins; int LoadModules(); @@ -18,40 +18,40 @@ int main(int argc, char *argv[]) { if(LoadModules()) return 1; //something wrong + for(list<plugin*>::iterator p = plugins.begin(); p != plugins.end(); p++) + { + cout<<"Loaded plugin: "<<(*p)->getName()<<'\n'; + (*p)->getFuncs().load(); + } + for(;;) + Sleep(1000); return 0; } -typedef PLUGININFO * (__cdecl * SetPluginInfo) (); -typedef int (__cdecl * Load) (); - -struct exported_funcs_s -{ - SetPluginInfo info; - Load load; -}; - int LoadModules() { - WIN32_FIND_DATA findFileData; - HANDLE hFile = FindFirstFile(".\\modules\\*", &findFileData); + WIN32_FIND_DATAA findFileData; + HANDLE hFile = 0; + if(!(hFile = FindFirstFileA(".\\modules\\*", &findFileData))) + return 1; //failed to find any plugins in directory HMODULE hPlugin = 0; char tmp[MAX_PATH] = {0}; - exported_funcs_s funcs; + plugin::exported_funcs_s funcs; while(hFile != INVALID_HANDLE_VALUE && GetLastError() != ERROR_NO_MORE_FILES) { strcpy(tmp, ".\\modules\\"); - strcat(tmp, (char*)findFileData.cFileName); - hPlugin = LoadLibrary(tmp); + strcat(tmp, findFileData.cFileName); + hPlugin = LoadLibraryA(tmp); funcs.info = (SetPluginInfo)GetProcAddress(hPlugin, "SetPluginInfo"); funcs.load = (Load)GetProcAddress(hPlugin, "Load"); if(funcs.info && funcs.load) { PLUGININFO *pi = funcs.info(); - plugins.push_back(plugin(hPlugin ,pi->shortName)); - //cout<<pi->shortName; - funcs.load(); + plugins.push_back(new plugin(hPlugin, funcs, pi->shortName)); } - FindNextFile(hFile, &findFileData); + else + FreeLibrary(hPlugin); + FindNextFileA(hFile, &findFileData); } return 0; } @@ -82,9 +82,14 @@ const char* plugin::getName() { return szPluginName; } -plugin::plugin(const HMODULE &hMod, const char *name) +const plugin::exported_funcs_s plugin::getFuncs() +{ + return funcs; +} +plugin::plugin(const HMODULE hMod, const exported_funcs_s fnct, const char *name) { hModule = hMod; + funcs = fnct; szPluginName = new char [strlen(name)+1]; strcpy(szPluginName, name); } diff --git a/core/plugin.h b/core/plugin.h index fd25d2a..95a14cc 100644 --- a/core/plugin.h +++ b/core/plugin.h @@ -1,16 +1,28 @@ #ifndef PLUGIN_H #define PLUGIN_H + +typedef PLUGININFO * (__cdecl * SetPluginInfo) (); +typedef int (__cdecl * Load) (); + + class plugin { public: + struct exported_funcs_s + { + SetPluginInfo info; + Load load; + }; const HMODULE getHmodule(); + const exported_funcs_s getFuncs(); int setHandle(const HMODULE &hMod); int setName(const char *name); const char *getName(); - plugin(const HMODULE &hModule, const char *name); + plugin(const HMODULE hModule, const exported_funcs_s fnct, const char *name); ~plugin(); private: HMODULE hModule; char *szPluginName; + exported_funcs_s funcs; }; #endif diff --git a/modules/example/Makefile b/modules/example/Makefile index cdb01c8..451583e 100644 --- a/modules/example/Makefile +++ b/modules/example/Makefile @@ -1,4 +1,4 @@ -CFLAGS=-O2 -msse -fomit-frame-pointer -pipe -mdll -mwindows -I../../api/ -D DEBUG +CFLAGS=-g -mdll -mwindows -I../../api/ -D DEBUG CXXFLAGS=${CFLAGS} LDFLAGS=-Wl,-O1 -shared -static-libgcc CPPFLAGS = @@ -6,7 +6,7 @@ CC=i686-pc-mingw32-gcc CXX=i686-pc-mingw32-g++ STRIP=i686-pc-mingw32-strip LD=i686-pc-mingw32-ld -LNK_COMMON= +LNK_COMMON=-lkernel32 MAINOBJS=main.o all: main diff --git a/modules/example/main.cpp b/modules/example/main.cpp index a4c0ee6..76a004d 100644 --- a/modules/example/main.cpp +++ b/modules/example/main.cpp @@ -28,7 +28,7 @@ extern "C" __declspec(dllexport) PLUGININFO* SetPluginInfo() extern "C" int __declspec(dllexport) Load() { - std::cout<<"core run every code in this function.\n"; + MessageBoxA(0, "Plugin Example Succesful loaded", "INFO", MB_OK); return 0; //all ok, retrun 0 } |