G
Guest
--------------------------------------------------------------------------------
I need to do the exactly same thing in VB.NET.
Load a unmanaged C DLL dynamically and then call a function in which I pass
the callback function as an argument. My C function being called callback as
type _cdecl.
Does anybody have any ideas?
Here is what I am trying to do:
-----------Native Code snippet----------------
typedef ErrorCode (__cdecl * CALLBACK_HANDLER)(
const int messageType, const char * message) ;
//This is the native function to be invoked
ErrorCode register(CALLBACK_HANDLER messageHandler, const char * parameters);
----------------------------------------------
-------------VB.NET code snippet-------------
.......
Module CallbackHandler
Public Delegate Function Callback(ByVal messageType As Long, ByVal message
As String) As Long
Public Declare Function register Lib "api.dll" (ByVal trafficType As
Integer, ByVal listener As Callback) As Long
End Module
......
.......
Public Function myCallback(ByVal messageType As Long, ByVal message As
String) As Long
Try
MsgBox(messageType)
MsgBox(message)
Catch ex As Exception
'MsgBox(ex)
Finally
End Try
End Function
......
......
Dim cb As CallbackHandler.myCallback
cb = AddressOf myCallback
CallBackHandler.register(2, cb)
.......
----------------------------------------------
However I keep getting the error NullReferenceException which I guess is
because my native declaration is _cdecl while I'm trying to make a _stdcall.
Any help would be greatly appreciated.
Peace!
I need to do the exactly same thing in VB.NET.
Load a unmanaged C DLL dynamically and then call a function in which I pass
the callback function as an argument. My C function being called callback as
type _cdecl.
Does anybody have any ideas?
Here is what I am trying to do:
-----------Native Code snippet----------------
typedef ErrorCode (__cdecl * CALLBACK_HANDLER)(
const int messageType, const char * message) ;
//This is the native function to be invoked
ErrorCode register(CALLBACK_HANDLER messageHandler, const char * parameters);
----------------------------------------------
-------------VB.NET code snippet-------------
.......
Module CallbackHandler
Public Delegate Function Callback(ByVal messageType As Long, ByVal message
As String) As Long
Public Declare Function register Lib "api.dll" (ByVal trafficType As
Integer, ByVal listener As Callback) As Long
End Module
......
.......
Public Function myCallback(ByVal messageType As Long, ByVal message As
String) As Long
Try
MsgBox(messageType)
MsgBox(message)
Catch ex As Exception
'MsgBox(ex)
Finally
End Try
End Function
......
......
Dim cb As CallbackHandler.myCallback
cb = AddressOf myCallback
CallBackHandler.register(2, cb)
.......
----------------------------------------------
However I keep getting the error NullReferenceException which I guess is
because my native declaration is _cdecl while I'm trying to make a _stdcall.
Any help would be greatly appreciated.
Peace!