Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 1.6 KB

sample_138.md

File metadata and controls

53 lines (37 loc) · 1.6 KB

Home

How to find the application associated with a file name

Before you begin:

See also:


Code:

DECLARE INTEGER FindExecutable IN shell32;
	STRING lpFile, STRING lpDir, STRING @lpResult

lcResult = SPACE(250)

IF FindExecutable ("c:\MyDocuments\daily.doc", "", @lcResult) > 32
	lcResult = ALLTRIM(STRTRAN(lcResult, Chr(0), " "))
	? lcResult
ELSE
	*    2 = ERROR_FILE_NOT_FOUND
	*    3 = ERROR_PATH_NOT_FOUND
	*   21 = ERROR_NOT_READY
	*  123 = ERROR_INVALID_NAME
	*  127 = ERROR_PROC_NOT_FOUND
	* 1008 = ERROR_NO_TOKEN

	DECLARE INTEGER GetLastError IN kernel32
	? "Error code:", GetLastError()
ENDIF  

Listed functions:

FindExecutable
GetLastError

Comment:

Normally this code returns a path to the Microsoft Word, or to any application associated with DOC files.

Note that the source file -- in the sample code "c:\MyDocuments\daily.doc" -- must exists, even if a dummy file of zero size.

Unlike the FindExecutable, another API function the AssocQueryString retrieves file associations without relying on names of physical files.