1
2 program Project1;
3
4 uses
5 Forms,
6 Classes,
7 SysUtils,
8 Dialogs,
9 ImageHlp, // routines to access debug information
10 Windows;
11
12 // by Dmitry Streblechenko
13 procedure ListDLLFunctions(DLLName: string; List: TStrings);
14 type
15 chararr = array [0..$FFFFFF] of Char;
16 var
17 H: THandle;
18 I,
19 fc: integer;
20 st: string;
21 arr: Pointer;
22 ImageDebugInformation: PImageDebugInformation;
23 begin
24 List.Clear;
25 DLLName := ExpandFileName(DLLName);
26 if FileExists(DLLName) then
27 begin
28 H := CreateFile(PChar(DLLName), GENERIC_READ, FILE_SHARE_READ or
29 FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
30 if H<>INVALID_HANDLE_VALUE then
31 try
32 ImageDebugInformation := MapDebugInformation(H, PChar(DLLName), nil, 0);
33 if ImageDebugInformation<>nil then
34 try
35 arr := ImageDebugInformation^.ExportedNames;
36 fc := 0;
37 for I := 0 to ImageDebugInformation^.ExportedNamesSize - 1 do
38 if chararr(arr^)[I]=#0 then
39 begin
40 st := PChar(@chararr(arr^)[fc]);
41 if Length(st)>0 then
42 List.Add(st);
43 if (I>0) and (chararr(arr^)[I-1]=#0) then
44 Break;
45 fc := I + 1
46 end
47 finally
48 UnmapDebugInformation(ImageDebugInformation)
49 end
50 finally
51 CloseHandle(H)
52 end
53 end
54 end;
55
56 // the following is an example how to use the procedure
57 var
58 List: TStrings;
59 I: integer;
60 S: string;
61
62 begin
63 List := TStringList.Create;
64
65 ListDLLFunctions('c:\winnt\system32\mfc42.dll', List);
66
67 S := 'List of functions';
68 for I := 0 to List.Count - 1 do
69 S := S + #13#10 + List[I];
70 ShowMessage(S);
71 List.Free
72 end.
|