gpt4 book ai didi

c++ - HWID Windows - 使用 Qt 框架

转载 作者:行者123 更新时间:2023-11-28 08:08:40 26 4
gpt4 key购买 nike

我正在制作一些东西,需要获取计算机的 HWID,跨平台。这是在 C++ 中,我正在使用带有 Qt Creator 的 Qt 框架。我真的没有发现太多,所以我会解释。我正在尝试在 Windows 上获取 HWID,并且在我尝试编译它时它一直说我有未解析的外部符号。这是我的 HWID 代码:

#include "mainwindow.h"
#include "ui_mainwindow.h"

#ifdef _WIN32 | _WIN64//Windows
#define _WIN32_WINNT 0x0400
#include <Windows.h>
#define get_hwid() windows_hwid()

#elif defined __APPLE__ //Mac
#define get_hwid() mac_hwid()

#else //Unknown OS
#define get_hwid() unknown_hwid()

#endif

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMessageBox::about(this, "About", get_hwid());
}

QString MainWindow::windows_hwid()
{
HW_PROFILE_INFO hwProfInfo;
if(GetCurrentHwProfile(&hwProfInfo))
{
return "we got it.";
}
return "couldn't get it";
}

QString MainWindow::mac_hwid()
{
QProcess proc;

QStringList args;
args << "-c" << "ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { print $3; }'";
proc.start( "/bin/bash", args );
proc.waitForFinished();

return proc.readAll();
}

QString MainWindow::unknown_hwid()
{
return "hello unknown person!";
}

这会抛出这些错误:

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _imp_GetCurrentHwProfileW@4 referenced in function "public: class QString __thiscall MainWindow::windows_hwid(void)" (?windows_hwid@MainWindow@@QAE?AVQString@@XZ)

debug\MCBruter.exe:-1: error: LNK1120: 1 unresolved externals

我 99% 确定底部的那个是我的第一个引起的,所以我会忽略它。我不知道该怎么做... Mac 的工作正常,只有 Windows 的给我带来了问题。谢谢,海特莱克。

最佳答案

您遇到的是链接器错误,这是由于您包含了相关的包含文件,但您没有将目标文件链接到正确的导入库。将 Advapi32.lib 添加到要链接的库中,错误就会消失。

顺便说一下,特定 API 链接的正确库总是在 MSDN 的文档中指定:如果您查看 page of GetCurrentHwProfile你会发现:

Header: Winbase.h (include Windows.h)

Library: Advapi32.lib

DLL: Advapi32.dll

关于c++ - HWID Windows - 使用 Qt 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9651045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com