【问题标题】:C++ error: 'QueryFullProcessImageNameA' was not declared in this scopeC++ 错误:“QueryFullProcessImageNameA”未在此范围内声明
【发布时间】:2021-07-08 08:05:44
【问题描述】:

我有这个功能,并且我有#include'd必要的文件,但我仍然收到这个错误。

操作系统:Windows 10

编译器:MinGW

string ProcessIdToName(DWORD processId)
{
    string ret;
    HANDLE handle = OpenProcess(
        PROCESS_QUERY_LIMITED_INFORMATION,
        FALSE,
        processId 
    );
    if (handle)
    {
        DWORD buffSize = 1024;
        CHAR buffer[1024];
        if (QueryFullProcessImageNameA(handle, 0, buffer, &buffSize))
        {
            ret = buffer;
        }
        else
        {
            printf("Error GetModuleBaseNameA : %lu", GetLastError());
        }
        CloseHandle(handle);
    }
    else
    {
        printf("Error OpenProcess : %lu", GetLastError());
    }
    return ret;
}

【问题讨论】:

  • @CristiFati 与 QueryFullProcessImageName 相同的错误。
  • 当你在header B中包含header A,同时在header A中包含header B时,通常会发生此错误。你是这样做的吗?
  • Using the Windows Headers。我感觉更合适的解决方案是停止使用 MinGW。它有所有错误的默认值,你迫不及待地不想再使用了。比如... ANSI 编码。
  • Ming 因使用过时的 Windows SDK 而臭名昭著。它的标题可能根本不知道QueryFullProcessImageName()。如果是这样,您可能必须在运行时使用 GetProcAddress() 手动导入函数。

标签: c++ windows winapi mingw


【解决方案1】:

确保在包含标题之前将宏 _WIN32_WINNT 定义为大于或等于 0x0501:

#define _WIN32_WINNT 0x0501
#include <Windows.h>
#include <Psapi.h>

【讨论】:

  • OP 正在尝试使用QueryFullProcessImageName(),而不是GetProcessImageFileName()
猜你喜欢
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
  • 1970-01-01
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多