The Win32 API function to detect information about the underlying system is GetNativeSystemInfo
. Call the function and read the wProcessorArchitecture
member of the SYSTEM_INFO
struct that the function populates.
Although it is actually possible to use IsWow64Process
to detect this. If you call IsWow64Process
and TRUE
is returned, then you know that you are running on a 64 bit system. Otherwise, FALSE
is returned. And then you just need to test the size of a pointer, for instance. A 32 bit pointer indicates a 32 bit system, and a 64 bit pointer indicates a 64 bit system. In fact, you can probably get the information from a conditional supplied by the compiler, depending on which compiler you use, since the size of the pointer is known at compile time.
Raymond Chen described this approach in a blog article. He helpfully included code which I reproduce here:
BOOL Is64BitWindows()
{
#if defined(_WIN64)
return TRUE; // 64-bit programs run only on Win64
#elif defined(_WIN32)
// 32-bit programs run on both 32-bit and 64-bit Windows
// so must sniff
BOOL f64 = FALSE;
return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
return FALSE; // Win64 does not support Win16
#endif
}