2012-03-10 54 views
0

我正在做一些需要獲取跨平臺cmoputer的HWID的東西。這是用C++編寫的,我正在Qt Creator中使用Qt框架。我真的沒有發現太多,所以我會解釋。我試圖在Windows上獲取HWID,並且一旦我嘗試編譯它,它會一直說我有無法解析的外部符號。這裏是我的HWID填充碼:HWID Windows - 使用Qt框架

#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[email protected] referenced in function "public: class QString __thiscall MainWindow::windows_hwid(void)" ([email protected]@@[email protected]@XZ)

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

我敢肯定,99%的底部有一個引起我的第一一,所以我會忽略這一點。我不知道該怎麼辦...... Mac的工作正常,只是Windows給我的問題。謝謝,Hetelek。

+0

你添加以下Windows庫:Advapi32.lib? – akhisp 2012-03-10 23:26:40

回答

1

你有一個鏈接器錯誤,是由於你已經包含了相關的包含文件,但是你沒有鏈接你的目標文件和正確的導入庫。將Advapi32.lib添加到庫鏈接並錯誤將消失。

順便說一句,來鏈接特定API正確的庫及其在MSDN文檔中總是被指定:如果你看一下page of GetCurrentHwProfile,你會發現:

Header: Winbase.h (include Windows.h)

Library: Advapi32.lib

DLL: Advapi32.dll