summaryrefslogtreecommitdiff
path: root/core/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/main.cpp')
-rw-r--r--core/main.cpp89
1 files changed, 88 insertions, 1 deletions
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 <windows.h>
+#include <iostream>
+//#include <tchar.h>
+
+#include <list>
+
#include <api.h>
#include <pluginapi.h>
+#include "plugin.h"
+
+using namespace std;
+
+list<plugin> 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<<pi->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);
+}
+