From 4384e3d393f4ece218f401864b4edfaa0545f123 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 1 Aug 2010 19:30:02 +0300 Subject: modified: Makefile modified: main.cpp modified: ../modules/example/main.cpp --- core/main.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) (limited to 'core/main.cpp') diff --git a/core/main.cpp b/core/main.cpp index 9c42aaa..44be9a6 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -1,9 +1,96 @@ #include +#include +//#include + +#include + #include #include +#include "plugin.h" + +using namespace std; + +list plugins; + +int LoadModules(); + +int main(int argc, char *argv[]) +{ + if(LoadModules()) + return 1; //something wrong + 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); + HMODULE hPlugin = 0; + char tmp[MAX_PATH] = {0}; + 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); + 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<shortName; + funcs.load(); + } + FindNextFile(hFile, &findFileData); + } + return 0; +} + +const HMODULE plugin::getHmodule() +{ + return hModule; +} +int plugin::setHandle(const HMODULE &hMod) +{ + if(!hMod) + return 1; + hModule = hMod; + return 0; +} -int main() +int plugin::setName(const char *name) { + if(strlen(name)< 2) + return 1; + szPluginName = new char [strlen(name)+1]; + strcpy(szPluginName, name); return 0; } + +const char* plugin::getName() +{ + return szPluginName; +} +plugin::plugin(const HMODULE &hMod, const char *name) +{ + hModule = hMod; + szPluginName = new char [strlen(name)+1]; + strcpy(szPluginName, name); +} +plugin::~plugin() +{ + FreeLibrary(hModule); + free(szPluginName); +} + -- cgit v1.2.3