C++ 共享内存 获取游戏数据

写了一个获取游戏数据的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;
}

 

posted @ 2017-11-13 15:26  Barrey's  阅读(1666)  评论(0)    收藏  举报