---------------------------------------------------------------------------------------------------
                      [ENHANCED] VFP 9.0 FIX - THE MAXIMUM NUMBER OF CHARACTERS FOR THE APPLICATION SEARCH PATH
                                 January 2024
                 ---------------------------------------------------------------------------------------------------
                                    CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 1023,
     now the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 8191.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun40377a :: ; proc near
             push ebp                                                        ;0x0040377a :        55
             mov ebp , esp                                                   ;0x0040377b :        8bec


     ;
     ;                 ----------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE MAXIMUM NUMBER OF CHARACTERS FOR THE APPLICATION SEARCH PATH
     ;                                November 2019
     ;                 ----------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 1023,
     ; now the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 8191.
     ;
     ; 2019/11/20, by ccb
     ;

     ;         sub esp , 0408h                                                 ;0x0040377d :        81ec08040000

             mov eax , 02008h                                                 ;0x0040377d :        81ec08040000
             call Fun42c118


             mov eax ,  dword ptr [ Data937090 ]                             ;0x00403783 :        a190709300
             push ebx                                                        ;0x00403788 :        53
             push edi                                                        ;0x00403789 :        57


     ;
     ;                 ----------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE MAXIMUM NUMBER OF CHARACTERS FOR THE APPLICATION SEARCH PATH
     ;                                November 2019
     ;                 ----------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 1023,
     ; now the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 8191.
     ;
     ; 2019/11/20, by ccb
     ;

     ;         pushd 0400h                                                     ;0x0040378a :        6800040000
     ;         pushd offset Data918f58                                                  ;0x0040378f :        68588f9100
     ;         lea ebx ,  dword ptr [ ebp + 0FFFFFBF8h ]                       ;0x00403794 :        8d9df8fbffff

             pushd 02000h                                                     ;0x0040378a :        6800040000
             pushd offset Data918f58                                                  ;0x0040378f :        68588f9100
             lea ebx ,  dword ptr [ ebp - 02008h ]                       ;0x00403794 :        8d9df8fbffff


             mov  dword ptr [ ebp - 4 ] , eax                                ;0x0040379a :        8945fc
             call Fun41513d                                                  ;0x0040379d :        e89b190100
             test eax , eax                                                  ;0x004037a2 :        85c0
             je Label4037be                                                  ;0x004037a4 :        7418


     ;
     ;                 ----------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE MAXIMUM NUMBER OF CHARACTERS FOR THE APPLICATION SEARCH PATH
     ;                                November 2019
     ;                 ----------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 1023,
     ; now the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 8191.
     ;
     ; 2019/11/20, by ccb
     ;

     ;         mov edx , 0400h                                                 ;0x004037a6 :        ba00040000
             mov edx , 02000h                                                 ;0x004037a6 :        ba00040000


             mov ecx , ebx                                                   ;0x004037ab :        8bcb
             call Fun41b81c                                                  ;0x004037ad :        e86a800100


     ;
     ;                 ----------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE MAXIMUM NUMBER OF CHARACTERS FOR THE APPLICATION SEARCH PATH
     ;                                November 2019
     ;                 ----------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 1023,
     ; now the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 8191.
     ;
     ; 2019/11/20, by ccb
     ;

     ;         mov dword ptr vfpa_searchpath_issearchpath,01h


             mov edi , offset Data935b20                                              ;0x004037b2 :        bf205b9300
             mov edx , ebx                                                   ;0x004037b7 :        8bd3
             call Fun414b0d                                                  ;0x004037b9 :        e84f130100


     ;
     ;                 ----------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE MAXIMUM NUMBER OF CHARACTERS FOR THE APPLICATION SEARCH PATH
     ;                                November 2019
     ;                 ----------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 1023,
     ; now the maximum number of characters for the application search path (from the MS-DOS environment variable PATH) is 8191.
     ;
     ; 2019/11/20, by ccb
     ;

     Label4037bd ::
     ;         mov dword ptr vfpa_searchpath_issearchpath,00h


     Label4037be ::
             mov  ecx , dword ptr [ ebp - 4 ]                                ;0x004037be :        8b4dfc
             call Fun42bf1d                                                  ;0x004037c1 :        e857870200
             pop edi                                                         ;0x004037c6 :        5f
             pop ebx                                                         ;0x004037c7 :        5b
             leave                                                           ;0x004037c8 :        c9
             ret                                                             ;0x004037c9 :        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.

     IMPORTANT NOTE:
     If there are 2 or more semicolons (:) in a path, for example, c:\aaac:\bbb,
     or there are only 2 backslashes (\\) in a path,
     or the length of a path > 260,
     and there is no the config file (config.fpw) in the application folder,
     vfp will cause an error "Error locating config file-bad path?".

     For more information, please refer to:
     https://jeffpar.github.io/kbarchive/kb/163/Q163801/
     Q163801: PRB: "Error Locating Config File-Bad Path?" in Visual FoxPro

     In vfp9 (and vfp6, vfp7, vfp8), it locates the config file (config.fpw) in the following folders:
     1, the compiled executable file (in VFP Runtime or VFP Multi-threaded Runtime),
     2, the application folder,
     3, the PATH environment variable to the specified folder.
     if there is no the config file (config.fpw) in the compiled executable file and the application folder,
     and there are some problems in the MS-DOS environment variable PATH,
     vfp will cause an error "Error locating config file-bad path?".

     In VFP Advanced, it locates the config file (config.fpw) in the following folders:
     1, the compiled executable file (in VFP Runtime or VFP Multi-threaded Runtime),
     2, the application folder,
     3, the PATH environment variable to the specified folder.
     if there is no the config file (config.fpw) in the compiled executable file and the application folder,
     and there are some problems in the MS-DOS environment variable PATH,
     vfp will cause an error "Error locating config file--bad path in the MS-DOS environment variable PATH or the SET PATH command?".

     There are some methods to solve the problem:
     1, recommend to edit the bad path in the MS-DOS environment variable PATH or the SET PATH command,
     2, include the config file (config.fpw) in the compiled executable file,
     3, create the config file (config.fpw) in the application folder.

     In vfp9 (and vfp6, vfp7, vfp8), it locates the resource file (foxuser.dbf) in the following folders:
     1, the application folder,
     2, the PATH environment variable to the specified folder.
     if there is no the resource file (foxuser.dbf) in the application folder,
     and there are some problems in the MS-DOS environment variable PATH,
     vfp will cause an error "Program Error: Invalid path or file name.",
     and then vfp will cancel the executable file.

     In VFP Advanced, it locates the resource file (foxuser.dbf) in the following folders:
     1, the compiled executable file (in VFP Runtime or VFP Multi-threaded Runtime),
     2, the application folder,
     3, the PATH environment variable to the specified folder.
     if there is no the resource file (foxuser.dbf) in the compiled executable file and the application folder,
     and there are some problems in the MS-DOS environment variable PATH,
     vfp will cause an error "Invalid path or file name--bad path in the MS-DOS environment variable PATH or the SET PATH command?",
     and then vfp will locates the resource file (foxuser.dbf) in the rest paths,
     and then vfp will run the executable file continue.

     There are some methods to solve the problem:
     1, recommend to edit the bad path in the MS-DOS environment variable PATH or the SET PATH command,
     2, include the resource files (foxuser.dbf and foxuser.fpt) in the compiled executable file,
     3, create the resource files (foxuser.dbf and foxuser.fpt) in the application folder.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix100.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix103.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix287.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix354.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix355.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix356.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix357.asp

     2, foxite.com:
     https://www.foxite.com/archives/invalid-path-when-starting-my-vfp-app-0000462246.htm


6. OTHER:

     For reference only, there is no guarantees.

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