G
Guest
I have a problem dealing with passing a function address to a COM callback. I
use this COM function for communicating to a hardware. My original project
was written in VB. I have converted it to C#. One of the problem is passing
a function address to a COM function as a parameter with another progress
value. My callback function is very simple using the progress value to update
my progressbar. Because this COM function usually takes a long time (sending
a large mount of data to a hardware for example). In my old VB project, it
works fine. But when I convert it to C#, I do not know how to do it. Is there
anybody can help me to solve this problem?
The following is the VB code:
‘Declaration
Dim ProgressValue As Long
Dim objHardware As MyComLib.Hardware
Dim FileName As String
Private Form_Load()
Set objHardware = New MyComLib.Hardware
FileName = “C:\Test.binâ€
End Sub
Private Sub cmdSendData_Click()
Dim lAddress As Long
lAddress = AddressOf UpdateProgressBar
Call objHardware.SendData(FileName, lAddress, ProgressValue)
End Sub
Public Sun UpdateProgressBar()
ProgressBar1.Value = ProgressValue
End Sub
Actually objHardware, ProgressValue and UpdateProgressBar are defined in
Module as public variables.
Many thanks,
Minfu
use this COM function for communicating to a hardware. My original project
was written in VB. I have converted it to C#. One of the problem is passing
a function address to a COM function as a parameter with another progress
value. My callback function is very simple using the progress value to update
my progressbar. Because this COM function usually takes a long time (sending
a large mount of data to a hardware for example). In my old VB project, it
works fine. But when I convert it to C#, I do not know how to do it. Is there
anybody can help me to solve this problem?
The following is the VB code:
‘Declaration
Dim ProgressValue As Long
Dim objHardware As MyComLib.Hardware
Dim FileName As String
Private Form_Load()
Set objHardware = New MyComLib.Hardware
FileName = “C:\Test.binâ€
End Sub
Private Sub cmdSendData_Click()
Dim lAddress As Long
lAddress = AddressOf UpdateProgressBar
Call objHardware.SendData(FileName, lAddress, ProgressValue)
End Sub
Public Sun UpdateProgressBar()
ProgressBar1.Value = ProgressValue
End Sub
Actually objHardware, ProgressValue and UpdateProgressBar are defined in
Module as public variables.
Many thanks,
Minfu