我正嘗試在VisualC++中爲ReadProcessMemory和WriteProcessMemory創建自己的函數,所以我不必每次都創建新的函數調用時輸入所有信息。這個項目是Windows窗體。這裏的問題通過函數傳遞值
void Read(DWORD Add, int Value);
private: System::Void btnP1Money_Click_1(System::Object^ sender, System::EventArgs^e)
{
int BigMoney = 100000;
int GetMoneyValue;
DWORD MonAddr = 0x180A6C8;
Read(MonAddr, GetMoneyValue);
}
void Read(DWORD Add, int Value)
{
HWND window = FindWindow(0, _T("Process Window Name"));
DWORD pID = NULL;
DWORD base = dwGetModuleBaseAddress(pID, _T("Game.exe"));
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
GetWindowThreadProcessId(window, &pID);
ReadProcessMemory(handle, (LPCVOID)(base+Add), &Value, 4, NULL);
}
在遊戲中的值是500,但是從閱讀()的返回值是0。不知道我做錯了。我不想每次在每個按鈕單擊和複選框勾選時在Read()函數中定義所有內容。
感謝
謝謝你的回覆弗拉德。這正是我對標題所做的。我將函數聲明更改爲void Read(DWORD Add,int&Value);和函數定義中的標題無效Read(DWORD Add,int&Value){//相同的代碼},它會產生那些奇怪的結果。任何想法爲什麼?謝謝 – Syperus 2013-03-04 18:03:01
@Syperus可以發佈ReadProcessMemory函數代碼嗎? – VladL 2013-03-04 19:15:11
從WINBASE.H'BOOL WINAPI ReadProcessMemory( __in HANDLE hProcess, __in LPCVOID lpBaseAddress, __out_bcount_part(n大小,* lpNumberOfBytesRead)LPVOID lpBuffer, __in SIZE_T n大小, __out_opt SIZE_T * lpNumberOfBytesRead );' – Syperus 2013-03-05 02:03:34