在Delphi中调用VC动态库,回调函数如何定义
一个VC的dll,需要在delphi调用,其中有个回调函数的参数,不知道该怎么写,请大家帮忙看看
先看VC的声明
1、回调函数
typedef long (__stdcall *VOX_CVSA_CALLBACK_OnReportSwitchVideoResult)(int nMonNo,int nCamNo,long nResult,
const char *errInfo, long lParam);
typedef long (__stdcall *VOX_CVSA_CALLBACK_OnReportVideoMapping)(int nMonNo,int nCamNo, long lParam);
2、回调函数结构体
struct CVSA_NOTIFY{
VOX_CVSA_CALLBACK_OnReportSwitchVideoResult OnReportSwitchVideoResult;
long lOnReportSwitchVideoResultParam;
VOX_CVSA_CALLBACK_OnReportVideoMapping OnReportVideoMapping;
long lOnReportVideoMappingParam;
};
3、动态库函数
CLIENT_VIDEO_SERV_API long __stdcall VOX_CVSA_SetNotify(long hInstance, struct CVSA_NOTIFY *pNotify);
下面是根据上面的部分改的Delphi代码
1、回调函数
VOX_CVSA_CALLBACK_OnReportSwitchVideoResult =
Function (nMonNo: Integer; nCamNo: Integer; nResult: Integer; errInfo: PChar; lParam: Integer): Integer;
VOX_CVSA_CALLBACK_OnReportVideoMapping =
Function (nMonNo : Integer; nCamNo: Integer; lParam: Integer): Integer;
2、回调函数结构体
PCVSA_NOTIFY = ^TCVSA_NOTIFY;
TCVSA_NOTIFY = Record
OnReportSwitchVideoResult: VOX_CVSA_CALLBACK_OnReportSwitchVideoResult;
lOnReportSwitchVideoResultParam: Integer;
OnReportVideoMapping: VOX_CVSA_CALLBACK_OnReportVideoMapping;
lOnReportVideoMappingParam: Integer;
end;
3、动态库函数
Function VOX_CVSA_SetNotify(hInstance: Integer; pNotify: PCVSA_NOTIFY): Integer; stdcall; external 'VoxCVSA_SDK.dll' ;
-----------------------------------------------------------------------------------------------------------------------
我的实现如下:
1、先声明一个测试类
TVoxImpl = class
private
FCVSA_NOTIFY : PCVSA_NOTIFY ;
Function VideoResult(nMonNo: Integer; nCamNo: Integer; nResult: Integer; errInfo: PChar; lParam: Integer): Integer;
Function VideoMapping(nMonNo : Integer; nCamNo: Integer; lParam: Integer): Integer;
public
Constructor Create;
end;
2、在Create中注册回调函数
Procedrue TVoxImpl.Create()
begin
New(FCVSA_NOTIFY);
FCVSA_NOTIFY^.lOnReportSwitchVideoResultParam := 0;
FCVSA_NOTIFY^.lOnReportVideoMappingParam := 0;
****** 编译到下面这就提示错误了,[Incompatible types: regular procedure and method pointer]*******************
FCVSA_NOTIFY^.OnReportSwitchVideoResult := VideoResult;
FCVSA_NOTIFY^.OnReportVideoMapping := VideoMapping;
end;
请帮忙看看,这个回调函数到底该怎么弄啊!