如何判断当前操作系统是否为x64?百度了一下,几乎全是这个答案
BOOL IsWow64() { typedef BOOL(WINAPI *ISWOW64PROCESS)(HANDLE, PBOOL); ISWOW64PROCESS fnIsWow64Process; BOOL bIsWow64 = FALSE; fnIsWow64Process = (ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); if (fnIsWow64Process != nullptr) fnIsWow64Process(GetCurrentProcess(), &bIsWow64); return bIsWow64; }
其实MSDN上已经明确说明了IsWow64Process函数的第2个参数,当你的进程是x64且系统是x64的时候这个函数是会返回FALSE的
也就是说,在两边都是x64的情况下,上面的代码将会返回FALSE!
那么怎么真正准确的判断当前系统是不是x64呢?
bool isWow64() { #ifdef _WIN64 return true; #else typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); auto fnIsWow64Process = (BOOL(WINAPI*)(HANDLE, PBOOL))GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process"); if (fnIsWow64Process) { BOOL f64 = FALSE; return !!fnIsWow64Process(GetCurrentProcess(), &f64) && f64; } return false; #endif }