InertiaM
Well-known member
I've only ever used delegates before when trying to update a ProgressBar etc.
Unfortunately, I now have to write an application that communicates with a third party DLL written by a coder who has no knowledge of VB.
Here's what I have so far:-
The call to the DLL works, and it performs the function it is supposed to, but I dont appear to be getting any feedback via the delegate.
Any suggestions would be greatly appreciated
Unfortunately, I now have to write an application that communicates with a third party DLL written by a coder who has no knowledge of VB.
Here's what I have so far:-
VB.NET:
Public Declare Function Optimise Lib "nameremoved.dll" (ByVal hPtr As IntPtr, ByVal lpDir As String, _
ByVal lpJob As String, ByVal lpSystem As String, ByVal jFlags As Long, ByVal OCB As OptimiserCallback) As Long
Private Delegate Function OptimiserCallback(ByVal sMode As Integer, ByVal lParam As String) As Long
Private cb As OptimiserCallback
Private JOBDirectory As String = "f:\"
Private JOBFile As String = "test"
Private Result As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
cb = AddressOf OptimiserCallbackFunction
Result = Optimise(Me.Handle, JOBDirectory, JOBFile, "c:\", 0, cb)
End Sub
Private Function OptimiserCallbackFunction(ByVal sMode As Integer, ByVal lParam As String) As Long
OptimiserCallbackFunction = 0 'return 2 to cancel
Select Case sMode
Case 10
'better solution found
'TODO: update screen
Case 12
'success
Button1.Enabled = True
Case 13
'abnormal termination
Button1.Enabled = True
End Select
End Function
The call to the DLL works, and it performs the function it is supposed to, but I dont appear to be getting any feedback via the delegate.
Any suggestions would be greatly appreciated