Article ID: 197192
Article Last Modified on 7/1/2004
* FindExec.prg
*
* This example demonstrates Visual FoxPro and FPW2.6 code to find the
* location of Word for Windows based on a file association.
*
* A file with the specific association must already exist for
* FindExecutable to work correctly. Therefore, the sample creates
* a fictitious file with a .DOC extension.
*
* If an association is not present, FindExecutable will
* return an empty string.
* Modify this string to SAMPLE.XLS to find the path to Excel.
lcSampleDoc = "SAMPLE.DOC"
lihandle = FCREATE(lcSampleDoc)
=FCLOSE(lihandle)
lpFile = lcSampleDoc
lpDirectory = ''
lpResults = SPACE(128)
* Any VFP version.
IF ("VISUAL FOXPRO" $ UPPER(VERSION()))
DECLARE INTEGER FindExecutable IN SHELL32 ;
STRING@lpFile, STRING@lpDirectory, ;
STRING @lpResults
liReturnValue = FindExecutable(@lpFile, @lpDirectory,@lpResults)
ELSE
* FPW 2.x version.
SET LIBRARY TO HOME() + "foxtools.fll"
lfFindExe = RegFn("FindExecutable", "@C@C@C", "I", ;
"SHELL.DLL")
liReturnValue = CallFn(lfFindExe, @lpFile, @lpDirectory, @lpResults)
ENDIF
* Interpret the return code.
DO CASE
CASE liReturnValue = 0
? "FindExecutable failed: Out of memory or resources"
CASE liReturnValue = 31
? "FindExecutable failed: No association for file type"
CASE liReturnValue = 2
? "FindExecutable failed: Specified file not found"
CASE liReturnValue = 3
? "FindExecutable failed: Specified path not found"
CASE liReturnValue = 11
? "FindExecutable failed: Invalid EXE format"
OTHERWISE
* Read out to the null terminator.
lpResults = LEFT(lpResults, AT(CHR(0), lpResults) - 1)
? "Full path of application: " + lpResults
ENDCASE
* Delete the dummy file you created.
DELETE FILE (lcSampleDoc)
140724 PRB: FindExecutable() Truncates Result at First Space in LFN
Keywords: kbhowto kbapi KB197192