Windows exe文件可以访问调用它的命令字符串,包括其路径和文件名。例如。 C:\MyApp\MyApp.exe --help
。
但是对于通过LoadLibrary
调用的dll来说并非如此。有没有人知道dll的方法是找出它的路径和文件名是什么?
具体来说,我对Delphi解决方案很感兴趣,但我怀疑任何语言的答案几乎都是一样的。
答案 0 :(得分:36)
我认为你正在寻找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以来已经有一段时间了:)