#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 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); }