”地址” VB6 到 VB.NET

发布于 2024-08-25 03:11:25 字数 598 浏览 9 评论 0原文

我在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

他是夢罘是命 2024-09-01 03:11:25

您可能会看到此错误:

“AddressOf”表达式不能是
转换为 'Long' 因为 'Long' 是
不是委托类型。

您可能想要做的是创建一个委托,然后将 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。

You are probably seeing this error:

'AddressOf' expression cannot be
converted to 'Long' because 'Long' is
not a delegate type.

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:

Public Delegate Sub ReadDataCallBackDelegate(ByVal nPort As Long, _
  ByVal pPacketBuffer As Byte, ByVal nPacketSize As Long)

Then change your P/Invoke declaration to:

Declare Function MP4_ClientStart Lib "hikclient.dll" (ByVal pClientinfo As _
  CLIENT_VIDEOINFO, ByVal abab As ReadDataCallBackDelegate) As Long

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.

浪菊怪哟 2024-09-01 03:11:25

关于非托管代码中的回调,请参阅类似的帖子是否对您有帮助。

关于您的问题 - 我认为您不需要回调函数或者您发布的示例不正确/不完整 - 请参阅上面指出的帖子并澄清您的代码示例。

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.

↘紸啶 2024-09-01 03:11:25

我假设 MP4_ClientStart 的第二个参数应该是回调函数的地址。问题可能在于您在这里将其定义为 Long,在 VB6 中是 32 位值,但在 VB.NET 中是 64 位值。将声明更改为以下内容可能会取得一些成功:

Declare Function MP4_ClientStart Lib "hikclient.dll" _
    (pClientinfo As CLIENT_VIDEOINFO, ByVal abab As Integer) As Integer

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:

Declare Function MP4_ClientStart Lib "hikclient.dll" _
    (pClientinfo As CLIENT_VIDEOINFO, ByVal abab As Integer) As Integer
夜光 2024-09-01 03:11:25

下面是 VB.NET 的实现:

Declare Function MP4_ClientStart Lib "hikclient.dll" (ByRef pClientinfo As _
  CLIENT_VIDEOINFO, ByVal abab As ReadDataCallBackDelegate) As Integer

Public Delegate Sub ReadDataCallBackDelegate(ByVal nPort As Long, _
  ByRef pPacketBuffer As Byte, ByVal nPacketSize As Long)

Public Sub ReadDataCallBack(ByVal nPort As Integer, ByRef pPacketBuffer As _
  Byte, ByVal nPacketSize As Integer)

  If Not bSaved_DVS Then
    bSaved_DVS = True
    HW_OpenStream(hChannelHandle, pPacketBuffer, nPacketSize)
  End If
  HW_InputData(hChannelHandle, pPacketBuffer, nPacketSize)

End Sub

MP4_ClientStart(clientinfo, AddressOf ReadDataCallBack)

Here is the VB.NET implementation:

Declare Function MP4_ClientStart Lib "hikclient.dll" (ByRef pClientinfo As _
  CLIENT_VIDEOINFO, ByVal abab As ReadDataCallBackDelegate) As Integer

Public Delegate Sub ReadDataCallBackDelegate(ByVal nPort As Long, _
  ByRef pPacketBuffer As Byte, ByVal nPacketSize As Long)

Public Sub ReadDataCallBack(ByVal nPort As Integer, ByRef pPacketBuffer As _
  Byte, ByVal nPacketSize As Integer)

  If Not bSaved_DVS Then
    bSaved_DVS = True
    HW_OpenStream(hChannelHandle, pPacketBuffer, nPacketSize)
  End If
  HW_InputData(hChannelHandle, pPacketBuffer, nPacketSize)

End Sub

MP4_ClientStart(clientinfo, AddressOf ReadDataCallBack)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文