FindExecutable function
Applies to: desktop apps only
Retrieves the name of and handle to the executable (.exe) file associated with a specific document file.
Syntax
HINSTANCE FindExecutable( __in LPCTSTR lpFile, __in_opt LPCTSTR lpDirectory, __out LPTSTR lpResult );
Parameters
- lpFile [in]
-
Type: LPCTSTR
The address of a null-terminated string that specifies a file name. This file should be a document.
- lpDirectory [in, optional]
-
Type: LPCTSTR
The address of a null-terminated string that specifies the default directory. This value can be NULL.
- lpResult [out]
-
Type: LPTSTR
The address of a buffer that receives the file name of the associated executable file. This file name is a null-terminated string that specifies the executable file started when an "open" by association is run on the file specified in the lpFile parameter. Put simply, this is the application that is launched when the document file is directly double-clicked or when Open is chosen from the file's shortcut menu. This parameter must contain a valid non-null value and is assumed to be of length MAX_PATH. Responsibility for validating the value is left to the programmer.
Return value
Type: HINSTANCE
Returns a value greater than 32 if successful, or a value less than or equal to 32 representing an error.
The following table lists possible error values.
| Return code/value | Description |
|---|---|
|
The specified file was not found. |
|
The specified path is invalid. |
|
The specified file cannot be accessed. |
|
The system is out of memory or resources. |
|
There is no association for the specified file type with an executable file. |
Remarks
Use FindExecutable for documents. If you want to retrieve the path of an executable file, use the following:
AssocQueryString(ASSOCF_OPEN_BYEXENAME,
ASSOCSTR_EXECUTABLE,
pszExecutableName,
NULL,
pszPath,
pcchOut);
Here, pszExecutableName is a pointer to a null-terminated string that specifies the name of the executable file, pszPath is a pointer to the null-terminated string buffer that receives the path to the executable file, and pcchOut is a pointer to a DWORD that specifies the number of characters in the pszPath buffer. When the function returns, pcchOut is set to the number of characters actually placed in the buffer. See AssocQueryString for more information.
When FindExecutable returns, the lpResult parameter may contain the path to the Dynamic Data Exchange (DDE) server started if a server does not respond to a request to initiate a DDE conversation with the DDE client application.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | FindExecutableW (Unicode) and FindExecutableA (ANSI) |
See also
Send comments about this topic to Microsoft
Build date: 3/7/2012
***REMOVED DUPLICATE*** { sorry guys, I deserve forgiveness for the last post ;) }
- 4/20/2012
- kthxbai2u.com
- 4/20/2012
- kthxbai2u.com
I would like to see more Delphi code posted on the windows API pages, to make it easier to understand API calls in Delphi.
I promise the WWW that I will post comments with example sources whenever I learn a new API or stumble accross one while searching Google. Without further delay, I bring to you your tip for the day!
[code]
//NOT kthxbai2u.com code. Not sure who to credit.
function getDefaultBrowser : TBrowserInformation;
var
tmp : PChar;
res : PChar;
begin
tmp := StrAlloc(255);
res := StrAlloc(255);
try
GetTempPath(255,tmp);
FileCreate(tmp+'htmpl.htm');
//THIS is an example of FindExecutable API call in Delphi. Simple. :)
FindExecutable('htmpl.htm',tmp,Res);
Result.Name := ExtractFileName(res);
Result.Path := ExtractFilePath(res);
SysUtils.DeleteFile(tmp+'htmpl.htm');
finally
StrDispose(tmp);
StrDispose(res);
end;
end;
[/code]
nJoy ;) ~kthxbai2u(.com)
- 4/20/2012
- kthxbai2u.com
http://visualstudiomagazine.com/articles/2009/10/13/finding-an-associated-executable.aspx
- 10/22/2009
- Tony Toews - Access MVP
This has been confirmed by folks over in the microsoft.public.vb.general.discussion newsgroup. Subject
FindExecutable API call fails for ACCDB file extensions
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.vb.general.discussion&tid=4556a349-dd2f-4e57-a37e-f65969c23fc3&cat=&lang=&cr=&sloc=&p=1
http://groups.google.ca/group/microsoft.public.vb.general.discussion/browse_thread/thread/109aaa1c7d6a31a7/76f9a67c39002178
Note Mike Williams statement: "There were all sorts of strange anomilies where certain file
extensions were found by FindExecutable and other file extensions were
not, with (up to now) no apparent ryhme or reason behind it. "
- 9/13/2009
- Tony Toews - Access MVP