Windows DLL可以检索自己的文件名吗?
问题描述:
Windows EXE文件可以访问调用它的命令字符串,包括其路径和文件名。例如。 C:\MyApp\MyApp.exe --help
。Windows DLL可以检索自己的文件名吗?
但是,这不是通过LoadLibrary
调用的dll。有谁知道一个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;
未经检验虽然已有一段时间,因为我与德尔福合作:)
SysUtils单元有GetModuleName - 已经从D7,我想。 – 2009-06-22 05:38:28