title: How to listen to a C#.NET activeX control's event in vb6
body: <p>The .net control has been referenced and added to the vb6 project. It also shows the events that I have in the interface. However, vb6 is not registering to the events and I do not know why. I have read several dozen articles on the subject, used code from a working .Net Control/vb6. This is my first round robin with Events so its probably something very small I'm missing, but here's the code:</p>
  
  <p>C#.NET</p>
  
  <pre><code>[ComVisible (true)]
  [Guid(CustomerCreditControl.EventsId)]
  [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
  public interface ICustomerCreditControlEvents
  {
      [DispId(1)]
      void Test();
  }
  
  [ComVisible(true)]
  [Guid(CustomerCreditControl.InterfaceId)]
  [InterfaceType(ComInterfaceType.InterfaceIsDual)]
  public interface ICustomerCreditControl
  {
      void SetAccount(string customerNumber, int generatorId);
      string CreditHold { get; }
  }
  
  [ComVisible(true)]
  [Guid(CustomerCreditControl.ClassId)]
  [ClassInterface(ClassInterfaceType.None)]
  [ComSourceInterfaces(typeof(ICustomerCreditControlEvents))]
  public partial class CustomerCreditControl : UserControl, ICustomerCreditControl
  {
       public delegate void TestEventHandler();
       public event TestEventHandler TestEvent;
      [ComRegisterFunction()]
      private static void Register(Type t)
      {
          ComRegistration.RegisterControl(t, "");
      }
  
      [ComUnregisterFunction()]
      private static void Unregister(Type t)
      {
          ComRegistration.UnregisterControl(t);
      }
      public CustomerCreditControl()
      {
          InitializeComponent();
      }
      public void SetAccount(string customerNumber, int generatorId)
      {
          _customer = RCI.DataAccess.DataFactory.Current.AccountService.GetCustomer(customerNumber.Trim());           
          SetAccount(_customer, generatorId);
      }
      public void btnNewSalesOrder_Click(object sender, EventArgs e)
      {
          if (TestEvent != null)
          {
              MessageBox.Show("Test Event Fired");
              TestEvent();
          }
          else
              MessageBox.Show("TestEvent = null");
  
          string[] SOI = {"a","b","c"};
          MessageBox.Show(SOI.ToString());
          OnNewSalesOrder(ref SOI);
      }
   }
  </code></pre>
  
  <p>VB6</p>
  
  <pre><code>Private Sub customerCreditInfo_Test()
       MsgBox "Test 2"
  End Sub
  </code></pre>
  
  <p>The vb6 code recognizes the test event, but it does not register to the event. The control is placed on a vb6 form. I have 'MsgBox "Test 2"' just as a test. The tlb is referenced by the project and the activeX is added to the toolbox components. I have unregistered this dll from windows and gone through and removed all instances from the registry. I am using regasm /register /codebase /tlb to register the dll.</p>
  
  <p>Using Visual Studio 2008, .net 2.0 and compiling on a Windows 7 machine.</p>
  
  <p>What am I missing?</p>