AddressOf VB.net

P

peter

Probably you might help me regarding this.. I'm new to these Vb.net
language. My question is Does AddressOf is accepted in Vb.net?

in this VbCode: I have this API
===================================
Public Declare Function SetCallbacks Lib "tfm.dll" ( _
ByVal hConn As Long, ByVal pfnGuiCallback As Long, ByVal
pGuiCallbackCtx As Long, ByVal pfnGuiStateCallback As Long, ByVal
pGuiStateCallbackCtx As Long) As Long

===Callback.bas - Module===
Result = SetCallbacks(Connection, 0&, 0&, AddressOf STATE_CALLBACK, 0&

- i have this module Callback.bas a procedure function called
STATE_CALLBACK

=======================================
Function STATE_CALLBACK(ByVal pGuiStateCallbackCtx As Long, ByVal
dwGuiState As Long, ByRef pbyRes As Byte, ByVal dwMsg As Long, ByVal
byProg As Byte, ByVal pSamBuf As Long, ByVal Data As Long) As Long


How will i convert this to vb.net???! I have a module for the
Callback..

what i did was with the same format
======================================
Result = SetCallbacks(Connection, 0, 0, AddressOf
Callback.STATE_CALLBACK, 0)

and the error appeared was "AddressOf expression cannot convertes to
integer because integer is not delegate type" Im getting stucked in
here... I need it badly..

I'll appreciate for helping me

tnx..
 
I

Imran Koradia

The AddressOf operator is available in VB.NET also. However, the way you
implement callback procedures in VB.NET is a little different. First of all,
'Long' from VB6 converts to 'Integer' in VB.NET. Next, you can use delegates
to implement call procedures.
Here's how:

Delegate Function STATE_CALLBACK ( _
ByVal pGuiStateCallbackCtx As Integer, ByVal dwGuiState As Integer,
_
ByRef pbyRes As Byte, ByVal dwMsg As Integer, _
ByVal byProg As Byte, ByVal pSamBuf As Integer, _
ByVal Data As Integer) As Integer

Public Declare Function SetCallbacks Lib "tfm.dll" ( _
ByVal hConn As Integer, ByVal pfnGuiCallback As Integer, _
ByVal pGuiCallbackCtx As Integer, _
ByVal pfnGuiStateCallback As STATE_CALLBACK, _
ByVal pGuiStateCallbackCtx As Integer) As Integer


Function State_Cbk(ByVal pGuiStateCallbackCtx As Integer, _
ByVal dwGuiState As Integer, ByRef pbyRes As Byte, _
ByVal dwMsg As Integer, ByVal byProg As Byte, _
ByVal pSamBuf As Integer, ByVal Data As Integer) As Integer

' here goes your callback code..

End Function

In the SetCallbacks, I assume the remaining parameters also pass addresses
to callback procedures. But since you're using just one of them, you can
define the remaining as Integers and pass in 0. This is how you would call
the function.

Dim Result = SetCallbacks(Connection, 0, 0, AddressOf STATE_CALLBACK, 0)

hope that helps..
Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top