如何向Inproc COM服务器添加新接口并实现新接口 [英] How to add and implement a new interface to an Inproc COM server

查看:156
本文介绍了如何向Inproc COM服务器添加新接口并实现新接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了Windows桌面带(使用Windows SDK示例),并且需要一种与之通信的方式(一个调用以启动另一个应用程序的IPC,而IPC已经在工作).

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.

我的COM经验非常有限,但是从我所看到的内容中推断,我认为应该可以创建一个新的COM接口,在deskband对象中实现它(我可以通过IBandSite访问),调用QueryInterface( )设置为我自己的界面,然后使用它直接呼叫桌面带.

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 ...)

所以,我的问题是:这是一种可行的方法吗?有人可以给我一个概述如何进行的概述(或指向一些可能有用的资源-缺少阅读COM书籍的知识,这就是我的建议)最后一种方法).如果不是,是否会想到其他选择?

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.

推荐答案

这是您的路径:您将一个新接口添加到.idl文件中,并且如果在.idl文件中有一个与您的COM对象相对应的共同类您可以在共同类定义中列出该新接口.然后,编译.idl,这将为您提供一个.h文件和一个带标识符的.c文件-C ++ IID和C ++接口定义.

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.

然后,您从C ++接口继承COM对象C ++类,并实现它的所有方法.如果出于某种原因您不想或不想实现一个方法,则必须从该方法实现中返回E_NOTIMPL.

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.

最后一件非常重要的事情:您必须在COM对象类中更改QueryInterface()行为.如果使用ATL,则必须在COM映射中添加一个条目.如果您不使用ATL进行更改,请QueryInterface()-请参见此问题,以了解在实施多个示例的情况下如何实现QueryInterface() COM接口.

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 you QueryInterface() - see this question for how to implement QueryInterface() in case of implementing several COM interfaces.

这篇关于如何向Inproc COM服务器添加新接口并实现新接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆