COM接口实现继承 [英] COM Interface Implementation Inheritance

查看:79
本文介绍了COM接口实现继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在创建一个进程外COM服务器来承载许多32位DLL,以便64位进程可以通过包装器接口"访问它们.这些包装器接口中的每一个都实现IDispatch接口以及访问32位DLL的许多包装器方法".

因为IUnknown和IDispatch方法的实现在每个包装器接口中几乎相同,所以我认为我可以通过在基类中实现这些方法并让每个包装器接口继承这些实现来节省一些时间.

我构造代码的方式是,基本接口继承IDispatch,而基类则继承基本接口.子接口不继承任何内容,子类继承子接口和基类.

根据Microsoft的说法,如果使用C ++多重继承来实现多个接口,则各种接口可以共享一个IUnknown实现."

我还需要一段时间才能真正进行测试.以前有人尝试过这样的东西吗? COM对象是否可以继承公用接口的实现?

预先感谢您的评论或建议.



我的代码如下所示:

Hello,

I am creating an out-of-process COM server to host a number of 32-bit DLLs so that they can be accessed by a 64-bit process through ''wrapper interfaces''. Each of these wrapper interfaces implements the IDispatch interface as well as a number of ''wrapper methods'' that access the 32-bit DLLs.

Because the implementations of the IUnknown and IDispatch methods are nearly identical in each wrapper interface, I thought I could save some time by implementing these methods in a base class and having each of the wrapper interfaces inherit these implementations.

The way I have structured my code, the base interface inherits IDispatch, and the base class inherits the base interface. The child interface inherits nothing, and the child class inherits the child interface and the base class.

According to Microsoft, "If you are using C++ multiple inheritance to implement multiple interfaces, the various interfaces can share one implementation of IUnknown."

It will be some time before I can really test this out. Has anyone tried something like this before? Is it possible for COM objects to inherit implementations of common interfaces?

Thanks in advance for your comments or suggestions.



My code looks something like this:

//Filename: Base.idl

import "oaidl.idl";
import "ocidl.idl";
import "unknwn.idl";
[
    object,
    uuid(...),
    dual,
    oleautomation
]
interface IBase : IDispatch
{ }
[ uuid(...) ]
library BaseLib
{
    importlib("stdole32.tlb");
    importlib("stdole2.tlb");
    interface IBase;

    [ uuid(...) ]
    coclass Base
    {
        [default] interface IBase;
    }
}









************************
//Filename: Base.h

#include "Base_h.h"

class Base : public IBase
{
public:

    //Construction
    Base();
    ~Base();

    //IUnknown implementation
    HRESULT STDMETHODCALLTYPE QueryInterface(...);
    ULONG   STDMETHODCALLTYPE AddRef();
    ULONG   STDMETHODCALLTYPE Release();

    //IDispatch implementation
    HRESULT STDMETHODCALLTYPE GetTypeInfoCount(...);
    HRESULT STDMETHODCALLTYPE GetTypeInfo(...);
    HRESULT STDMETHODCALLTYPE GetIDsOfNames(...);
    HRESULT STDMETHODCALLTYPE Invoke(...);

    //Helper methods

protected:
    
    /* Some virtual helper methods here... */

    long m_RefCount;
};





*********************
//Filename: Child.idl

import "oaidl.idl";
import "ocidl.idl";
[
    object,
    uuid(...),
    dual,
    oleautomation
]
interface IChild
{ // Child interface methods }

[ uuid(...)]
library ChildLib
{
    importlib("stdole32.tlb");
    importlib("stdole2.tlb");
    interface IChild;
    [ uuid(...) ]
    coclass Child
    {
        [default] interface IChild;
    }
}





*******************
//Filename: Child.h

#include "Base.h"
#include "IChild_h.h"

class Child : public IChild, public Base
{
public:
    //Construction
    Child();
    ~Child();

    //Child Interface Methods
    // ....

protected:

    /* Helper method implementations ... */

};

推荐答案

您应该很好,这是许多ATL基类/模板类所要做的.例如,IDispatchImpl 提供了IDispatch 实现基础.
You should be good, this is what a lot of the ATL base/template classes do. Example, IDispatchImpl provides an IDispatch implementation base.


只需使用^ ]-如果我正确理解了您的问题-它可以完成您想做的事情.

话虽这么说-我只是放弃了整个DCOM的想法-然后将混合模式的C ++/CLI包装器封装在您的32位dll上,并通过32位自托管WCF服务公开其服务. />
我提供了许多链接,它们可能会在另一个答案中为您提供帮助:
如何部署Web服务? [ ^ ]

这种设计可能会更容易实现:)

问候
Espen Harlinn
Just use ATL[^] - If I understood your question correctly - it does what you want to do.

Having said that - I''d just drop the whole DCOM idea - and go for a mixed mode C++/CLI wrapper aound your 32-bit dll''s and expose their services through a 32-bit self hosting WCF service.

I''ve provided a number of links that may help you in another answer:
How can I deploy web service?[^]

This design will probably be much simpler to implement :)

Regards
Espen Harlinn


这篇关于COM接口实现继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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