Delphi 如何从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.

相关阅读 >>

Delphi xe8中的正则表达式提取日语(平假名,片假名,汉字)

Delphi 解析Delphi中的loadlibrary,getprocaddress,freelibrary

Delphi 控制滚动条

Delphi access数据库密码的mdb的访问报错“无法启动应用程序,或是已被其他用户已独占方式打开”

Delphi把id字段中的最大值赋给edit1.text

Delphi 用 superobject 解析淘宝上的 json 数据

Delphi运行时拖拉、改变元件大小

Delphi判断sql server 服务是否断开

Delphi得到cpu的序列号

Delphi unidac 连接mdb access 数据库

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...