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

标签 c++ qt

我正在制作一些东西,需要获取计算机的 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/

相关文章:

php - 自动重新排列图像的行

c++ - 在 C++/C 中获取错误的绝对值

c++ - 用较小的 QPixMap 替换 QPixMap 的一部分

qt - Qt Creator中是否有按钮的hide属性?

c++ - 扩展 QAbstractListModel 以显示自定义背景颜色?

c++ - 这两种访问数组的方法是否实现相同?

c++ - 如何通过跳过=从txt文件中读取整数?

qt - 如何在我处理之前报告进度而不浏览整个文件

c++ - UI 中的 Qt5 小部件属性

c++ - 区分 C++ 静态方法是被类调用还是被对象调用