RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.GetModuleName Function

Returns the fully qualified name for a module, given its handle.

Pascal
function GetModuleName(Module: HMODULE): string;
C++
AnsiString GetModuleName(HMODULE Module);

Call GetModuleName to obtain the fully qualified name of a module, given its handle. 

Module is the handle of the module whose file name is required.

Warning: :On Linux, GetModuleName is not always successful. Depending on the way the application is called, the presence of the /proc file system, and other factors, there are times when GetModuleName may return a name that is not fully qualified or in some cases, no file name at all. Be sure to check the results of this function before using the returned value.
 

C++ Examples: 

 

/*
This example requires a button and a label.  When the user clicks
the button, the GetModuleName function retieves the path and name
of the project executable using the file handle HInstance.
*/
AnsiString __fastcall GetUsersFileName(void)
{
  return GetModuleName(unsigned(HInstance));
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Label1->Caption = GetUsersFileName();
}

 

Delphi Examples: 

{
This example requires a button and a label.  When the user clicks
the button, the GetModuleName function retieves the path and name
of the project executable using the file handle HInstance.
}
function GetUsersFileName: string;
begin
  Result := SysUtils.GetModuleName(HInstance);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := GetUsersFileName;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!