我有一些问题要将我的VB6项目转换为VB.NET
我不明白这个“AddressOf”函数应该如何在VB.NET中使用
我的VB6代码:
Declare Function MP4_ClientStart Lib "hikclient.dll" _ (pClientinfo As CLIENT_VIDEOINFO,ByVal abab As Long) As Long Public Sub ReadDataCallBack(ByVal nPort As Long,pPacketBuffer As Byte,_ ByVal nPacketSize As Long) If Not bSaved_DVS Then bSaved_DVS = True HW_OpenStream hChannelHandle,pPacketBuffer,nPacketSize End If HW_InputData hChannelHandle,nPacketSize End Sub nn1 = MP4_ClientStart(clientinfo,AddressOf ReadDataCallBack)
您可能会看到此错误:
‘AddressOf’ expression cannot be
converted to ‘Long’ because ‘Long’ is
not a delegate type.
你可能想要做的是创建一个委托然后将adab的类型更改为该委托类型.将其添加到课程中:
Public Delegate Sub ReadDataCallBackDelegate(ByVal nPort As Long,_ ByVal pPacketBuffer As Byte,ByVal nPacketSize As Long)
然后将您的P / Invoke声明更改为:
Declare Function MP4_ClientStart Lib "hikclient.dll" (ByVal pClientinfo As _ CLIENT_VIDEOINFO,ByVal abab As ReadDataCallBackDelegate) As Long
不要删除/更改您的ReadDataCallBack Sub,您仍然需要它.
那时他编译应该很开心.但是,其他人提出的观点很重要. VB6中的整数和长整数的长度与VB.NET中的长度不同.因此在.NET中,只要在VB6中使用Long,就需要使用Integer.