2012-06-15 31 views

回答

2

沒有辦法獨家使用Qt,AFAIK。以下是你如何做到這一點。

#include <windows.h> 
#include <tchar.h> 
#include <QtCore/QSysInfo> 

typedef enum { Win_64, Win_32, Error, Other } OsType; 

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 

OsType checkOS() { 
#ifndef Q_OS_WIN32 
    return Other; 
#else 
    // An application compiled for 64 bits can only run on a 64 bit os, 
    // so no need to check any further. 
    if (QSysInfo::WordSize == 64) return Win7_64; 
    // A 32 bit application may be running on a 64 bit OS. 
    BOOL is64 = FALSE; 
    // IsWow64Process may not be available in kernel32 on all Windows versions, so we bind to it 
    // at runtime. 
    LPFN_ISWOW64PROCESS fnIsWow64Process; 
    fnIsWow64Process = (LPFN_ISWOW64PROCESS) 
      GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process"); 
    // No way it's a 64 bit OS if it doesn't have this API. 
    if (fnIsWow64Process == NULL) return Win_32; 
    // Note that GetCurrentProcess() can't fail. 
    if (!IsWow64Process(GetCurrentProcess(), &is64)) return Error; // The check has failed. 
    return is64 ? Win_64 : Win_32; 
#endif 
} 
+0

謝謝你的回覆兄弟...我也想知道爲贏得XP太.. 可能yopu請給XP多一個解決方案。 – Kenta

+0

完成。你想專門檢查Win 7,所以我添加了一個檢查。簡單地刪除該行「修復」它可以在任何64位版本上工作。提示未來:如果你想得到更一般的答案,可以問一個更一般的問題。不要包含不必要的細節。在你的情況下,把「Windows 7」放在這個問題上會起反作用。 –