-------------------------------------------------
                        VFP 9.0 FIX - OS() Function
                                 January 2017
                 -------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), the OS() function always returns "Windows 6.02" on Windows 8.1 or later.

     There is a program for test:

     *PROC testosfunction

     SET STEP OFF
     SET ECHO OFF
     SET DEBUG OFF
     SET ESCAPE OFF
     SET TALK OFF
     SET SAFETY OFF

     _SCREEN.VISIBLE=.T.
     _SCREEN.WINDOWSTATE=2

     SET EXCLUSIVE OFF
     SET MULTILOCK ON
     SET COLLATE TO "MACHINE"

     CLOSE DATABASES ALL
     CLOSE TABLES ALL

     ?"OS() = "+OS()
     ?"OS(1) = "+OS(1)
     ?"OS(2) = "+OS(2)
     ?"OS(3) = "+OS(3)
     ?"OS(4) = "+OS(4)
     ?"OS(5) = "+OS(5)
     ?"OS(6) = "+OS(6)
     ?"OS(7) = "+OS(7)
     ?"OS(8) = "+OS(8)
     ?"OS(9) = "+OS(9)
     ?"OS(10) = "+OS(10)
     ?"OS(11) = "+OS(11)
     WAIT

     CLOSE DATABASES ALL
     CLOSE TABLES ALL

     RETURN

     * END OF PROC TESTOSFUNCTION.


2. CAUSE:

     For some reasons, the GetVersion and GetVersionEx windows api can't work correctly on windows 8.1 or later,
     please refer to:
     https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx

     In vfp9 (and vfp6, vfp7, vfp8), the OS() function use the GetVersionEx windows api to get the operating system version information,
     so it always returns "Windows 6.02" on Windows 8.1 or later.


3. RESOLUTION:

     We can write some code to fix the BUG.

     vfpa_getversionexa proc

     push ebp
     mov ebp,esp
     sub esp,04h
     push eax
     push ebx
     push ecx
     push edx
     push esi
     push edi
     pushfd

     mov eax,dword ptr [ebp+08h]
     push eax
     call GetVersionExA

     mov dword ptr [ebp-04h],eax

     mov edi,dword ptr [ebp+08h]

     ; dwMajorVersion
     mov eax,dword ptr fs:[30h]
     mov eax,dword ptr [eax+0A4h]
     mov dword ptr [edi+04h],eax

     ; dwMinorVersion
     mov eax,dword ptr fs:[30h]
     mov eax,dword ptr [eax+0A8h]
     mov dword ptr [edi+08h],eax

     ; dwBuildNumber
     mov eax,dword ptr fs:[30h]
     movzx eax,word ptr [eax+0ACh]
     mov dword ptr [edi+0Ch],eax

     ; dwPlatformId
     mov eax,dword ptr fs:[30h]
     mov eax,dword ptr [eax+0B0h]
     mov dword ptr [edi+10h],eax

     popfd
     pop edi
     pop esi
     pop edx
     pop ecx
     pop ebx
     pop eax
     mov eax,dword ptr [ebp-04h]
     mov esp,ebp
     pop ebp
     ret 04h

     vfpa_getversionexa endp

     We can use the vfpa_getversionexa() function instead of the GetVersionEx windows api,
     then the OS() function can return the operating system version information correctly on Windows 8.1 or later.

     Please refer to the picture os-windows10.jpg:


4. APPLIES TO:

     VFP 6.0.8167.0
     VFP 6.0.8961.0 (SP5)

     VFP 7.0.0.9262
     VFP 7.0.0.9465 (SP1)

     VFP 8.0.0.2521
     VFP 8.0.0.3117 (SP1)

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.

     IMPORTANT NOTE:
     Please use the OS() function carefully.
     For example, the following code can not run fine in VFP Advanced:
     IF OS(3) >= "6" && OS(3) = "10" on Windows 10 in VFP Advanced
     Recommend to use the following code:
     IF VAL(OS(3)) >= 6 && VAL(OS(3)) = 10 on Windows 10 in VFP Advanced


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com

     2, microsoft.com:
     https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
     https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx
     https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx

     3, foxite.com:
     https://www.foxite.com/archives/detect-difference-between-8-and-81-0000420484.htm
     https://www.foxite.com/archives/exporttoxlsx-vfp-10-tochuanbing-chen-0000434139.htm

     4, mattslay.com:
     http://www.mattslay.com/does-microsoft-visual-foxpro-run-on-windows-10/


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please e-mail to ccb2000@163.com.