Mega Code Archive

 
Categories / Delphi / System
 

Make Application.ExeName work in DLLs

Title: Make Application.ExeName work in DLLs Question: When you work with DLL you will discover that Application.ExeName will not return the DLL filename, but the filename of the application that loaded your library. That's a problem in some cases. You can use the GetModuleFileName to achieve this problem. Answer: In Forms.pas, at line 6856 you'll find: function TApplication.GetExeName: string; begin Result := ParamStr(0); end; for DLLs you can use this: function GetRealExeName: string; var ExeName:array[0..MAX_PATH] of char; begin fillchar(ExeName,SizeOf(ExeName),#0); GetModuleFileName(HInstance,ExeName,MAX_PATH); Result:=ExeName; end; now, this will return also DLL file names.