寫了一個獲取游戲數據的DEMO:
主要源代碼如下:
// ConsoleApplication1.cpp : 定義控制台應用程序的入口點。
//
#include "stdafx.h"
#include<iostream>
#include<Windows.h>
using namespace std;
struct GetPluginData
{
int data[22];
};
struct GetInfo
{
char pluginname[51];
char plugininfo[20][31];
};
struct DllInfo
{
char type[11];
char name[11];
};
GetPluginData getData()
{
GetPluginData result;
HINSTANCE hDllInst=LoadLibrary(_T("RacePlugin.dll")); //加載對應的 游戲的 DLL 庫
if(hDllInst)
{
typedef GetPluginData(*MYFUNC)(int); //定義函數類型
MYFUNC youFunctionNameAlias=NULL; //函數別名
youFunctionNameAlias=(MYFUNC)GetProcAddress(hDllInst,"GetDataArray"); //DLL庫中的 GetDataArray函數
if(youFunctionNameAlias)
{
result=youFunctionNameAlias(0); //正式調用 DLL庫中的函數 有返回到 結構體的 數組中
}
FreeLibrary(hDllInst);
}
return result;
}
int _tmain(int argc, _TCHAR* argv[])
{
GetPluginData a=getData();
printf("%d",a.data[0]);
return 0;
}