”地址” VB6 到 VB.NET
我在将 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, pPacketBuffer, nPacketSize
End Sub
nn1 = MP4_ClientStart(clientinfo, AddressOf ReadDataCallBack)
I´m having some problem to convert my VB6 project to VB.NET
I don't understand how this "AddressOf" function should be in VB.NET
My VB6 code:
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, pPacketBuffer, nPacketSize
End Sub
nn1 = MP4_ClientStart(clientinfo, AddressOf ReadDataCallBack)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能会看到此错误:
您可能想要做的是创建一个委托,然后将 adab 的类型更改为该委托类型。将其添加到类中:
然后将您的 P/Invoke 声明更改为:
不要删除/更改您的 ReadDataCallBack Sub,您仍然需要它。
那时他的编译器应该很高兴。然而,其他人提出的观点很重要。 VB6 中整数和长整型的长度与 VB.NET 中不同。因此,在 .NET 中,只要在 VB6 中使用 Long,就需要使用 Integer。
You are probably seeing this error:
What you probably want to do is create a delegate then change the type of adab to that delegate type. Add this to the class:
Then change your P/Invoke declaration to:
Do not delete/change your ReadDataCallBack Sub, you still need that.
At that point he compiler should be happy. However, the point made by others is important. The length of Integers and Longs is different in VB6 than in VB.NET. So in .NET you need to use Integer anytime you used a Long in VB6.
关于非托管代码中的回调,请参阅类似的帖子是否对您有帮助。
关于您的问题 - 我认为您不需要回调函数或者您发布的示例不正确/不完整 - 请参阅上面指出的帖子并澄清您的代码示例。
Regarding callbacks in unmanaged code see if this similar post helps you.
Regarding your question - I don't think you need callback functions or the example you posted is not correct/complet - see the post indicated above and clarify your code sample.
我假设 MP4_ClientStart 的第二个参数应该是回调函数的地址。问题可能在于您在这里将其定义为 Long,在 VB6 中是 32 位值,但在 VB.NET 中是 64 位值。将声明更改为以下内容可能会取得一些成功:
I assume that the second parameter to MP4_ClientStart is supposed to be the address of a callback function. Likely the problem is that you've defined it here as a Long, which in VB6 is a 32-bit value, but in VB.NET is a 64-bit value. You'll probably have some success by changing your declaration to:
下面是 VB.NET 的实现:
Here is the VB.NET implementation: