简体   繁体   English

为什么 ReadProcessMemory 给我错误代码 299?

[英]Why Does ReadProcessMemory Give Me Error Code 299?

I am trying to read a float from a game's memory.我正在尝试从游戏内存中读取浮点数。 The game is called Muck, it is 64 bit.游戏叫 Muck,它是 64 位的。 My program's platform is also 64 bit.我的程序平台也是 64 位的。 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).当我调用 ReadProcessMemory() 时,它给了我一个我知道不是正确值的值,它返回 0(这意味着有一个错误)。 Calling GetLastError() gives me error code 299 .调用 GetLastError() 会给我错误代码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();
    }
}

Here is how I solved it:这是我解决它的方法:

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

I was passing a pointer.我正在传递一个指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM