I am having a strange problem. For a fun little test, I decided to see if I could get some minesweeper info out of memory. For some reason though, ReadProcessMemory() fails every time. I am not sure why because with this same code I was previously reading some memory from other processes. I have tried opening the process with PROCESS_ALL_ACCESS but to no avail. Can anyone point me in the right direction?
Also, point out any bad code practices.
Code:#include <stdio.h> #include <windows.h> typedef unsigned long DWORD; int main(void) { HWND hWnd = FindWindow(NULL, "Minesweeper"); HWND pHandle; DWORD PID; unsigned long lpWidth = 0x1005334; unsigned long bytesread; unsigned int width; if (hWnd == NULL) { printf("Window not found\n"); return 1; } printf("Window Handle = %x\n", hWnd); GetWindowThreadProcessId(hWnd, &PID); printf("Process ID = %x\n", PID); pHandle = OpenProcess(PROCESS_ALL_ACCESS, 1, PID); printf("Process Handle = %x\n", pHandle); if (pHandle == NULL) { printf("The Process handle could not be retrieved\n"); return 1; } if (ReadProcessMemory(pHandle, &lpWidth, &width, sizeof(width), &bytesread)) { printf("Width = %d\n", width); } else { printf("ReadProcessMemory Failed\n"); } return 0; }



LinkBack URL
About LinkBacks



