Is there a Windows API call that will tell me if I'm running on a 64-bit OS?
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开发者_JAVA百科 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.
IsWow64Process
might be what you are looking for.
GetNativeSystemInfo()
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.
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.
精彩评论