I am converting an app from VBA to VB.NET using VS .NET 2003. I have an I/O card that has an interrupt function that will execute a provided callback function. In VBA I could pass the addressof myCallBack function. VB.NET requires a Delegate to point to myCallBack function. I wrote my code per this article and I don't get errors, but the callback function isn't called. The dll function expects a Long. I am providing a Delegate.
Thank you for reviewing my issue!
Am I not importing something needed to make this work?Platform invoke converts the delegate to a familiar callback format automatically.
Code:
Imports System
Imports System.runtime.InteropServices
Public Delegate Function CallBack() As Long
Public Class frmPowerVentTest
Inherits System.Windows.Forms.Form
'...
Private Sub frmPowerVentTest_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rv as Integer
'...
rv = DIO_INT1_EventMessage(CARD, INT1_FP1C0, 0, 0, AddressOf myCallBack)
'...
end sub
Public Shared Function myCallBack() As Long
On Error GoTo ErrorHandler
Debug.WriteLine("CallBack Function called")
myCallBack = 0
Exit Function
ErrorHandler:
HandleErrors(Err)
End Function
End class
Code:
Public Module Dask
Declare Function DIO_INT1_EventMessage Lib "Pci-Dask.dll" (ByVal CardNumber As Integer, ByVal Int1Mode As Integer, ByVal windowHandle As Long, ByVal message As Long, ByVal callbackAddr As CallBack) As Integer 'changed "Long" to "CallBack"
End Module
Thank you for reviewing my issue!