How to detect on C++ is windows 32 or 64 bit? I see a lot of examples in .Net but I need C++. Also IsWow64Process() dosen't works for me, becouse "If the process is running under 32-bit Windows, the value is set to FALSE. If the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE"
if I have 32 bit proc under 32 bit OS I have FALSE if I have 64 bit proc under 64 bit OS I have FALSE
BUT I dont care about process bit I need OS bit
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
}
GetSystemWow64DirectoryW
Retrieves the path of the system directory used by WOW64. This directory is not present on 32-bit Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With