⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 importdllut.pas

📁 delphi 编写的在DLL中建立回调函数机制。
💻 PAS
字号:
unit ImportDllUt;

interface
uses
  Windows,SysUtils,Classes;


type
  TUtImportDll = class
  private

    { Private declarations }
  public
    function IDU_GetPluginInfo(filepath:string;var DllInfo: array of string):boolean;
    function IDU_PlugExecute(filepath,PlugType:string;var SetInfo:string):Boolean;
    function IDU_PlugCallBack(filepath,PlugType:string;var SetInfo:string):Boolean;
    procedure IDU_CallBackExcute(SetInfo:string):Boolean;
    { Public declarations }
  end;

var
  UtImportDll: TUtImportDll;

implementation


function TUtImportDll.IDU_GetPluginInfo(filepath:string;var DllInfo: array of string):boolean;
type
TGetDllInfo=function :PChar;

var
DllHandle: THandle;
PFunc: TFarProc;
getInfo:TGetDllInfo;
i:integer;

begin

     Result:=true;
     try
     DllHandle:= Loadlibrary(pchar(filepath));

     for i:=0 to 3 do
     begin

       if DllHandle > 0 then
           begin
           PFunc := GetProcAddress(DllHandle,PChar(CT_FunctionInfo[i]));


           if (PFunc<> nil) then
             begin
               getInfo:=TGetDllInfo(PFunc);
               DllInfo[i]:=getInfo;
               PFunc:=nil;
             end;
           end;
     end;

     
     except
     FreeLibrary(DllHandle);
     Result:=false;
     end;
     FreeLibrary(DllHandle);
     {try
     FreeLibrary(DllHandle);
     except
     end;}

end;

function TUtImportDll.IDU_PlugCallBack(filepath, PlugType: string;
  var SetInfo: string): Boolean;
begin

end;

function TUtImportDll.IDU_PlugExecute(filepath,PlugType:string;var SetInfo:string):Boolean;
type
 TPlugExecute=function(SetInfo:string):pchar;

var
  DllHandle: THandle;
  PFunc: TFarProc;
  PlugExecute:TPlugExecute;
  Info:PChar;
begin

  Result:=true;                      

  try
  DllHandle:= Loadlibrary(PChar(filepath));
  if DllHandle > 0 then
     begin
     PFunc := GetProcAddress(DllHandle,PChar(PlugType));
     if (PFunc <> nil) then
       begin
       PlugExecute:=TPlugExecute(PFunc);
       end;
       SetInfo:=PlugExecute(SetInfo);
     end;
  except
   FreeLibrary(DllHandle);
   Result:=false;
  end;
   FreeLibrary(DllHandle);

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -