How does COM select how to marshal an interface?

后端 未结 2 626
死守一世寂寞
死守一世寂寞 2020-12-29 14:57

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

  • typelib marshalling
  • proxy/stub marshalling
  • implementing IMarshal by the obj
2条回答
  •  长发绾君心
    2020-12-29 15:23

    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.

    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.

    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.

    Hope this helps.

提交回复
热议问题