2008-08-05 31 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 - 已經從D7,我想。 – 2009-06-22 05:38:28

相關問題