DelphiFAQ Home Search:

Retrieve list of exported functions from a DLL

 

comments7 comments. Current rating: 2 stars (4 votes). Leave comments and/ or rate it.

To retrieve the list of exported functions from a DLL, pass the DLL name and a TStrings object to the function ListDLLFunctions() shown below.

This does not show the parameters for each export, which you can only get from the author of the DLL.

program Project1;

uses
  Forms,
  Classes,
  SysUtils,
  Dialogs,
  ImageHlp, // routines to access debug information
  Windows;

// by Dmitry Streblechenko
procedure ListDLLFunctions(DLLName: String; List: TStrings);
type
  chararr = array [0..$FFFFFF] of Char;
  var
  H: THandle;
  I,
  fc: integer;
  st: string;
  arr: Pointer;
  ImageDebugInformation: PImageDebugInformation;
begin
  List.Clear;
  DLLName := ExpandFileName(DLLName);
  if FileExists(DLLName) then
  begin
    H := CreateFile(PChar(DLLName), GENERIC_READ, FILE_SHARE_READ or
      FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    if H<>INVALID_HANDLE_VALUE then
      try
        ImageDebugInformation := MapDebugInformation(H, PChar(DLLName), nil, 0);
        if ImageDebugInformation<>nil then
          try
            arr := ImageDebugInformation^.ExportedNames;
            fc := 0;
            for I := 0 to ImageDebugInformation^.ExportedNamesSize - 1 do
              if chararr(arr^)[I]=#0 then
              begin
                st := PChar(@chararr(arr^)[fc]);
                if Length(st)>0 then
                  List.Add(st);
                if (I>0) and (chararr(arr^)[I-1]=#0) then
                  Break;
                fc := I + 1
              end
          finally
            UnmapDebugInformation(ImageDebugInformation)
          end
      finally
        CloseHandle(H)
      end
  end
end;

// the following is an example how to use the procedure
var
  List: TStrings;
  I: integer;
  S: String;

begin
  List := TStringList.Create;

  ListDLLFunctions('c:\winnt\system32\mfc42.dll', List);

  S := 'List of functions';
  for I := 0 to List.Count - 1 do
    S := S + #13#10 + List[I];
  ShowMessage(S);
  List.Free
end.

Comments:

2006-01-18, 11:46:28
anonymous from Sweden  
Unfortnatly It doesn't work...... The result shows 'List of Functions' but nothing else...
2006-02-08, 10:02:51
anonymous from United States  
rating
To see why this doesn't work, and to get code that does, search for this in Google Groups:
'peter below' 'How to extract exported function names from .DLL'

- Ron Schuster
2007-01-08, 15:36:36
anonymous from Italy  
thanks
2007-03-21, 00:47:01
akunyer@gmail.com from Malaysia  
Not working....actually what is the problem . Just appear 'List of functions'
2008-02-21, 12:10:04
anonymous from Germany  
rating
This code isn't working with XP (anymore?)

regards
2008-03-23, 23:36:51
Abhijeet from India  
rating
Hi,
Used this code and created sample applicaiton. This code doesnot return any funciton names from a DLL.

The statement 'arr := ImageDebugInformation^.ExportedNames;' returns nil, so can not see the exported functions from DLL.
2008-03-23, 23:36:55
Abhijeet from India  
rating
Hi,
Used this code and created sample applicaiton. This code doesnot return any funciton names from a DLL.

The statement 'arr := ImageDebugInformation^.ExportedNames;' returns nil, so can not see the exported functions from DLL.

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: