Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving DLL method names and parameters programmatically

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
I have a C++ DLL I want to use in a Delphi app. I do not know the methods contained in the DLL and wondered if there's an effective programmatic way of obtaining what methods the DLL exports and perhaps what parameters are need in the method calls. I found a bit of code online that promised to do what I'm requesting (minus the parameter list) but it doesn't return any method names. I know I can use TDump.exe but I would like a programmatic method is possible, anyone got any ideas?

The code I couldn't get to work can be found at this link:
Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Hi ,
this is the same function but it worked for me

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,ImageHlp;

procedure TForm1.Button1Click(Sender: TObject);
var
List: TStrings;
I: integer;
S: String;
begin
List := TStringList.Create;
ListDLLFunctions('c:\Soy32.dll', List);
S := 'List of functions';
for I := 0 to List.Count - 1 do
S := S + #13#10 + List;
ShowMessage(S);

List.Free
end;


procedure Tform1.ListDLLFunctions(DLLName: string; List: TStrings);
// by Dmitry Streblechenko
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^) = #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;
 
Did someone forget to turn off TGML proccessing? (Mentioning no names of course)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top