Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Long param as Callback Function address to dll

Status
Not open for further replies.

LLBP

IS-IT--Management
Jan 31, 2002
39
US
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.
Platform invoke converts the delegate to a familiar callback format automatically.
Am I not importing something needed to make this work?
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!
 
Does anyone have any ideas on how to get this callback function to work? I really need some help. This will prevent the operator from having to press <SPACEBAR> and then press the test start button on the control panel. I will be able to detect the test start button being pressed.

Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top