Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

" addressof " VB6 to VB.NET

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)
like image 309
johan Avatar asked Mar 17 '10 15:03

johan


2 Answers

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.

like image 55
Jim Counts Avatar answered Sep 19 '22 00:09

Jim Counts


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.

like image 36
Ando Avatar answered Sep 19 '22 00:09

Ando