Why Does ReadProcessMemory Give Me Error Code 299?

Issue

I am trying to read a float from a game’s memory. The game is called Muck, it is 64 bit. My program’s platform is also 64 bit. When I call ReadProcessMemory(), it gives me a value that I know is not the correct value, and it returns 0 (which means there was an error). Calling GetLastError() gives me error code 299.

Code:

#include <iostream>
#include <Windows.h>
#include <string>
#include <list>
#include <TlHelp32.h>

int main()
{
    HWND hwnd = FindWindowA(NULL, "Muck");
    DWORD procID;
    HANDLE handle = NULL;
    int base = NULL;
    if (hwnd == NULL) {
        return 1;
    }
    GetWindowThreadProcessId(hwnd, &procID);
    handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);



    float val;
    _int64 loc = 0x1C06B7251CC;
    bool r = ReadProcessMemory(handle, &loc, &val, sizeof(float), NULL);
    if (r == 0)
    {
        std::cout << GetLastError();
    }
}

Solution

Here is how I solved it:

LPVOID loc = (LPVOID)0x1DB7C83158C;
bool r = ReadProcessMemory(handle, loc, &val, 4, NULL);

I was passing a pointer.

Answered By – deadpython

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published