-----------------------------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - THE NUMBER OF TIMES TO TRY AGAIN AFTER CREATE COMPOUND FILE FAILED
                                 January 2024
                 -----------------------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), somtimes the create compound file command runs failed on Windows Vista or later.


2. CAUSE:

     There are some compatible problems when the create compound file command calls the StgCreateDocfile Windows API
     for the Windows Defender program or the antivirus programs.
     Now if the create compound file command calls the StgCreateDocfile Windows API failed,
     it will call the StgCreateDocfile Windows API many times again.

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label7ff775 ::
             push ebp                                                        ;0x007ff775 :        55
             mov ebp , esp                                                   ;0x007ff776 :        8bec
             sub esp , 0110h                                                 ;0x007ff778 :        81ec10010000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x007ff77e :        a190709300
             push ebx                                                        ;0x007ff783 :        53
             push esi                                                        ;0x007ff784 :        56
             mov  esi , dword ptr [ ebp + 8 ]                                ;0x007ff785 :        8b7508
             add esi , 030h                                                  ;0x007ff788 :        83c630
             xor ebx , ebx                                                   ;0x007ff78b :        33db
             cmp  dword ptr [esi] , ebx                                      ;0x007ff78d :        391e
             mov  dword ptr [ ebp - 4 ] , eax                                ;0x007ff78f :        8945fc
             push edi                                                        ;0x007ff792 :        57
             jne Label7ff7ad                                                 ;0x007ff793 :        7518


     ;
     ;                 ------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE NUMBER OF TIMES TO TRY AGAIN AFTER CREATE COMPOUND FILE FAILED
     ;                                  August 2023
     ;                 ------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; The number of times to try again after create compound file failed.
     ;
     ; 2023/8/2, by ccb
     ;

     ;         push esi                                                        ;0x007ff795 :        56
     ;         push ebx                                                        ;0x007ff796 :        53
     ;         pushd 04001012h                                                 ;0x007ff797 :        6812100004
     ;         push ebx                                                        ;0x007ff79c :        53
     ;         call  StgCreateDocfile                            ;0x007ff79d :        ff15e47b9100

             mov dword ptr vfpa_createcompoundfile_createcompoundfile_cnt,00h

     Label7ff795 ::
             push esi
             push ebx
             pushd 04001012h
             push ebx
             call  StgCreateDocfile
             test eax , eax
             je Label7ff7a3
             mov ecx,dword ptr vfpa_sys9139_data
             inc dword ptr vfpa_createcompoundfile_createcompoundfile_cnt
             cmp dword ptr vfpa_createcompoundfile_createcompoundfile_cnt,ecx
             ja Label7ff7a3
             push dword ptr vfpa_sys9074_data
             call  Sleep
             jmp Label7ff795


     Label7ff7a3 ::
             mov edi , eax                                                   ;0x007ff7a3 :        8bf8
             cmp edi , ebx                                                   ;0x007ff7a5 :        3bfb
             jne Label7ff84b                                                 ;0x007ff7a7 :        0f859e000000

     Label7ff7ad ::
             mov  ecx , dword ptr [ ebp + 12 ]                               ;0x007ff7ad :        8b4d0c
             pushd 0105h                                                     ;0x007ff7b0 :        6805010000
             add ecx , 04h                                                   ;0x007ff7b5 :        83c104
             lea edi ,  dword ptr [ ebp + 0FFFFFEF4h ]                       ;0x007ff7b8 :        8dbdf4feffff
             call Fun4a742a                                                  ;0x007ff7be :        e8677ccaff
             call Fun53d093                                                  ;0x007ff7c3 :        e8cbd8d3ff
             push eax                                                        ;0x007ff7c8 :        50
             push ebx                                                        ;0x007ff7c9 :        53
             pushd 0FFFFFFFFh                                                ;0x007ff7ca :        6aff
             mov eax , edi                                                   ;0x007ff7cc :        8bc7
             push eax                                                        ;0x007ff7ce :        50
             lea ebx ,  dword ptr [ ebp + 0FFFFFEF0h ]                       ;0x007ff7cf :        8d9df0feffff
             call Fun4d9aab                                                  ;0x007ff7d5 :        e8d1a2cdff
             mov ebx , eax                                                   ;0x007ff7da :        8bd8
             xor edi , edi                                                   ;0x007ff7dc :        33ff
             cmp ebx , edi                                                   ;0x007ff7de :        3bdf
             je Label7ff7f4                                                  ;0x007ff7e0 :        7412
             mov  eax , dword ptr [esi]                                      ;0x007ff7e2 :        8b06
             cmp eax , edi                                                   ;0x007ff7e4 :        3bc7
             je Label7ff7ee                                                  ;0x007ff7e6 :        7406
             mov  ecx , dword ptr [eax]                                      ;0x007ff7e8 :        8b08
             push eax                                                        ;0x007ff7ea :        50
             call  dword ptr [ ecx + 8 ]                                     ;0x007ff7eb :        ff5108

     Label7ff7ee ::
             mov  dword ptr [esi] , edi                                      ;0x007ff7ee :        893e
             mov eax , ebx                                                   ;0x007ff7f0 :        8bc3
             jmp Label7ff84d                                                 ;0x007ff7f2 :        eb59

     Label7ff7f4 ::
             cmp  dword ptr [ ebp + 20 ] , edi                               ;0x007ff7f4 :        397d14
             mov  eax , dword ptr [ ebp + 8 ]                                ;0x007ff7f7 :        8b4508
             lea ecx ,  dword ptr [ eax + 32 ]                               ;0x007ff7fa :        8d4820
             push ecx                                                        ;0x007ff7fd :        51
             push  dword ptr [esi]                                           ;0x007ff7fe :        ff36
             push eax                                                        ;0x007ff800 :        50
             push edi                                                        ;0x007ff801 :        57
             pushd 01h                                                       ;0x007ff802 :        6a01
             pushd offset Data920d04                                                  ;0x007ff804 :        68040d9200
             push  dword ptr [ ebp + 0FFFFFEF0h ]                            ;0x007ff809 :        ffb5f0feffff
             je Label7ff819                                                  ;0x007ff80f :        7408
             call  OleCreateLinkToFile                         ;0x007ff811 :        ff15a87b9100
             jmp Label7ff824                                                 ;0x007ff817 :        eb0b

     Label7ff819 ::
             pushd offset Data9223dc                                                  ;0x007ff819 :        68dc239200
             call  OleCreateFromFile                           ;0x007ff81e :        ff15ac7b9100

     Label7ff824 ::
             lea esi ,  dword ptr [ ebp + 0FFFFFEF0h ]                       ;0x007ff824 :        8db5f0feffff
             mov edi , eax                                                   ;0x007ff82a :        8bf8
             call Fun4d6e5f                                                  ;0x007ff82c :        e82e76cdff
             test edi , edi                                                  ;0x007ff831 :        85ff
             jne Label7ff84b                                                 ;0x007ff833 :        7516
             mov  esi , dword ptr [ ebp + 8 ]                                ;0x007ff835 :        8b7508
             mov  eax , dword ptr [esi]                                      ;0x007ff838 :        8b06
             push esi                                                        ;0x007ff83a :        56
             call  dword ptr [ eax + 112 ]                                   ;0x007ff83b :        ff5070
             mov edi , eax                                                   ;0x007ff83e :        8bf8
             test edi , edi                                                  ;0x007ff840 :        85ff
             jne Label7ff84b                                                 ;0x007ff842 :        7507
             or  dword ptr [ esi + 0A0h ] , 01h                              ;0x007ff844 :        838ea000000001

     Label7ff84b ::
             mov eax , edi                                                   ;0x007ff84b :        8bc7

     Label7ff84d ::
             mov  ecx , dword ptr [ ebp - 4 ]                                ;0x007ff84d :        8b4dfc
             pop edi                                                         ;0x007ff850 :        5f
             pop esi                                                         ;0x007ff851 :        5e
             pop ebx                                                         ;0x007ff852 :        5b
             call Fun42bf1d                                                  ;0x007ff853 :        e8c5c6c2ff
             leave                                                           ;0x007ff858 :        c9
             ret 010h                                                        ;0x007ff859 :        c21000


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.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix278.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix65.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix66.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix67.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix68.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix69.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix70.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix71.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix72.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix73.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix74.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix84.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix85.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix107.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix108.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix109.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix110.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix143.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix144.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix145.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix146.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix147.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix148.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix149.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix150.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix203.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix261.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix262.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix269.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix270.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix348.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix349.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix350.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix351.asp

     2, microsoft.com:
     https://devblogs.microsoft.com/oldnewthing/20120907-00/?p=6663


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.