How to detect 64-bit OS
On 64-bit Windows the 32-bit Windows-based applications run under WOW64 x86 emulator. WOW64 isolates 32-bit applications from 64-bit applications, which includes preventing file and registry collisions. Console, GUI, and service applications are supported. However, 32-bit processes cannot load 64-bit DLLs, and 64-bit processes cannot load 32-bit DLLs.
A 32-bit application can detect whether it is running under WOW64 by calling the IsWow64Process function. The application can obtain additional information about the processor by using the GetNativeSystemInfo function.
The IsWow64Process function is only present in Windows OS that have 64-bit versions. We can check for it existence indirectly using VFP OS() function" or directly with GetProcAddress / GetModuleHandle WIN API functions.
| Operating system | Version number | Has 64-bit version |
|---|---|---|
| Windows Server 2008 | 6.0 | Yes |
| Windows Vista | 6.0 | Yes |
| Windows Server 2003 | 5.2 | Yes |
| Windows XP | 5.1 | Yes |
| Windows 2000 | 5.0 | No |
| This is sample code. Add error handling and adjust to your requirements as necessary. |
&& First determine if IsWow64Process function exists in the OS we're running under && It can be done indirectly using OS() function or directly with GetProcAddress WIN API function && Using OS function &&llIsWow64ProcessExists = (VAL(OS(3)) >= 6 ) OR (VAL(OS(3)) = 5 AND VAL(OS(4)) >= 1 ) && Using GetProcAddress WIN API function DECLARE Long GetModuleHandle IN WIN32API STRING lpModuleName DECLARE Long GetProcAddress IN WIN32API Long hModule, String lpProcName llIsWow64ProcessExists = (GetProcAddress(GetModuleHandle("kernel32"),"IsWow64Process") <> 0) llIs64BitOS = .F. IF llIsWow64ProcessExists DECLARE Long GetCurrentProcess IN WIN32API DECLARE Long IsWow64Process IN WIN32API Long hProcess, Long @ Wow64Process lnIsWow64Process = 0 && IsWow64Process function return value is nonzero if it succeeds && The second output parameter value will be nonzero if VFP application is running under 64-bit OS IF IsWow64Process( GetCurrentProcess(), @lnIsWow64Process) <> 0 llIs64BitOS = (lnIsWow64Process <> 0) ENDIF ENDIF ? llIs64BitOS
The MSDN says on IsWow64Process API page: "Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function."
You're quoting out of context. The full quote: "For compatibility with operating systems that do not support this function, call GetProcAddress to detect whether IsWow64Process is implemented in Kernel32.dll. If GetProcAddress succeeds, it is safe to call this function. Otherwise, WOW64 is not present. Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function".
IOW, just checking for presence of IsWow64Process() function in the Kernel32.dll is not reliable way to detect 64-bit OS. OTOH, using the IsWow64Process() to to detect 64-bit OS from within VFP is fine.