Events
COM events support a N:M publish/subscribe model. A connection point (source) can have multiple subscribers (1:M) and a listener (sink) can subscribe to multiple COM servers (N:1).
The protocol to subscribe to an event is formal and has several steps.
- It is assumed that a user-defined callback interface has been registered on the system. The sink implements this interface.
- The sink calls QueryInterface on the source to get a pointer to IConnectionPointContainer.
- The sink calls IConnectionPointContainer::FindConnectionPoint with the IID of the callback interface, and gets a pointer to the relevant IConnectionPoint.
- The sink calls IConnectionPoint::Advise to start receiving events.
- (The source sends events to the sink’s callback interface…)
- To unsubscribe, the sink calls IConnectionPoint::Unadvise and calls Release on the IConnectionPoint and IConnectionPointContainer pointers.
.NET components can be both sources and sinks of COM events (a.k.a. unmanaged events).