Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is IconnectionPoint and EventHandling

Trying to understand What is IConnectionPoint and how this is connected to IConnectionPointContainer,IEnumConnectionPoints,IEnumConnections and EventHandling.

Read the artcicles from MSDN and CodeProject which is explaining a about other methods like: QueryInterface() and otherthings.

I am unable to figure out how all these things(IConnectionPointContainer,IEnumConnectionPoints,IEnumConnections) are interconnected with eachother and event Handling.

I just want to create a simpleClient which Will trigger an event in COM object.

If there are any articles or code snippet that can explain how things are related to each other with simple and small chunk of code will be helpfull.

Worth mentioning that I have started development in C recently, a beginner.

Edit @sharptooth

For the Line "typically your client will receive events and the COM object will trigger those events. "

From many articles, What I understood is When we use connection points at that point, the client exposes a set of methods that the server uses.

I am just Outlining portion of the article from TechRepublich:

Client server vs. sink source

So the main difference between normal programming with COM in a standard client-server system and using connection points is that in the standard client-server case, the server exposes a list of methods that the client employs, and in the connection point case, the client exposes a set of methods that the server uses.

like image 533
Simsons Avatar asked Feb 27 '23 09:02

Simsons


1 Answers

Looks like you get the big picture wrong. Typically your client will receive events and the COM object will trigger those events. To achieve this the client requests (QueryInterface()) the IConnectionPointContainer interface, calls IConnectionPointContainer::FindConnectionPoint() and IConnectionPoint::Advise() and passes a pointer to itself or some subobject there.

The client will have to implement some events interface (the one GUID of which is passed into IConnectionPointContainer::FindConnectionPoint()). Once subscribed (advised) the client will receive calls from the COM server - the events.

Typically the COM server does something routinely and decides to notify clients of it (say a user moves the mouse in an ActiveX control) - it just gets an array of pointers to event receivers and calls a method it wants on that interface.

COM events are in fact an implementation of callbacks. The same way you use callback in C++ (or C or any other languages supporting function pointers or interfaces) you use events in COM. Yes, you're right that when the server triggers the event the client in fact acts as a server reacting to the event. That's a callback scenario - the other code calls your functionality. In this case the server calls your implementation of the events interface.

like image 177
sharptooth Avatar answered Mar 03 '23 10:03

sharptooth