可以检索自己的文件名吗

可以检索自己的文件名吗

本文介绍了Windows dll 可以检索自己的文件名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

A Windows exe file has access to the command string which invoked it, including its path and filename. eg. C:\MyApp\MyApp.exe --help.

但对于通过 LoadLibrary 调用的 dll 而言并非如此.有没有人知道 dll 找出它的路径和文件名的方法?

But this is not so for a dll invoked via LoadLibrary. Does anyone know of a way for a dll to find out what its path and filename is?

特别是我对 Delphi 解决方案感兴趣,但我怀疑任何语言的答案都差不多.

Specifically I'm interested in a Delphi solution, but I suspect that the answer would be pretty much the same for any language.

推荐答案

我认为您正在寻找 GetModuleFileName.

I think you're looking for 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 以来已经有一段时间了:)

Untested though, been some time since I worked with Delphi :)

这篇关于Windows dll 可以检索自己的文件名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:39