如何向 Inproc COM 服务器添加和实现新接口
我已经实现了一个 Windows 桌面带(使用 Windows SDK 示例),并且需要一种与其进行通信的方法(一次调用以启动 IPC 与另一个应用程序,IPC 已经在工作)。
我的 COM 经验非常有限,但从我所看到的情况推断,我认为应该可以创建一个新的 COM 接口,在 deskband 对象中实现它(我可以通过 IBandSite 访问它),为我的对象调用 QueryInterface()上面有自己的接口,然后用它直接调用桌带。
我已经尝试过这个,但很快就遇到了问题(主要原因是:我不知道我大部分时间实际上在做什么......)
所以,我的问题是:这是一种可行的方法吗?有人可以提供吗?如果是的话,我会概述如何继续(或者指出一些可能有帮助的资源 - 缺少阅读 COM 书籍,这将是我的最后一种方法)。如果不是,是否会想到替代方案?
感谢您抽出宝贵的时间并致以最美好的祝愿,
雷内。
I've implemented a windows deskband (using the windows SDK sample) and need a way to communicate (one call to start IPC with another application, IPC is already working) with it.
My COM experience is very limited but extrapolating from what I've seen, I think it should be possible to create a new COM interface, implement it in the deskband object (which I have access to via IBandSite), call QueryInterface() for my own interface on it and then use it to call directly into the deskband.
I've tried this but ran into problems very quickly (main reason being: I've no idea what I'm actually doing most of the time ...)
So, my questions are: Is this a viable approach and can someone give me an outline on how to proceed if it is (or point to some resource that could be helpful - short of reading a COM book, which would be my last approach). If it is not, do alternatives come to mind ?
Thank you for your time and best wishes,
Rene.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您的路径:您将一个新接口添加到 .idl 文件中,并且如果 .idl 文件中有一个与您的 COM 对象相对应的共同类,您将在共同类定义中列出该新接口。然后编译 .idl,这会得到一个 .h 文件和一个带有标识符的 .c 文件 - C++ IID 和 C++ 接口定义。
然后从 C++ 接口继承 COM 对象 C++ 类并实现它的所有方法。如果出于某种原因您不能或不想实现某个方法,则必须从该方法实现中返回
E_NOTIMPL
。最后一件非常重要的事情:您必须更改 COM 对象类中的
QueryInterface()
行为。如果您使用 ATL,则必须在 COM 映射中添加一个条目。如果您不使用 ATL,请更改QueryInterface()
- 请参阅此问题了解如何实现< code>QueryInterface() 在实现多个 COM 接口的情况下。Here's you path: you add a new interface into .idl file and also if you have a co-class in the .idl file that corresponds to you COM object you list that new interface in the co-class definition. Then you compile the .idl and this gets you a .h file and a .c file with identifiers - the C++ IID and C++ interface definition.
Then you inherit your COM object C++ class from the C++ interface and implement all methods of it. If for whatever reason you can't or don't want to implement a method you have to return
E_NOTIMPL
from that method implementation.One very important final thing: you have to change
QueryInterface()
behavior in you COM object class. If you use ATL you have to add an entry into the COM map. If you don't use ATL change youQueryInterface()
- see this question for how to implementQueryInterface()
in case of implementing several COM interfaces.