Delphi get DLL List of functions

Source: Internet
Author: User

Find a few, and finally found a useful

function Getdllfileexports (

Szfilename:pchar;
Mstrings:tstrings
): Boolean;
Var
Hfile:thandle;
Hfilemapping:thandle;
Lpfilebase:pointer;
Pimg_dos_header:pimagedosheader;
Pimg_nt_header:pimagentheaders;
Pimg_export_dir:pimageexportdirectory;
Ppdwnames: ^pdword;
Szfunc:pchar;
I:integer;
Begin
Result: = False;
If not Assigned (mstrings) then Exit;
hfile: = CreateFile (szFileName, Generic_read, File_share_read, Nil,
open_existing, File_attribute_normal, 0);
if (hfile = invalid_handle_value) then Exit;
Hfilemapping: = createfilemapping (hfile, Nil, page_readonly, 0, 0, nil);
If hfilemapping = 0 Then
Begin
CloseHandle (hfile);
Exit;
End

Lpfilebase: = MapViewOfFile (hfilemapping, file_map_read, 0, 0, 0);
If lpfilebase = Nil Then
Begin
CloseHandle (hfilemapping);
CloseHandle (hfile);
Exit;
End

Pimg_dos_header: = Pimagedosheader (lpfilebase);
Pimg_nt_header: = Pimagentheaders (
Integer (pimg_dos_header) + integer (pimg_dos_header._lfanew));

If IsBadReadPtr (Pimg_nt_header, SizeOf (image_nt_headers)) or
(pimg_nt_header.signature <> image_nt_signature) Then
Begin
UnmapViewOfFile (lpfilebase);
CloseHandle (hfilemapping);
CloseHandle (hfile);
Exit;
End

Pimg_export_dir: = Pimageexportdirectory (
Pimg_nt_header.optionalheader.datadirectory[image_directory_entry_export].
virtualaddress);
If not Assigned (Pimg_export_dir) Then
Begin
UnmapViewOfFile (lpfilebase);
CloseHandle (hfilemapping);
CloseHandle (hfile);
Exit;
End
6E 2E 6F 6D
Pimg_export_dir: = Pimageexportdirectory (
Imagervatova (Pimg_nt_header, Pimg_dos_header, DWORD (Pimg_export_dir),
Pimagesectionheader (Pointer (nil) ^)));

Ppdwnames: = Pointer (Pimg_export_dir.addressofnames);

Ppdwnames: = Pointer (Imagervatova (Pimg_nt_header, Pimg_dos_header,
DWORD (Ppdwnames), Pimagesectionheader (Pointer (nil) ^)));
If not Assigned (ppdwnames) Then
Begin
UnmapViewOfFile (lpfilebase);
CloseHandle (hfilemapping);
CloseHandle (hfile);
Exit;
End

For I: = 0 to Pimg_export_dir.numberofnames-1 do
Begin
Szfunc: = PChar (Imagervatova (Pimg_nt_header, Pimg_dos_header,
DWORD (ppdwnames^), Pimagesectionheader (Pointer (nil) ^)));
Mstrings.add (Szfunc);
INC (Ppdwnames);
End
UnmapViewOfFile (lpfilebase);
CloseHandle (hfilemapping);
CloseHandle (hfile);
Result: = True;

End

Invoke Example

Procedure Tf_main.btntestclick (Sender:tobject);
Begin
Getdllfileexports (' f:\ disc burning \reclib\librtmp.dll ', memo1.lines);
End

http://blog.csdn.net/youthon/article/details/7666727

Delphi get DLL List of functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.