Page 1 of 1
FindExecutable
Posted: Tue Dec 07, 2010 10:42 am
by dige
Code: Select all
Procedure.s FindExecutable (File.s); Retrieves the name to the executable (.exe) file associated with a specific document file
Protected libid.i, FuncId.i, *mem, Result.s
; http://msdn.microsoft.com/en-us/library/bb776419%28VS.85%29.aspx
libid = OpenLibrary(#PB_Any, "shell32.dll" )
If libid
FuncId = GetFunction(libid, "FindExecutableA" )
If FuncId
*mem = AllocateMemory(#MAX_PATH)
If *mem
If CallFunctionFast(FuncId, @File, #Null, *mem ) > 32
Result = PeekS(*mem, #PB_Any, #PB_Ascii)
EndIf
FreeMemory(*mem)
EndIf
EndIf
CloseLibrary(libid)
EndIf
ProcedureReturn Result
EndProcedure
Debug "C:\Temp\Document.pdf"
Re: FindExecutable
Posted: Tue Dec 07, 2010 10:46 am
by Joakim Christiansen
That's a handy one!
Re: FindExecutable
Posted: Tue Dec 07, 2010 11:14 am
by Rings
whats wrong with that one:
Code: Select all
Result.s=Space(#MAX_PATH)
r=FindExecutable_(@File.s,@Path.s,@Result.s)
Re: FindExecutable
Posted: Tue Dec 07, 2010 1:41 pm
by dige
I prefer to have more control over api calls. Its also more safe for
use with different windows versions... or for futur usage against
deprecated functions...
Re: FindExecutable
Posted: Tue Dec 07, 2010 1:55 pm
by cas
I agree with Rings. Except if you are coding your app for older windows version than XP (which doesn't have this function available), there is no point of doing it manually.
MSDN wrote:Returns a value greater than 32 if successful, or a value less than or equal to 32 representing an error.
Shouldn't then instead of
Code: Select all
If CallFunctionFast(FuncId, @File, #Null, *mem ) >= 32
be this:
Code: Select all
If CallFunctionFast(FuncId, @File, #Null, *mem ) > 32
?
Re: FindExecutable
Posted: Wed Dec 08, 2010 9:47 am
by dige
@CAS: you're right! I've fixed the code above.
cas wrote:I agree with Rings. Except if you are coding your app for older windows version than XP (which doesn't have this function available), there is no point of doing it manually.
If you're goin to distribut programs, you'll wonder what Windows versions still in use...