Wednesday, March 8, 2017

Determine What Operating System in Visual Foxpro


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 included in Windows OS that have 64-bit versions. To avoid an error we have to check for it presence with GetProcAddress / GetModuleHandle WIN API functions before it can be called.


lcOS = OS(1)
DO CASE
CASE "6.02" $ lcOS AND OS(11) = "1"
 lcPlatform = "WIN8"
CASE "6.01" $ lcOS AND OS(11) = "1"
 lcPlatform = "WIN7"
CASE "6.01" $ lcOS
 lcPlatform = "WIN2008R2"
CASE "6.00" $ lcOS AND OS(11) = "1"
 lcPlatform = "VISTA"
CASE "6.00" $ lcOS
 lcPlatform = "WIN2008"
CASE "5.02" $ lcOS
 lcPlatform = "WIN2003"
CASE "5.01" $ lcOS
 lcPlatform = "WINXP"
CASE "5.0" $ lcOS
 lcPlatform = "WIN2000"
CASE "NT" $ lcOS
 lcPlatform = "WINNT"
CASE "4.0" $ lcOS OR "3.9" $ lcOS
 lcPlatform = "WIN95"
CASE "4.1" $ lcOS
 lcPlatform = "WIN98"
CASE "4.9" $ lcOS
 lcPlatform = "WINME"
CASE "3." $ lcOS
 lcPlatform = "WIN31"
OTHERWISE
 lcPlatform = "(Unknown)"
ENDCASE

** IsWow64Process
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 
lcPlatform = lcPlatform+" "+IIF(llIs64BitOS,"(64-bit)","(32-bit)")

? lcPlatform
}

No comments:

Post a Comment