什么是 IconnectionPoint 和 EventHandling
尝试了解什么是 IConnectionPoint
以及它如何连接到 IConnectionPointContainer、IEnumConnectionPoints、IEnumConnections
和 EventHandling。
阅读 MSDN 和 CodeProject 正在解释其他方法,例如:QueryInterface()
和其他事情。
我无法弄清楚所有这些东西(IConnectionPointContainer,IEnumConnectionPoints,IEnumConnections
)是如何相互关联和事件处理的。
我只想创建一个 simpleClient 它将触发 COM 对象中的事件。
如果有任何文章或代码片段可以用简单的小块代码解释事物如何相互关联,将会很有帮助。
值得一提的是,我最近开始使用C进行开发,是一个初学者。
编辑 @sharptooth
对于“通常您的客户端将接收事件并且 COM 对象将触发这些事件
。”
这一行,我从很多文章中了解到,理解是当我们在该点使用连接点时, 客户端公开服务器使用的一组方法
。
我只是概述 TechRepublich:
客户端服务器与接收器源
因此,在标准客户端-服务器系统中使用 COM 进行正常编程与使用连接点之间的主要区别在于,在标准中客户端-服务器情况下,服务器公开客户端使用的一系列方法,而在连接点情况下,客户端公开服务器使用的一组方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来你的大局观是错误的。通常,您的客户端将接收事件,并且 COM 对象将触发这些事件。为了实现此目的,客户端请求 (
QueryInterface()
)IConnectionPointContainer
接口,调用IConnectionPointContainer::FindConnectionPoint()
和IConnectionPoint:: Advise()
并将指针传递给其自身或其中的某个子对象。客户端必须实现一些事件接口(其中的一个 GUID 被传递到 IConnectionPointContainer::FindConnectionPoint())。一旦订阅(建议),客户端将接收来自 COM 服务器的调用 - 事件。
通常,COM 服务器会定期执行某些操作并决定通知客户端(例如用户在 ActiveX 控件中移动鼠标) - 它只是获取指向事件接收器的指针数组并在该接口上调用它想要的方法。
COM 事件实际上是回调的实现。在 COM 中使用事件的方式与在 C++(或 C 或任何其他支持函数指针或接口的语言)中使用回调的方式相同。是的,您是对的,当服务器触发事件时,客户端实际上充当对事件做出反应的服务器。这是一个回调场景 - 其他代码调用您的功能。在这种情况下,服务器调用您的事件接口的实现。
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()
) theIConnectionPointContainer
interface, callsIConnectionPointContainer::FindConnectionPoint()
andIConnectionPoint::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.
这两篇文章提供了有用的信息:
https://devblogs.microsoft.com/oldnewthing/?p =4113
https://devblogs.microsoft.com/oldnewthing /20130612-00/?p=4103
@sharptooth 忘记提到的是,传递给
IConnectionPoint::Advise
的指针必须是指向COM
的指针目的。这意味着它不仅必须实现特定的事件接口,还必须实现 IUnknown 接口。
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 aCOM
object.This means It must not only implement the particular events interface but also the
IUnknown
interface.