Wednesday, September 12, 2007

Exposing COM events from .Net to Javascript in web browser

A lot has already been written about this so I won't repeat all the details here. These two links give a good guide to how to do it.

COM Interop Exposed - Part 2

HOW TO: Sink Managed C# Events in Internet Explorer Script

This post is about troubleshooting some common mistakes that may occur. The key thing to note is that if you fail to follow the steps listed in these articles:
  1. you will NOT get a compile time error
  2. you will NOT get an error when registering the component
  3. you will NOT get an error at runtime when you attach the event handler.
Mistakes that I made were:
  1. Did not put a Dispid attribute on the methods in my event interface.
  2. Had name mismatches between the events in my main class and the method names in my interface.
I'll add some test code here later.

No comments: