From 46a2415de1bd97c73527922a748af5455a1c6a0e Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 1 Aug 2010 22:14:12 +0300 Subject: first working --- core/main.cpp | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'core/main.cpp') 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 plugins; +list plugins; int LoadModules(); @@ -18,40 +18,40 @@ int main(int argc, char *argv[]) { if(LoadModules()) return 1; //something wrong + for(list::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<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); } -- cgit v1.2.3