Create own functions for Read/WriteProcesses

Hey everyone. I'm wanting to write my own functions for ReadProcessMemory and WriteProcessMemory, but I keep running into problems. Here's my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void Read(DWORD Add, DWORD Value);
void Write(DWORD Add, DWORD Value);

void Read(DWORD Add, DWORD Value)
{
	//Declare variables and set values
	GetWindowThreadProcessId(window, &pID);

	//Read process info
	ReadProcessMemory(handle, (LPCVOID)(base+Add), &Value, 4, NULL);
	

}
void Write(DWORD Add, DWORD Value)
{
	HWND window = FindWindow(0, _T("Process Window Name"));
	DWORD pID = NULL;
	DWORD base = dwGetModuleBaseAddress(pID, _T("App.exe"));
	HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
	GetWindowThreadProcessId(window, &pID);

	//Write to the memory address
	WriteProcessMemory(handle, (BYTE*)(base+Add), &Value, sizeof(Value), NULL);
	CloseHandle(handle);
}


I can read and write to the window process when I put it in the form call. For Example

1
2
private: System::Void button1_Click_1(System::Object^  sender, System::EventArgs^  e) 
{	


But when I try to create a function for read() and write() it doesn't work. For example when i try to get the money value from a game and add to it it doesn't work

1
2
3
4
5
6
7
8
9
int BigMoney = 100000;
DWORD GetMoneyValue;
DWORD MoneyAddress = 0x123456;

Read(MoneyAddress, GetMoneyValue);
GetMoneyValue = GetMoneyValue + BigMoney;
				 
Write(MoneyAddress, GetMoneyValue);


When I put all the coding into the call itself it works fine. I'm just trying to create these functions so I don't have to keep writing all that coding over and over for every call.

Any Ideas? Thanks
Topic archived. No new replies allowed.