【发布时间】:2012-03-27 21:45:37
【问题描述】:
我正在做一些需要获取计算机的 HWID、跨平台的东西。这是在 C++ 中,我正在使用 Qt 框架和 Qt Creator。我真的没有找到太多关于这个,所以我会解释。我正在尝试在 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 在函数“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 给我带来了问题。谢谢,Hetelek。
【问题讨论】:
-
你是否添加了以下windows库:Advapi32.lib?