Windows exe 文件可以访问调用它的命令字符串,包括其路径和文件名。例如。 C:\MyApp\MyApp.exe --help.

但对于通过以下方式调用的 dll 来说并非如此 LoadLibrary. 。有谁知道 dll 找出其路径和文件名的方法吗?

具体来说,我对 Delphi 解决方案感兴趣,但我怀疑对于任何语言来说答案都几乎相同。

有帮助吗?

解决方案

我认为您正在寻找 GetModuleFileName。

http://www.swissdelphicenter.ch/torry/showcode.php?id=143:

{
  If you are working on a DLL and are interested in the filename of the
  DLL rather than the filename of the application, then you can use this function:
}

function GetModuleName: string;
var
  szFileName: array[0..MAX_PATH] of Char;
begin
  FillChar(szFileName, SizeOf(szFileName), #0);
  GetModuleFileName(hInstance, szFileName, MAX_PATH);
  Result := szFileName;
end;

虽然未经测试,自从我使用 Delphi 以来已经有一段时间了:)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top