小编fin*_*jom的帖子

Delphi DLL和Delphi EXE之间的回调功能

我正在写一个Delphi DLL.在Delphi DLL中我想实现一个回调函数,这个回调函数应该调用回调用Delphi程序.回调函数的主要目的是在DLL中发生某些长操作,但是在调用者Delphi程序中应该进行进度报告(通过进度条)和操作取消.

我想得到一些支持如何正确实现DLL中的回调函数.我可以继续,直到分配从EXE传递的回调函数,但我知道如何从DLL本身启动调用.

这是定义部分(由EXE和DLL使用):

uses Windows;

Type
  PTCallBackStruct = ^TCallBackStruct;
  TCallBackStruct = packed record
  Handle: THandle;
  Caller: Pointer;           
  FileSize: LongInt;
end;

type

 TFunctionPointerType = function(ZCallbackRec: PTCallBackStruct): Longbool;
  stdcall;

type
  PTDLLParamaters = ^TDLLParamaters;
  TDLLParamaters = packed record
   Handle: THandle;
   Caller: Pointer; 
   CallbackFunction: TFunctionPointerType;
 end;

 var
   DLLCallback: TFunctionPointerType;
Run Code Online (Sandbox Code Playgroud)

EXE文件:

 uses ....    

 type

  function DLL_Callback(ZCallBackRec: PTCallBackStruct): LongBool; stdcall;
    forward;

  implementation

   function DLL_Callback(ZCallBackRec: PTCallBackStruct): LongBool; stdcall;
   begin
      // progress reporting this function should be called back from 
      //the DLL. The Handle and Self …
Run Code Online (Sandbox Code Playgroud)

delphi dll callback

5
推荐指数
1
解决办法
3316
查看次数

标签 统计

callback ×1

delphi ×1

dll ×1