januw a
januw a

Reputation: 2256

Error using GetModuleFileNameExA function in Qt

#include <iostream>
#include <windows.h>
#include <psapi.h>
#include <tlhelp32.h>

    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, 7632);
    wchar_t lpFilename[1024];
    GetModuleFileNameExW(hProcess, NULL, lpFilename, sizeof(lpFilename));
    qDebug() << QString::fromWCharArray(lpFilename);
    CloseHandle(hProcess);

The above code runs normally in vs2019, but when I use it wrong in qt, this error occurs:

error: undefined reference to `GetModuleFileNameExA'
error: ld returned 1 exit status

Upvotes: 0

Views: 307

Answers (1)

januw a
januw a

Reputation: 2256

Need to load Psapi.lib

Add in the <project name>.pro file

...

LIBS += \
    -lPsapi

...

Upvotes: 1

Related Questions