Reputation: 2256
#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
Reputation: 2256
Need to load Psapi.lib
Add in the <project name>.pro
file
...
LIBS += \
-lPsapi
...
Upvotes: 1