I'm programming a COM interop DLL in VB.NET and I need the events to be exposed to a VBA COM client. I just can't wrap my head around this one.
This is a COM wrapper for a .NET FTP library so don't get too confused by the fact that I'm raising a BytesTransferred event on a BytesTransferred event.
As I best recall, this code works but simply fails to show any events in the COM client when I use the object browser. It also fails to compile when I try to Dim my variable WithEvents:
Public Interface IFTP
Event BytesTransferred(ByVal ByteCount As Long, ByVal RemoteFileName As String)
End Interface
'Here's the relevant part of my class:
Public Interface IFTP
Event BytesTransferred(ByVal ByteCount As Long, ByVal RemoteFileName As String)
End Interface
Here's the relevant part of my class:
<ClassInterface(ClassInterfaceType.None)> _
Public Class FTP : Implements IFTP
Public Sub New()
'This needed for com interop
End Sub
Public Event BytesTransferred(ByVal ByteCount As Long, ByVal RemoteFileName As String) Implements IFTP.BytesTransferred
Private Sub fCon_BytesTransferred(ByVal sender As Object, ByVal e As EnterpriseDT.Net.Ftp.BytesTransferredEventArgs) Handles fCon.BytesTransferred
RaiseEvent BytesTransferred(e.ByteCount, e.RemoteFile)
End Sub
End Class
I've also tried something like this but I think I'm missing something here because it doesn't compile. I see an error that says I've failed to implement Sub BytesTransferred for interface IFTP:
Public Delegate Sub BytesTransferredDelegate(ByVal ByteCount As Long, ByVal RemoteFileName As String)
Public Interface IFTP
<DispId(1)> _
Sub BytesTransferred(ByVal ByteCount As Long, ByVal RemoteFileName As String)
End Interface
'Here's the relevant part of my class:
<ClassInterface(ClassInterfaceType.None)> _
<ProgId("MyTestClass.FTP")> _
<ComSourceInterfaces(GetType(IFTP))> _
Public Class FTP : Implements IFTP
Public Event BytesTransferred As BytesTransferredDelegate
Public Sub New()
'This needed for com interop
End Sub
Private Sub fCon_BytesTransferred(ByVal sender As Object, ByVal e As EnterpriseDT.Net.Ftp.BytesTransferredEventArgs) Handles fCon.BytesTransferred
RaiseEvent BytesTransferred(e.ByteCount, e.RemoteFile)
End Sub
End Class