VB.NET调用c++ dll中回调函数参数问题?急
碰到一个回调函数中参数类型的问题:
dll头文件中定义的函数原型:
// 设备句柄
typedef unsigned int DEVICE_HANDLE;
//回调函数原型
typedef void (STDCALL* CALLBACK_FUNC)
(DEVICE_HANDLE dev_handle, // 设备句柄
int type, // 回调类型
void *param); //回调参数
type —— 回调函数类型
有效类型:
type ==1 其对应的参数类型为(idenresult_array_t* idenresult_list);
type ==2 其对应的参数类型为(unsigned int* dev_status)
type ==3 对应参数类型为(server_t* server_status)
type ==4 (enroll_result_t *enroll_result)
type ==5 其对应的参数类型为(personinfo_id_t *info_id)
idenresult_array_t
server_t
enroll_result_t
personinfo_id_t
上述四种类型均为结构体struct
//业务接口,第二个参数为回调函数
EXTERN int STDCALL init_module (ipaddress_t *listened_addr, CALLBACK_FUNC callback_func );
******************************
vb.net中实现回调函数:
========声明:
回调函数
Public Delegate Sub CALLBACK_FUNC(dev_handle As UInteger, type As Integer, param As System.IntPtr)
业务接口
Public Declare Auto Function init_module Lib "name.dll" (ByRef listened_addr As ipaddress_t, callback_func As CALLBACK_FUNC) As Integer
=========实现:
................
public function aaa()
rs = init_module(listened_addr, AddressOf method_callback)
....
end function
////实现的回调函数
Public Shared Function method_callback(dev_handle As UInteger, type As Integer, param As System.IntPtr) As Integer
//在这函数里,当type为不同值时,怎么取到param对应的结构体对象实例。如上述写的uint或结构体类型???不知道怎么获取param在不同type下的结构体对象,VB.NET新手。
End Function