H4ZE
H4ZE

Reputation: 183

C++ error: 'QueryFullProcessImageNameA' was not declared in this scope

I have this function, and I have #include'd the necessary files, yet I am still getting this error.

OS: Windows 10

Compiler: 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;
}

Upvotes: 0

Views: 711

Answers (1)

H4ZE
H4ZE

Reputation: 183

Make sure you define the macro _WIN32_WINNT to be larger or equal 0x0501 before you include the headers:

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

Upvotes: 1

Related Questions