1、IsWow64Process
確定指定進程是否運行在64位操作系統的32環境(Wow64)下。
語法
BOOL WINAPI IsWow64Process( __in HANDLE hProcess, __out PBOOL Wow64Process );
參數
hProcess
進程句柄。該句柄必須具有PROCESS_QUERY_INFORMATION 或者 PROCESS_QUERY_LIMITED_INFORMATION 訪問權限
Wow64Process
指向一個bool值,
如果該進程是32位進程,運行在64操作系統下,該值為true,否則為false。
如果該進程是一個64位應用程序,運行在64位系統上,該值也被設置為false。
返回值
如果函數成功返回值為非零值。
如果該函數失敗,則返回值為零。要獲取擴展的錯誤的信息,請調用GetLastError .
微軟的例子:
#include <windows.h> #include <tchar.h> typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); LPFN_ISWOW64PROCESS fnIsWow64Process; BOOL IsWow64() { BOOL bIsWow64 = FALSE; //IsWow64Process is not available on all supported versions of Windows. //Use GetModuleHandle to get a handle to the DLL that contains the function //and GetProcAddress to get a pointer to the function if available. fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( GetModuleHandle(TEXT("kernel32")),"IsWow64Process"); if(NULL != fnIsWow64Process) { if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64)) { //handle error } } return bIsWow64; } int main( void ) { if(IsWow64()) _tprintf(TEXT("The process is running under WOW64.\n")); else _tprintf(TEXT("The process is not running under WOW64.\n")); return 0; }
注意:使用此函數判斷操作系統是32位還是64位並不合適,勉強要用的話,可以指向一個32位進程。
2、比較合適的做法是:
BOOL Is64bitSystem() { SYSTEM_INFO si; GetNativeSystemInfo(&si); if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 ) return TRUE; else return FALSE; }