summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/main.cpp45
-rw-r--r--core/plugin.h14
2 files changed, 38 insertions, 21 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