------------------------------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - CREATE A NEW COMMAND WINDOW HISTORY FILE BEFORE VISUAL FOXPRO EXITS
                               January 2024
                 ------------------------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp7, vfp8), it will ALWAYS create a new command window history file, and then write data to the file before it exits,
     but sometimes the command window history file is an empty file, the content of the command window history file has been lost.
     In VFP Advanced, if the command window history file exists, it will open the command window history file,
     if the command window history file does not exist, it will create a new command window history file,
     and then write data to the file before it exits.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun5531c3 :: ; proc near
             push ebp                                                        ;0x005531c3 :        55
             lea ebp ,  dword ptr [ esp + 0FFFFFF64h ]                       ;0x005531c4 :        8dac2464ffffff
             sub esp , 011Ch                                                 ;0x005531cb :        81ec1c010000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x005531d1 :        a190709300
             mov  dword ptr [ ebp + 098h ] , eax                             ;0x005531d6 :        898598000000
             mov eax ,  dword ptr [ Data93e6d0 ]                             ;0x005531dc :        a1d0e69300
             test eax , eax                                                  ;0x005531e1 :        85c0
             je Label553259                                                  ;0x005531e3 :        7474
             cmp  dword ptr [ Data9370b4 ] , 00h                             ;0x005531e5 :        833db470930000
             jne Label553259                                                 ;0x005531ec :        756b
             cmp  dword ptr [ Data93ba20 ] , 00h                             ;0x005531ee :        833d20ba930000
             je Label553259                                                  ;0x005531f5 :        7462
             cmp  dword ptr [ Data93926c ] , 00h                             ;0x005531f7 :        833d6c92930000
             jne Label553259                                                 ;0x005531fe :        7559
             mov  eax , dword ptr [eax]                                      ;0x00553200 :        8b00
             mov  eax , dword ptr [ eax + 88 ]                               ;0x00553202 :        8b4058
             push esi                                                        ;0x00553205 :        56
             mov  esi , dword ptr [eax]                                      ;0x00553206 :        8b30
             push edi                                                        ;0x00553208 :        57
             pushd offset Data93ba24                                                  ;0x00553209 :        6824ba9300
             lea eax ,  dword ptr [ ebp - 116 ]                              ;0x0055320e :        8d458c
             push eax                                                        ;0x00553211 :        50
             call Fun434bcf                                                  ;0x00553212 :        e8b819eeff
             pushd offset Data9256a0                                                  ;0x00553217 :        68a0569200
             lea eax ,  dword ptr [ ebp - 116 ]                              ;0x0055321c :        8d458c
             push eax                                                        ;0x0055321f :        50
             lea eax ,  dword ptr [ ebp - 112 ]                              ;0x00553220 :        8d4590
             push eax                                                        ;0x00553223 :        50
             call Fun42c5c5                                                  ;0x00553224 :        e89c93edff


     ;
     ;                 -------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - CREATE A NEW COMMAND WINDOW HISTORY FILE BEFORE VISUAL FOXPRO EXITS
     ;                                  July 2022
     ;                 -------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, it will ALWAYS create a new command window history file, and then write data to the file before it exits.
     ; In VFP Advanced, it will open the command window history file, and then write data to the file before it exits.
     ;
     ; 2022/7/8, by ccb
     ;

             cmp dword ptr vfpa_sys9103_data,00h
             jne Label553229
             mov edx , 01220h
             lea ecx ,  dword ptr [ ebp - 112 ]
             call Fun42ce21
             mov edi , eax
             test edi , edi
             jl Label553229
             jmp Label55323c


     Label553229 ::
             mov edx , 01228h                                                ;0x00553229 :        ba28120000
             lea ecx ,  dword ptr [ ebp - 112 ]                              ;0x0055322e :        8d4d90
             call Fun42ce21                                                  ;0x00553231 :        e8eb9bedff
             mov edi , eax                                                   ;0x00553236 :        8bf8
             test edi , edi                                                  ;0x00553238 :        85ff
             jl Label553257                                                  ;0x0055323a :        7c1b

     Label55323c ::
             and  byte ptr [ esi + 0E5h ] , 0EFh                             ;0x0055323c :        80a6e5000000ef
             pushd 00h                                                       ;0x00553243 :        6a00
             lea eax ,  dword ptr [ ebp - 128 ]                              ;0x00553245 :        8d4580
             push eax                                                        ;0x00553248 :        50
             push esi                                                        ;0x00553249 :        56
             push edi                                                        ;0x0055324a :        57
             call Fun555683                                                  ;0x0055324b :        e833240000


     ;
     ;                 -------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - CREATE A NEW COMMAND WINDOW HISTORY FILE BEFORE VISUAL FOXPRO EXITS
     ;                                  July 2022
     ;                 -------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, it will ALWAYS create a new command window history file, and then write data to the file before it exits.
     ; In VFP Advanced, it will open the command window history file, and then write data to the file before it exits.
     ;
     ; 2022/7/8, by ccb
     ;

             cmp dword ptr vfpa_sys9103_data,00h
             jne Label553250
             mov eax , edi
             test eax , eax
             jl Label553250
             imul eax , eax , 038h
             add eax , dword ptr [ Data93757c ]
             mov ecx , dword ptr [eax+4]
             push ebx
             mov ebx , edi
             push 00h
             push ecx
             call Fun41a6ae
             pop ebx
             jmp Label553250


     Label553250 ::
             mov ecx , edi                                                   ;0x00553250 :        8bcf
             call Fun42ddf2                                                  ;0x00553252 :        e89babedff

     Label553257 ::
             pop edi                                                         ;0x00553257 :        5f
             pop esi                                                         ;0x00553258 :        5e

     Label553259 ::
             mov  ecx , dword ptr [ ebp + 098h ]                             ;0x00553259 :        8b8d98000000
             call Fun42bf1d                                                  ;0x0055325f :        e8b98cedff
             add ebp , 09Ch                                                  ;0x00553264 :        81c59c000000
             leave                                                           ;0x0055326a :        c9
             ret                                                             ;0x0055326b :        c3


4. APPLIES TO:

     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_vfp9fix220.asp


6. OTHER:

     For reference only, there is no guarantees.

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