如何使用GetProcessImageFileName?

How to use GetProcessImageFileName?

我正在尝试使用 GetProcessImageFileName,但出现以下错误:

Undeclared identifier: 'GetProcessImageFileName'

我试过在 uses 子句中添加 PsAPITlHelp32 但没有解决问题。

我不确定 RTL 是否在任何地方提供了这个函数,但你总是可以导入它:

function GetProcessImageFileName(hProcess: THandle; 
                                 lpImageFileName: LPTSTR;
                                 nSize: DWORD): DWORD; stdcall;
                                 external 'PSAPI.dll' 
                                 name 'GetProcessImageFileNameA';

上面导入了 ANSI 版本(Delphi 2007)。或者,如果支持更高版本的 delphi(使用 unicode 字符串),您将有条件地导入 GetProcessImageFileNameW.