2008-08-05 18 views
25

Windowsのexeファイルは、パスとファイル名を含めて、起動したコマンド文字列にアクセスできます。例えば。 C:\MyApp\MyApp.exe --helpWindows dllが独自のファイル名を取得できますか?

しかし、これはLoadLibraryによって呼び出されるdllではそうではありません。誰かがdllがそのパスとファイル名が何であるかを知る方法を知っていますか?

具体的には私はDelphiソリューションに興味がありますが、その答えはどの言語でもほとんど同じであると思われます。

答えて

35

私はあなたが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; 

未テスト

+5

sysutilsのははgetModuleNameを持っているけれども、私はDelphiで働いていたので、いくつかの時間がかかった:) - すでにD7以来、私は思います。 –

+2

Delphi XEの場合、 'GetModuleName'は* System.pas *ユニットに定義されています – menjaraz

+1

Delphi 6では、' MAX'の定義に 'uses'節で' Windows'が必要です。 – w5m

関連する問題