Mirror

Get "executable" file name also from a DLL (Views: 101)


Problem/Question/Abstract:

If you still use ParamStr(0), or Application.ExeName for getting your executable path and file name, you could have problems developing DLLs. In fact if your DLL enquires ParamStr(0) it gets the path and file name of the executable which loaded your DLL.

Answer:

Using Application.ExeName is the same as using ParamStr(0), but there's a way to fix this and have the correct file name in every case.

Just 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;

<< Back to main page