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;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM