Set DWORD value from user input

My question is, how do i set the DWORD value from user input?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
DWORD Ammo = 0x0000000;
int MyAmmo;
int SetAmmo = 1;

int main(){

cin >> Ammo; //I need to figure out how to set the DWORD value, without my program crashing..

int pid = 321334;

HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

ReadProcessMemory(pHandle, (LPVOID)Ammo, &MyAmmo, sizeof(MyAmmo), 0);

WriteProcessMemory(pHandle, (LPVOID)Ammo, &SetAmmo, sizeof(SetAmmo), 0);
}
The way you're setting Ammo is correct. Are you sure that the address you're entering is correct and that you're entering in the correct format (decimal)? You can't just enter a value like 0x001F0001. Your program doesn't know how to parse that. You need to enter 2031617.
Ive fixed it with this piece of code here:

1
2
cin >> Addy;
DWORD Ammo = strtol(Addy.c_str(), 0, 0);
That's not the correct fix. All you need to do is tell cin you want to read hex input:
 
    std::cin >> std::hex >> Ammo;

Topic archived. No new replies allowed.