" addressof " VB6 to VB.NET
Asked Answered
O

4

6

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)
Obituary answered 17/3, 2010 at 15:11 Comment(1)
Please format using the <Code sample> formatPasteurism
P
5

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.

Peroration answered 17/3, 2010 at 15:58 Comment(0)
P
3

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.

Pasteurism answered 17/3, 2010 at 15:16 Comment(1)
yes , its not the complete code, just everything that has with the addressof function to do, and I need the callback functionObituary
D
2

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
Driven answered 17/3, 2010 at 15:51 Comment(0)
O
0

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)
Obituary answered 17/3, 2010 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.