0

I did define an interface in C# with an event as:

[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("02F91299-B87C-47D2-B501-7768E767E012")]
public interface IFoo
{
    event FooEventHandler FooEvent;
}

[ComVisible(true), Guid("2CB3858D-5729-47A1-B46B-C2C37C522E10")]
public delegate void FooEventHandler(IFoo sender, int status);

I have to implement this interface in an unmanaged C++ ATL DLL. The code class wizard proposes is:

STDMETHOD(add_FooEvent)(_FooEventHandler * value);
STDMETHOD(remove_FooEvent)(_FooEventHandler * value);

I see FooEventHandler as an IDispatch object. I do add/remove those _FooEventHandler * values into a list.

Now to my question: how do I fire/invoke this event for all stored _FooEventHandlers?

Thanks, Cabbi

UPDATE: I found the answer here: Exposing manged events to COM using C++

Community
  • 1
  • 1
cabbi
  • 393
  • 2
  • 12
  • 1
    I guess you should implement IConnectionPoint using IConnectionPointImpl templated class and the latter will have a collection of event receivers subscribed to the event. – sharptooth Jun 25 '13 at 10:45
  • Thanks for the comment, I know how to implement events from the DLL project IDL file, and how you correctly suggests, this is done by means of 'IConnectionPointImpl'. But this time I have to implement an "extern" C# interface and the class wizard only provides those add/remove pair passing an IDispatch object... :( – cabbi Jun 25 '13 at 13:42
  • You could ask regasm to export a typelib, then `#import` that into Visual C++ and so the interface will be visible to C++ code. Then you just inherit your object from `IConnectionPointImpl` and use a lot of rasp file. – sharptooth Jun 25 '13 at 13:47
  • I already have the TLB file and imported it into my C++ project. What do you mean with: "...and use a lot of rasp file" – cabbi Jun 25 '13 at 13:50
  • I mean you'll have to write some code and adapt it till it works. Step one is inheriting your COM object class from `IConnectionPointImpl`. – sharptooth Jun 25 '13 at 14:01
  • In my undertranding (I might be wrong!?) .net events are implemented with delegates (i.e. function pointers), ATL's with sinks. So I'm not sure IConnectionPointImpl will support .net event handlings. I'll try, and let you know – cabbi Jun 25 '13 at 16:54

0 Answers0