VB.NET调用c++ dll中回调函数参数问题?急

zhouqi724 2013-03-19 11:46:25
碰到一个回调函数中参数类型的问题:
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
...全文
107 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouqi724 2013-03-20
  • 打赏
  • 举报
回复
自己解决了,结贴了

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧