1. 程式人生 > >QT 判斷是否是64位機

QT 判斷是否是64位機

#include<Windows.h>
typedefvoid(WINAPI*PGNSI)(LPSYSTEM_INFO);
Dialog::Dialog(QWidget*parent):
QDialog(parent),
ui(newUi::Dialog)
{
ui->setupUi(this);
boolIsWin64=false;
#ifdefQ_OS_WIN
OSVERSIONINFOEXosvi;
SYSTEM_INFOsi;
PGNSIpGNSI;
ZeroMemory(&si,sizeof(SYSTEM_INFO));
ZeroMemory(&osvi,sizeof
(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFOEX);
GetVersionEx((OSVERSIONINFO*)&osvi);
pGNSI=(PGNSI)GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")),
"GetNativeSystemInfo");
if(NULL!=pGNSI)
pGNSI(&si);
elseGetSystemInfo(&si);
if(si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64
)
{
IsWin64=true;
}
elseif(si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL)
{
IsWin64=false;
}
#endif
qDebug()<<"the64bit:"<<IsWin64;
}
需要注意的幾個地方:
1.標頭檔案
#include<Windows.h>
2.
typedefvoid(WINAPI*PGNSI)(LPSYSTEM_INFO);