Skip to content

Latest commit

 

History

History
55 lines (38 loc) · 1.54 KB

sample_138.md

File metadata and controls

55 lines (38 loc) · 1.54 KB

Home

如何查找与文件名关联的应用程序

翻译:xinjie 2022.01.30

开始之前:

参看:


代码:

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  

函数列表:

FindExecutable
GetLastError

备注:

通常,此代码返回 Microsoft Word 或与 DOC 文件关联的任何应用程序的路径。

请注意,源文件——在示例代码“c:\MyDocuments\daily.doc”中——必须存在,即使是零大小的虚拟文件。

与 FindExecutable 不同,另一个 API 函数 AssocQueryString 检索文件关联,而不依赖于物理文件的名称。