delphi - Windows dllは独自のファイル名を取得できますか?

original title: "delphi - Can a Windows dll retrieve its own filename?"


Translate

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

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?

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



Windows exeファイルは、パスとファイル名を含む、それを呼び出したコマンド文字列にアクセスできます。例えば。 C:\ MyApp \ MyApp.exe --help。しかし、これはLoadLibraryを介して呼び出されたdllには当てはまりません。する...

これは翻訳後の要約です。完全な翻訳を表示する必要がある場合は、「翻訳」アイコンをクリックしてください。


すべての答え
  • Translate

    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;
    

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