无法将“ LPVOID&”(非const限定)初始化为“ int”

时间:2019-05-17 21:10:59

标签: c++

  

我收到此错误:   不能使用“ int”类型的值初始化“ LPVOID&”类型的引用(非const限定)

我正在尝试读取过程内存,但我无法弄清缺少的内容...

主代码调用ReadProcessInteger

#pragma once
#include <iostream>
#include <Windows.h>
#include <string>
#include "Nathalib.h"
using namespace std;

// Process
char process_name[] = "Dummy Target 1.exe";

// Variables
int addr_varInt = 0x001DF750, addr_varString = 0x001DF760, addr_varChar = 0x001DF7A8;

// Pointers


int main()
{     
    while(true)
    {   
        int buffer = 0;

        // Get PID
        cout << process_name << " PID: ";
        int pid = FindProcessByName(process_name);
        if (pid != 0) {
            cout << pid << endl;
        }
        else {
            cout << "Unable to find PID!" << endl;
            getchar();
            return 0;
        }

        // Open Process
        HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
        if (hProcess == NULL) { // Failed to get a handle
            cout << "OpenProcess failed. GetLastError = " << dec << GetLastError() << endl;
            system("pause");
            return EXIT_FAILURE;
        }
        else
        {
            cout << "Process " << pid << " is open." << endl;
        }

        // Read Process Memory
        if (ReadProcessInteger(hProcess, (LPCVOID)addr_varInt, buffer)) {
            getchar();
            cout << "-----------------------------------" << endl << endl;
        }
        else
        {

        }
    }
    return 0;
}

函数头文件

#ifndef NATHALIB
#define NATHALIB
#pragma once
#include <iostream>
#include <Windows.h>
#include <string>
#include <TlHelp32.h>
#include <stdio.h>
using namespace std;

int FindProcessByName(char name[]);
int ReadProcessInteger(HANDLE pid, LPCVOID address, LPVOID &result);

#endif

功能.cpp文件

#include "Nathalib.h"

DWORD ProcessID;

int FindProcessByName(char name[]){
    int pid = 0;
    PROCESSENTRY32 entry;
    entry.dwSize = sizeof(PROCESSENTRY32);

    HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

    if (Process32First(snapshot, &entry) == TRUE)
    {
        while (Process32Next(snapshot, &entry) == TRUE)
        {
            if (stricmp(entry.szExeFile, name) == 0)
            {
                pid = entry.th32ProcessID;
            }
        }
    }

    CloseHandle(snapshot);

    return pid;
}

int ReadProcessInteger(HANDLE pid, LPCVOID address, LPVOID &result) {
    if (ReadProcessMemory(pid, address, result, sizeof(int), NULL)) {

    }
    else {

    }
}

错误消息:

enter image description here

尝试以(LPVOID)buffer&buffer的身份启动,但是没有用(相同的错误)

0 个答案:

没有答案