What is IconnectionPoint and EventHandling
Asked Answered
P

2

5

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.

Pickpocket answered 25/8, 2010 at 6:37 Comment(0)
L
10

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.

Lactoprotein answered 25/8, 2010 at 6:42 Comment(1)
Edited the question with my queryPickpocket
C
-1

These two articles provide useful information:

https://devblogs.microsoft.com/oldnewthing/?p=4113

https://devblogs.microsoft.com/oldnewthing/20130612-00/?p=4103

What @sharptooth forgot to mention is, the pointer passed to IConnectionPoint::Advise must be a pointer to a COM object.

This means It must not only implement the particular events interface but also the IUnknown interface.

Catalan answered 2/1, 2020 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.