怎么样通过C++判断64位和32位系统?
怎么样通过C++判断64位和32位系统?
{32位系统上,指针和long类型都是32位;而在64位系统上,指针和long类型都是64位的。编程序的时候注意这两种类型和int等类型强制转换时会和32位系统不一样。其他方面没有大的区别}
#include <windows.h>
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
BOOL IsWow64()
{
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle("kernel32"),
"IsWow64Process"
);
BOOL bIsWow64 = FALSE;
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
// Error handle
return FALSE;
}
}
return bIsWow64;
}
BOOL Is64BitWindows()
{
#if defined(_WIN64)
return TRUE; // 64-bit programs run only on Win64
#else // _WIN32
// 32-bit programs run on both 32-bit and 64-bit Windows
// so must sniff
return IsWow64();
#endif
}
BOOL Is64BitCpu()
{
SYSTEM_INFO si;
BOOL bIs64BitCpu;
if (IsWow64())
{
bIs64BitCpu = TRUE;
}
else
{
GetSystemInfo(&si);
bIs64BitCpu = ((si.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_IA64)
|| (si.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_AMD64))
? TRUE : FALSE;
}
return bIs64BitCpu;
}