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