I am trying to create a game trainer for a game. I have found the needed memory addresses and now I want to write my values into that address.
For example: address of ammo is: 0x0E9AFD07
The WriteProcessMemory()
function in the Windows API can do this.
My source:
int main(){
DWORD pid;
int address = 0x0E9AFD07;
const int data = 20;
HWND hwnd = FindWindow(0 , "Max Payne v1.05");
GetWindowThreadProcessId(hwnd , &pid);
HANDLE hndl = OpenProcess(PROCESS_ALL_ACCESS , false ,pid);
WriteProcessMemory(hndl , &address , &data , 4 , NULL);
return 0;
}
But this code does not work!
If I should use WriteProcessMemory
like below:
WriteProcessMemory(hndl , (void*)0x0E9AFD07 , &data , 4 , NULL);
then the second parameter of the function is LPVOID
type and I read that LPVOID
is a pointer to anything.
So, why I can't pass a pointer to int
(address variable) for the second parameter?
And why should I use (void*)
?