COM如何选择如何封送接口? [英] How does COM select how to marshal an interface?

查看:210
本文介绍了COM如何选择如何封送接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为有三种方法可以在COM中实现编组:

As I get it there're three ways to implement marshalling in COM:


  • typelib marshalling

  • proxy / stub marshalling

  • 通过对象实现IMarshal

组件消费者(用户)选择将使用哪一个?它是自己决定,使用首选的方式,还是调用一些内置的函数,它解决了它的问题?

now how does the component consumer (user) choose which one will be used? Does it decide on its own and use the preferred way or does it call some built-in function and it solves the problem for it?

我目前体验以下:my组件实现了另一个公司的组件实现的自定义接口 ICustomInterface 。我的组件没有typelib,不实现IMarshal。系统注册表包含HKCR \Interface {uuidof(ICustomInterface)} \ProxyStubClsid32键,其中包含可以跟踪到该其他公司提供的库的代理/存根的GUID。

I currently experience the following: my component implements a custom interface ICustomInterface that is also implemented by a component from another company. My component doesn't have a typelib and doesn't implement IMarshal. The system registry contains the HKCR\Interface{uuidof(ICustomInterface)}\ProxyStubClsid32 key with a GUID of the proxy/stub that can be traced to a library provided by that other company.

现在当我的组件消费者初始化我的组件,它调用QueryInterface()从我的组件请求IMarshal,当返回E_NOINTERFACE它什么也不做。为什么这是 - 为什么不代理/存根库从其他公司踢?

Now when my component consumer initializes my component it calls QueryInterface() requesting IMarshal from my component and when returned E_NOINTERFACE it just does nothing. Why is this - why doesn't proxy/stub library from the other company kick in?

推荐答案

COM运行时将使用typelib如果您通过在 HKCR下添加其CLSID {00020424-0000-0000-C000-000000000046} 将接口标记为使用标准封送处理程序(oleautomation) \Interfaces \ {iid} \ProxyStubClsid (其中{iid}是您的接口的GUID)。您还需要一个类型库注册,以便运行时提取参数信息,并且您只能使用某些子类型。还有一些(旧的)信息此处此处

The COM runtime will use typelib (oleautomation) marshalling if you mark your interface as using the standard marshaler by adding its CLSID {00020424-0000-0000-C000-000000000046} under HKCR\Interfaces\{iid}\ProxyStubClsid (where {iid} is the GUID of your interface). You'll need to have a typelibrary registered too, in order for the runtime to extract the parameter information, and you can only use a certain subset of types. There's some more (old) information here and here.

如果要使用自定义代理/ stub,由MIDL编译器从您的IDL生成,那么您需要将接口注册表项更改为该代理对象的CLSID。这使您可以使用更广泛的类型,例如原始数组。

If you want to use a custom proxy/stub, as generated by the MIDL compiler from your IDL, then you'll need to change the interface registry entry to be the CLSID of that proxy object instead. This enables you to use a wider range of types, e.g. "raw" arrays.

如果你支持 IMarshal ,那么这将是优先使用机制。这意味着您可以更改对象以聚合自由线程封送器(使用其实现 IMarshal ),而无需更改注册表中的任何内容。这将避免创建任何代理。

If you support IMarshal then that's what'll be used in preference to either of these mechanisms. This means you can change your object to aggregate the free-threaded marshaler (using its implementation of IMarshal) without having to change anything in the registry. This will avoid any proxies being created.

希望这有助于。

这篇关于COM如何选择如何封送接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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