在 Qt 中使用 GetModuleFileNameExA 函数时出错 [英] Error using GetModuleFileNameExA function in Qt

查看:51
本文介绍了在 Qt 中使用 GetModuleFileNameExA 函数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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);

以上代码在vs2019中运行正常,但是在qt中使用错误时,出现这个错误:

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

推荐答案

需要加载Psapi.lib

Need to load Psapi.lib

.pro文件中添加

...

LIBS += \
    -lPsapi

...

这篇关于在 Qt 中使用 GetModuleFileNameExA 函数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆