----------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - THE DELAY TIME IN MILLISECONDS AFTER CLOSE FILE
                                 January 2024
                 ----------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), there are some compatible problems for the close file command on Windows Vista or later.


2. CAUSE:

     There are some compatible problems when the close file command calls the CloseHandle Windows API
     for the Windows Defender program or the antivirus programs.
     Now after the close file command calls the CloseHandle Windows API,
     it will delay the user-specified time in milliseconds.

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun42ddf2 :: ; proc near
             push ebp                                                        ;0x0042ddf2 :        55
             lea ebp ,  dword ptr [ esp + 0FFFFFE70h ]                       ;0x0042ddf3 :        8dac2470feffff
             sub esp , 0268h                                                 ;0x0042ddfa :        81ec68020000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x0042de00 :        a190709300
             push ebx                                                        ;0x0042de05 :        53
             push esi                                                        ;0x0042de06 :        56
             mov  dword ptr [ ebp + 018Ch ] , eax                            ;0x0042de07 :        89858c010000
             mov eax ,  dword ptr [ Data937108 ]                             ;0x0042de0d :        a108719300
             push edi                                                        ;0x0042de12 :        57
             mov edi , ecx                                                   ;0x0042de13 :        8bf9
             cmp edi , eax                                                   ;0x0042de15 :        3bf8
             mov  dword ptr [ ebp + 120 ] , edi                              ;0x0042de17 :        897d78
             mov  dword ptr [ ebp + 124 ] , 00h                              ;0x0042de1a :        c7457c00000000
             jnb Label57ffd7                                                 ;0x0042de21 :        0f83b0211500
             mov  ecx , dword ptr [ Data93757c ]                             ;0x0042de27 :        8b0d7c759300
             mov ebx , edi                                                   ;0x0042de2d :        8bdf
             imul ebx , ebx , 038h                                           ;0x0042de2f :        6bdb38
             mov  al , byte ptr [ ebx + ecx + 44 ]                           ;0x0042de32 :        8a440b2c
             add ebx , ecx                                                   ;0x0042de36 :        03d9
             test al , 01h                                                   ;0x0042de38 :        a801
             je Label57ffe1                                                  ;0x0042de3a :        0f84a1211500
             mov  eax , dword ptr [ ebx + 52 ]                               ;0x0042de40 :        8b4334
             test eax , eax                                                  ;0x0042de43 :        85c0
             mov esi , ebx                                                   ;0x0042de45 :        8bf3
             mov  dword ptr [ ebp + 080h ] , esi                             ;0x0042de47 :        89b580000000
             jne Label5501a0                                                 ;0x0042de4d :        0f854d231200

     Label42de53 ::
             test  byte ptr [ ebx + 8 ] , 010h                               ;0x0042de53 :        f6430810
             jne Label42dff4                                                 ;0x0042de57 :        0f8597010000
             lea edx ,  dword ptr [ ebp + 116 ]                              ;0x0042de5d :        8d5574
             lea eax ,  dword ptr [ ebp + 0FFFFFF78h ]                       ;0x0042de60 :        8d8578ffffff
             call Fun42c27f                                                  ;0x0042de66 :        e814e4ffff
             pushd 00h                                                       ;0x0042de6b :        6a00
             push eax                                                        ;0x0042de6d :        50
             call Fun42c2be                                                  ;0x0042de6e :        e84be4ffff
             add esp , 08h                                                   ;0x0042de73 :        83c408
             test eax , eax                                                  ;0x0042de76 :        85c0
             mov  dword ptr [ ebp + 124 ] , eax                              ;0x0042de78 :        89457c
             jne Label42de91                                                 ;0x0042de7b :        7514
             mov  esi , dword ptr [ ebp + 120 ]                              ;0x0042de7d :        8b7578
             push esi                                                        ;0x0042de80 :        56
             call Fun431d6c                                                  ;0x0042de81 :        e8e63e0000
             test eax , eax                                                  ;0x0042de86 :        85c0
             je Label42de91                                                  ;0x0042de88 :        7407
             mov eax , esi                                                   ;0x0042de8a :        8bc6
             call Fun42dd40                                                  ;0x0042de8c :        e8affeffff

     Label42de91 ::
             mov eax ,  dword ptr [ Data937220 ]                             ;0x0042de91 :        a120729300
             lea ecx ,  dword ptr [ ebp + 0FFFFFF78h ]                       ;0x0042de96 :        8d8d78ffffff
             cmp ecx , eax                                                   ;0x0042de9c :        3bc8
             jne Label580038                                                 ;0x0042de9e :        0f8594211500
             mov  edx , dword ptr [ Data937220 ]                             ;0x0042dea4 :        8b1520729300
             mov  eax , dword ptr [ edx + 76 ]                               ;0x0042deaa :        8b424c
             cmp  dword ptr [ ebp + 116 ] , eax                              ;0x0042dead :        394574
             mov dword ptr [ Data937220 ] ,  eax                             ;0x0042deb0 :        a320729300
             jne Label580042                                                 ;0x0042deb5 :        0f8587211500
             lea edx ,  dword ptr [ ebp + 112 ]                              ;0x0042debb :        8d5570
             lea eax ,  dword ptr [ ebp - 56 ]                               ;0x0042debe :        8d45c8
             call Fun42c27f                                                  ;0x0042dec1 :        e8b9e3ffff
             pushd 00h                                                       ;0x0042dec6 :        6a00
             push eax                                                        ;0x0042dec8 :        50
             call Fun42c2be                                                  ;0x0042dec9 :        e8f0e3ffff
             mov esi , eax                                                   ;0x0042dece :        8bf0
             add esp , 08h                                                   ;0x0042ded0 :        83c408
             test esi , esi                                                  ;0x0042ded3 :        85f6
             jne Label42defd                                                 ;0x0042ded5 :        7526
             mov  edi , dword ptr [ ebp + 080h ]                             ;0x0042ded7 :        8bbd80000000
             mov  eax , dword ptr [ edi + 44 ]                               ;0x0042dedd :        8b472c
             test  byte ptr ah , 01h                                         ;0x0042dee0 :        f6c401
             je Label58004c                                                  ;0x0042dee3 :        0f8463211500

     Label42dee9 ::
             mov  edi , dword ptr [ edi + 40 ]                               ;0x0042dee9 :        8b7f28
             push edi                                                        ;0x0042deec :        57
             call  CloseHandle                                 ;0x0042deed :        ff15f0719100


     ;
     ;                 -----------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE DELAY TIME IN MILLISECONDS AFTER CLOSE FILE
     ;                                December 2020
     ;                 -----------------------------------------------------------------------
     ;                                     CCB
     ;
     ; The delay time in milliseconds after close file.
     ;
     ; 2020/12/26, by ccb
     ;

             cmp dword ptr vfpa_sys9046_data,00h
             jle Label42def3
             push eax
             push dword ptr vfpa_sys9046_data
             call  Sleep
             pop eax


     Label42def3 ::
             neg eax                                                         ;0x0042def3 :        f7d8
             sbb eax , eax                                                   ;0x0042def5 :        1bc0
             inc eax                                                         ;0x0042def7 :        40
             call Label42d319                                                ;0x0042def8 :        e81cf4ffff

     Label42defd ::
             mov  ecx , dword ptr [ Data937220 ]                             ;0x0042defd :        8b0d20729300
             lea eax ,  dword ptr [ ebp - 56 ]                               ;0x0042df03 :        8d45c8
             cmp eax , ecx                                                   ;0x0042df06 :        3bc1
             jne Label580057                                                 ;0x0042df08 :        0f8549211500
             mov  ecx , dword ptr [ Data937220 ]                             ;0x0042df0e :        8b0d20729300
             mov  eax , dword ptr [ ecx + 76 ]                               ;0x0042df14 :        8b414c
             mov  ecx , dword ptr [ ebp + 112 ]                              ;0x0042df17 :        8b4d70

     Label42df1a ::
             cmp ecx , eax                                                   ;0x0042df1a :        3bc8
             mov dword ptr [ Data937220 ] ,  eax                             ;0x0042df1c :        a320729300
             jne Label580061                                                 ;0x0042df21 :        0f853a211500
             mov  eax , dword ptr [ ebp + 124 ]                              ;0x0042df27 :        8b457c
             test eax , eax                                                  ;0x0042df2a :        85c0
             jne Label42df36                                                 ;0x0042df2c :        7508
             test esi , esi                                                  ;0x0042df2e :        85f6
             jne Label58006b                                                 ;0x0042df30 :        0f8535211500

     Label42df36 ::
             mov  esi , dword ptr [ ebp + 080h ]                             ;0x0042df36 :        8bb580000000

     Label42df3c ::
             mov  eax , dword ptr [ ebp + 124 ]                              ;0x0042df3c :        8b457c
             xor edi , edi                                                   ;0x0042df3f :        33ff
             cmp eax , edi                                                   ;0x0042df41 :        3bc7
             jne Label580073                                                 ;0x0042df43 :        0f852a211500

     Label42df49 ::
             mov  ecx , dword ptr [ esi + 12 ]                               ;0x0042df49 :        8b4e0c
             call Fun42c1e2                                                  ;0x0042df4c :        e891e2ffff
             mov  dword ptr [ esi + 12 ] , edi                               ;0x0042df51 :        897e0c
             mov  ecx , dword ptr [ esi + 16 ]                               ;0x0042df54 :        8b4e10
             call Fun42c1e2                                                  ;0x0042df57 :        e886e2ffff
             mov  ecx , dword ptr [ esi + 20 ]                               ;0x0042df5c :        8b4e14
             mov  dword ptr [ esi + 16 ] , edi                               ;0x0042df5f :        897e10
             call Fun42c1e2                                                  ;0x0042df62 :        e87be2ffff
             mov  dword ptr [ esi + 20 ] , edi                               ;0x0042df67 :        897e14
             mov  edi , dword ptr [ Data93710c ]                             ;0x0042df6a :        8b3d0c719300
             test edi , edi                                                  ;0x0042df70 :        85ff
             je Label42df91                                                  ;0x0042df72 :        741d

     Label42df74 ::
             mov  ebx , dword ptr [edi]                                      ;0x0042df74 :        8b1f
             mov  edx , dword ptr [ ebp + 120 ]                              ;0x0042df76 :        8b5578
             mov  eax , dword ptr [ ebx + 4 * edx + 0178h ]                  ;0x0042df79 :        8b849378010000
             test eax , eax                                                  ;0x0042df80 :        85c0
             jne Label516af2                                                 ;0x0042df82 :        0f856a8b0e00

     Label42df88 ::
             mov  ecx , dword ptr [edi]                                      ;0x0042df88 :        8b0f
             mov  edi , dword ptr [ ecx + 12 ]                               ;0x0042df8a :        8b790c
             test edi , edi                                                  ;0x0042df8d :        85ff
             jne Label42df74                                                 ;0x0042df8f :        75e3

     Label42df91 ::
             mov  ecx , dword ptr [ esi + 44 ]                               ;0x0042df91 :        8b4e2c
             mov eax ,  dword ptr [ Data937774 ]                             ;0x0042df94 :        a174779300
             and ecx , 0FFFFF3FEh                                            ;0x0042df99 :        81e1fef3ffff
             cmp esi , eax                                                   ;0x0042df9f :        3bf0
             mov  dword ptr [ esi + 44 ] , ecx                               ;0x0042dfa1 :        894e2c
             mov  dword ptr [ esi + 52 ] , 00h                               ;0x0042dfa4 :        c7463400000000
             je Label42dfd0                                                  ;0x0042dfab :        7423

     Label42dfad ::
             mov  ecx , dword ptr [ ebp + 124 ]                              ;0x0042dfad :        8b4d7c
             test ecx , ecx                                                  ;0x0042dfb0 :        85c9
             jne Label580080                                                 ;0x0042dfb2 :        0f85c8201500
             mov  ecx , dword ptr [ ebp + 018Ch ]                            ;0x0042dfb8 :        8b8d8c010000
             call Fun42bf1d                                                  ;0x0042dfbe :        e85adfffff
             pop edi                                                         ;0x0042dfc3 :        5f
             pop esi                                                         ;0x0042dfc4 :        5e
             pop ebx                                                         ;0x0042dfc5 :        5b
             add ebp , 0190h                                                 ;0x0042dfc6 :        81c590010000
             mov esp , ebp                                                   ;0x0042dfcc :        8be5
             pop ebp                                                         ;0x0042dfce :        5d
             ret                                                             ;0x0042dfcf :        c3


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_vfp9fix143.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_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_vfp9fix278.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix279.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.