here is my problem
#include <iostream>
#include <Windows.h>
int main()
{
int coins = 1;
std::cout << &coins <<std::endl;
Sleep(10000);
return 0;
}
the coins value is the one i want to change with the second program
here is the code of the second program
#include <iostream>
int main()
{
int* coins = reinterpret_cast<int*> (0x57da7ffe7c);
std::cout<<*coins<<"\n";
return 0;
}
i expected that it will print the value of coins witch is (1) but it gives me this error (exited with code=3221225477)
the editor i use is vs code
>Solution :
Summary of information from the comments:
-
Each process has its own address space. Even if the address
0x57da7ffe7cis a fixed one in one process, you cannot access it from another like this.
The error code you get 3221225477 (which is 0xC0000005 in hex) is "Access Violation", meaning that you attempted to read an invalid address. -
You seems to be using Windows. There is a Windows API for reading another process memory (under certain limitations):
ReadProcessMemory. You can have a look at the documentation link, but it’s quite advanced to use. -
The address space of a process is valid only as long as it is alive. Therefore if you use
ReadProcessMemory, the first program would need to be still running at that stage (before your edit to the question you didn’t have aSleepin the first program, and so it would have exited almost immediatly).