Is there a Windows API call that will tell me if I'm running on a 64-bit OS? I have some legacy c++ code that makes a call to GetVersionEx to fill in a OSVERSIONINFO structure, but that only tells me (AFAIK) the OS (Vista, V7, etc.), but not the processing architecture. I can hack around this by simply looking for the existence of "C:\Program Files (x86)...", but this seems ugly. I'm sure there must be an API to return this info.
-
Just out of curiosity, why do you need to know? Is it not something that can't be done if pre-compiler directives? – Rowland Shaw Oct 29 '09 at 20:48
-
@Rowland: That cannot be done after a program has been released. Besides, a 64-bit OS is significantly different from a 32-bit at the hardware layers; i.e. a 32-bit driver installer should detect the 'bitness' of the host OS before installing. – Cecil Has a Name Oct 29 '09 at 20:54
-
I thought WOW handled the talking to drivers et al - I would assume that installation of said drivers would be done with an installation framework; just curiosity with the the intention of understanding *why* this would need to be done... – Rowland Shaw Oct 29 '09 at 21:00
4 Answers
IsWow64Process
might be what you are looking for.

- 8,920
- 3
- 38
- 56
-
1Just be aware that this function always returns false if run from a 64-bit application (because 64-bit apps aren't running in WoW64 mode). – Powerlord Oct 29 '09 at 21:00
-
1Absolutely. (Of course, detecting whether the current application is a 64-bit application could be done at compile-time, e.g. via `_M_X64` in msvc) – Michael Oct 29 '09 at 21:09
I found this post that seems to provide a good answer: Detect whether current Windows version is 32 bit or 64 bit
I don't know why it didn't come up when I search Stack Overflow before posting.
Incidentally, the best solution for me is to simply check for the ProgramW6432 environment variable.

- 1
- 1

- 11,300
- 15
- 49
- 66
The solution is pretty straight-forward. If you are compiling for 64-bit, you already know that you are running on a 64-bit version of Windows. So you only need to call IsWow64Process when compiling for 32-bit. The following implementation returns true
, if it is running on a 64-bit version of Windows:
bool Is64BitPlatform() {
#if defined(_WIN64)
return true; // 64-bit code implies a 64-bit OS
#elif defined(_WIN32)
// 32-bit code runs on a 64-bit OS, if IsWow64Process returns TRUE
BOOL f = FALSE;
return ::IsWow64Process(GetCurrentProcess(), &f) && f;
#else
#error Unexpected platform.
#endif
}
This answers the question you asked. The answer to the question you should have asked instead was posted in the response by Jerry Coffin already: Simply call GetNativeSystemInfo.

- 1
- 1

- 46,945
- 8
- 85
- 181