summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-08-01 19:30:02 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-08-01 19:30:02 +0300
commit4384e3d393f4ece218f401864b4edfaa0545f123 (patch)
treeed957a60603747ee18d68783b9a6c0ee33aee333
parentd83d23b9a9df04386966452f7b84d84b01dbb3fb (diff)
modified: Makefile
modified: main.cpp modified: ../modules/example/main.cpp
-rw-r--r--core/Makefile6
-rw-r--r--core/main.cpp89
-rw-r--r--modules/example/main.cpp31
3 files changed, 117 insertions, 9 deletions
diff --git a/core/Makefile b/core/Makefile
index e5568e1..c488384 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -1,12 +1,12 @@
-CFLAGS=-O2 -msse -fomit-frame-pointer -pipe -mwindows -mwin32 -D DEBUG -I../api/
+CFLAGS=-g -mwindows -mwin32 -D DEBUG -I../api/
CXXFLAGS=${CFLAGS}
-LDFLAGS=-Wl,-O1 -static-libgcc
+LDFLAGS=-static-libgcc
CPPFLAGS =
CC=i686-pc-mingw32-gcc
CXX=i686-pc-mingw32-g++
STRIP=i686-pc-mingw32-strip
LD=i686-pc-mingw32-ld
-LNK_COMMON=
+LNK_COMMON=-lkernel32
MAINOBJS=main.o
all: main
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);
+}
+
diff --git a/modules/example/main.cpp b/modules/example/main.cpp
index e778c9c..a4c0ee6 100644
--- a/modules/example/main.cpp
+++ b/modules/example/main.cpp
@@ -1,13 +1,34 @@
#include <windows.h>
#include <api.h>
#include <pluginapi.h>
+#include <iostream>
-HINSTANCE hDllInstance=NULL;
-BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) //default dll entry point
+HINSTANCE hInst;
+BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) //default dll entry point
{
- if (ul_reason_for_call == DLL_PROCESS_ATTACH)
- hDllInstance = (HINSTANCE)hModule;
+ hInst = hinstDLL;
return TRUE;
}
-
+PLUGININFO pluginInfo =
+{
+ sizeof(PLUGININFO), //size of structure
+ (char*)"example plugin", //short name
+ 0, //description
+ 0, //author
+ 0, //author email
+ PLUGIN_MAKE_VERSION(0,0,0,1), //version
+ 0 //flags (unused)
+};
+
+extern "C" __declspec(dllexport) PLUGININFO* SetPluginInfo()
+{
+ return &pluginInfo;
+}
+
+extern "C" int __declspec(dllexport) Load()
+{
+ std::cout<<"core run every code in this function.\n";
+ return 0; //all ok, retrun 0
+}
+