(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI PathFindOnPath Function
Searches the provided, alternative and "standard" (e.g. System32) paths for a file with the specified name.
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
function PathFindOnPath(pszPath : LPCSTR; ppszOtherDirs : POINTER) : BOOL;
pszPath [in/out] A pointer to a buffer with a maximum length of MAX_PATH (= 260) single or double byte characters, provided and initialized with the file name to search for by the caller. If the function succeeds this buffer contains the fully qualified path of the found file when the function returns.
ppszOtherDirs [in] A pointer to an array of null terminated folder paths, to search prior to the "standard" paths and the paths listed in the PATH environment variable.
Return Values
If a file with the specified file name and extension is found in any of the searched folders the function returns TRUE (= 1), if not, FALSE (= 0).
PROCEDURE TForm4.TestShlWAPIPathFindOnPath(Sender : TObject);

VAR filetofindbuf : ARRAY[0 .. MAX_PATH] OF CHAR;
VAR otherdirs : STRING;
//VAR otherdirsarray : ARRAY[0 .. 2] OF PChar;
VAR otherdirsarray : ARRAY[0 .. 1] OF PChar;
VAR otherdirsarrayp : POINTER;
VAR apiretval : BOOL;
VAR newinfoline : STRING;

FillChar(filetofindbuf, Length(filetofindbuf), #0);
otherdirs := '';
otherdirsarray[0] := NIL;
otherdirsarray[1] := NIL;
//otherdirsarray[2] := NIL;
otherdirsarrayp := NIL;
apiretval := FALSE;
newinfoline := '';

filetofindbuf := 'Notepad.exe';
otherdirs := '';
newinfoline := filetofindbuf;
newinfoline := 'PathFindOnPath called with ' + filetofindbuf;
//apiretval := PathFindOnPath(filetofindbuf, PChar(otherdirs));
apiretval := PathFindOnPath(filetofindbuf, NIL);
IF apiretval THEN
newinfoline := 'TRUE ' + filetofindbuf
newinfoline := 'FALSE';

filetofindbuf := 'Orca.exe';
//otherdirs := 'C:\Program Files\Common Files;C:\Program Files\Orca';
otherdirsarray[0] := 'C:\Program Files\Common Files';
otherdirsarray[1] := 'C:\Program Files\Orca';
//otherdirsarray[2] := NIL;
otherdirsarrayp := @otherdirsarray;

newinfoline := filetofindbuf;
newinfoline := 'PathFindOnPath called with ' + filetofindbuf;
newinfoline := newinfoline + ' ' + otherdirsarray[0];
newinfoline := newinfoline + ' ' + otherdirsarray[1];
apiretval := PathFindOnPath(filetofindbuf, PChar(otherdirsarrayp));
IF apiretval THEN
newinfoline := 'TRUE ' + filetofindbuf
newinfoline := 'FALSE';

Provided Orca is installed under C:\Program Files\Orca\ on your (NT) system, the above example ought to produce the following output:
PathFindOnPath called with Notepad.exe
TRUE C:\Windows\system32\Notepad.exe
PathFindOnPath called with Orca.exe C:\Program Files\Common Files C:\Program Files\Orca
TRUE C:\Program Files\Orca\Orca.exe
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Implemented as ANSI (PathFindOnPath and PathFindOnPathA) and Unicode (PathFindOnPathW) functions.
Min. ShlWAPI.dll version according to MS SDK doc.: 4.71
Min. ShlWAPI.dll version based on SST research: 4.71
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98, Windows 2000 and later
See Also
PathFileExists, PathIsDirectory, PathIsSystemFolder.
Windows APIs: PathFindOnPath, PathIsDirectory, PathIsSystemFolder.

Document/Contents version 1.00
Page/URI last updated on 07.12.2023
Copyright © Stoelzel Software Technologie (SST) 2010 - 2017
Suggestions and comments mail to: