Visual c ++ GetModuleFIleNameEx()返回随机十六进制

时间:2019-05-13 01:29:03

标签: windows visual-c++ psapi

所以我一直在使用psapi.h及其相关功能,并且在通过pid返回进程的pid(例如005FF818)获取进程目录时遇到麻烦,它在msdn文档中表示其指针{{3} },但&filename仍为十六进制,* filename为67。

我可以在Windows 10上使用Visual Studio 2017

请注意,我使用了另一篇文章中的代码:https://docs.microsoft.com/en-us/windows/desktop/api/psapi/nf-psapi-getmodulefilenameexa

#include "pch.h"
#include <stdlib.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include "Windows.h"
#include "psapi.h"
#include <tchar.h>

using namespace std;

DWORD proc_id[1024];    // array for process id's
DWORD ret_bytes;        // number of bytes returned from
EnumProcesses()
FILE *proc_file;

int main() {
    HANDLE Handle = NULL;
    TCHAR filename[MAX_PATH];
    Handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,    false, 5920);
    if (Handle != NULL) {
        if (GetModuleFileNameEx(Handle, NULL, filename, MAX_PATH) == 0) {
            Print("Cant get name");
        }
        else {
            cout << "Process name is: " << filename << endl;
        }
        CloseHandle(Handle);
    }
    else {
        Print("Failed to open");
    }
}

预期接近C:\ Program Files \ Mozilla Firefox \ firefox.exe 有随机的十六进制,例如005FF818或009BF658

0 个答案:

没有答案