title: VB.Net Com Interop - Sink COM Events to VBA Client
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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:
  
  &lt;ClassInterface(ClassInterfaceType.None)&gt; _
      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
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>Public Delegate Sub BytesTransferredDelegate(ByVal ByteCount As Long, ByVal RemoteFileName As String)
  
  Public Interface IFTP
      &lt;DispId(1)&gt; _
      Sub BytesTransferred(ByVal ByteCount As Long, ByVal RemoteFileName As String)
  End Interface
  
  'Here's the relevant part of my class:
  
  &lt;ClassInterface(ClassInterfaceType.None)&gt; _
      &lt;ProgId("MyTestClass.FTP")&gt; _
      &lt;ComSourceInterfaces(GetType(IFTP))&gt; _
  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
  </code></pre>