Delphi中专用的回调函数是of Object ,如果在C++的库函数中需要使用到回调函数,则不能使用of Object 方式的回调函数,而是应该使用stdcall方式的回调函数,并且该函数不能是类的实现方法,必须是单独的一个函数,这一点跟of Object的回调函数有较大差别。下面举个例子
type
Csample = function(plen : Integer):Integer;stdcall;
function Csonsample( sample : Csample):Integer;stdcall;external 'Captest.dll' name 'sampleFun'; Csonsample是库函数sampleFun的别名,该函数的参数是一个回调函数指针;
下面定义一个回调函数
function theCapData(pLen : Integer):Integer;stdcall;
begin
//************** valid check ***************************
Result := 0;
end;
在Delphi中调用库函数并传入回调函数指针
Csonsample(theCapData);