管理COM聚集 [英] Managed COM aggregation

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

问题描述

这是我的理解构建聚集现有的COM对象的COM对象意味着执行重定向逻辑中的外部对象的IUnknown.QueryInterface方法。

It is my understanding building a COM object aggregating an existing COM object implies implementing redirection logic in the IUnknown.QueryInterface method of the outer object.

我的问题是怎么做,如果你正在构建的对象进行管理。在管理对象的IUnknown没有明确执行COM互操作为您完成。所以,我该怎么办告诉COM互操作,我建立的对象是另一个COM对象的集合?

The question I have is how to do that if the object you are building is managed. On managed objects IUnknown is not explicitly implemented COM Interop does it for you. So how do I tell COM Interop that the object I build is an aggregation of another COM object?

到目前为止,我发现的唯一途径,是落实在外部内部对象的所有接口,并明确重定向他们。这是一个)丑和b)假设你知道所有的接口来实现这是不是在我的情况的情况。

So far the only way I found is to implement all the interfaces of the inner object on the outer and explicitly redirect them. This is a) ugly and b) assumes that you know all the interfaces to implement which is not the case in my situation.

有什么想法?

推荐答案

如果您使用的是.NET 4,那么你可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.icustomqueryinterface.getinterface%28VS.100%29.aspx">ICustomQueryInterface覆盖默认的 IUnknown.QueryInterface 逻辑。 有对COM聚集一个样品在codePLEX - 实施是很简单

If you are using .NET 4 then you could use ICustomQueryInterface to override the default IUnknown.QueryInterface logic. There's a sample for COM aggregation on CodePlex - the implementation is quite straightforward:

CustomQueryInterfaceResult ICustomQueryInterface.GetInterface(ref Guid iid, out IntPtr ppv)
{
    if(iid.Equals(new Guid("00000000-0000-0000-0000-000000001234")))
    {
        ppv = Marshal.GetComInterfaceForObject(this.innerObject, typeof(IInnerInterface), CustomQueryInterfaceMode.Ignore);
        return CustomQueryInterfaceResult.Handled;
    }
    ppv = IntPtr.Zero;
    return CustomQueryInterfaceResult.NotHandled;
}

这篇关于管理COM聚集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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