"addressof" VB6 - VB.NET

I'm having trouble converting my VB6 project to VB.NET

I do not understand how this "AddressOf" function should be in VB.NET

My VB6 code is:

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)
+5
source share
4 answers

You probably see this error:

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

What you probably want to do is create a delegate and then change the adab type to this 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 / do not modify your ReadDataCallBack file, you still need to.

. , . VB6, VB.NET. .NET Integer, Long in VB6.

+4

, , .

- , / - . , , .

+3

I assume that the second parameter MP4_ClientStart should be the address of the callback function. The problem is probably that you defined it here as Long, which in VB6 is a 32-bit value, but in VB.NET it is a 64-bit value. You are likely to succeed by changing your declaration to:

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

Very pleasant, thanks!

I did it like this:

VB.NET Code:

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)
0
source

All Articles