tags:

views:

125

answers:

2
+3  Q: 

Get BPL File Name

From within a BPL, is it possible to get its own file name? e.g. C:\foo\bar.bpl

(dynamically loaded and delphi7, if it matters)

+7  A: 

Call GetModuleFileName. For the module handle, use SysInit.HInstance. Passing zero will give you the host EXE's file name instead, also known as ParamStr(0).

Rob Kennedy
Thankyou, works as expected :)
Christopher Chase
A: 

Example use of GetModuleFileName:

function  DLLFileName : string;
begin
  SetLength(Result,MAX_PATH);
  GetModuleFileName(HInstance,PCHar(Result),MAX_PATH);
  SetLength(Result,StrLen(PChar(Result)));
end;
Jason Southwell
The last two lines can be folded into one, as `GetModuleFileName()` returns the number of characters copied, so the `StrLen()` isn't necessary.
mghie
It's even easier:Result := PChar(Result);
dummzeuch
@dummzeuch: Looks easier, yes. Calls the equivalent of `StrLen()` internally anyway. For those that crave the smallest and fastest code...
mghie