【发布时间】:2014-10-01 15:57:04
【问题描述】:
Calling a callback function in Delphi from a C++ DLL
我遇到了类似的错误,但是我的 C++ 声明有点不同。
typedef int __stdcall CALLBACK(void* pP1, int I1, unsigned char* pUC,
int I2, int I3, int I4, void* pP2);
我转换成的:
type TCALLBACK = function(var pP1: Pointer; var I1: integer;
var pUC: PChar; var I2: Integer; var I3: Integer; var I4: Integer;
var pP2: Pointer): Integer cdecl stdcall;
函数引用回调函数:
int MyFunction(void* pP1, TCALLBACK* pCallback, void* pP2);
我转换成的:
MyFunction: function(pP1: Pointer; var pCallBack: Pointer;
pP2: Pointer): Integer cdecl stdcall;
调用函数:
var P : Pointer;
begin
//Addr
P := Addr(PCALLBACK); //had this as @PCALLBACK
UFS_StartCapturing(ScannerHandle, P, self);
end;
Delphi 中声明的回调函数为:
function MyCallback(var pP1: Pointer; var I1: integer; var pUC: PChar;
var I2: Integer; var I3: Integer; var I4: Integer;
var pP2: Pointer): Integer;
var
MainForm : TfrmMain;
begin
//Do your thing
end;
我知道我的问题在于指向回调 (CALLBACK*) 的指针,现在正在尝试:
ADRESSOFCALLBACK= ^TCALLBACK;
MyFunction: function(pP1: Pointer; var pCallBack: ADRESSOFCALLBACK;
pP2: Pointer): Integer cdecl stdcall;
还是不行。
【问题讨论】: