How do I register a proxy/stub for a COM interface

2019-06-02 17:20发布

问题:

There's Another Company that ships the product that consumes IAnotherCompanyInterface. We want to ship a COM object that implements IAnotherCompanyInterface. That interface is not Automation-compatible, so the next easiest option to enable marshalling is using a proxy/stub. Another Company doesn't ship the proxy/stub and doesn't want to.

Compiling and registering the proxy/stub is not a problem by itself but consider the following situation. There's our company shipping a COM object implementing IAnotherCompanyInterface and the ThirdPartyCompany that does the same. So both components might end up being deployed on the same machine.

Proxy/stub registration is system-wide for an interface. How should their proxy/stub implementations co-reside?

回答1:

You can skip the registry in your client altogether by using reg-free COM or activation context. You can provide "custom" comInterfaceExternalProxyStub entries in the manifest file that reference you proxy/stub implementation.



回答2:

It's a while since I worked with this stuff, so this is "thinking aloud" but hopefully it'll be some help...

I presume that you can see a type library that describes the interface you want to implement. If so, load it into oleview.exe. Copy the IDL it gives you into a new .idl file of your own, and base your own implementation on that file.

I know your question is actually about the proxy/stub DLL. That's fine. Yours will be generated along with your actual COM server, and it will work on your machines and those of your users. If your code is installed on a machine that also has "Another Company's" bits installed, it shouldn't matter...

The proxy/stub is just a bit of code that tells COM how to transfer params and return values between COM client and COM server. If yours is built from IDL that was generated from their typelib, they will be functionally equivalent. Your COM server can be successfully called via their proxy/stub and vice versa.

However, if they change their proxy/stub, they might no longer be functionally equivalent. But in that case, they probably also changed the interface and your COM server would no longer be usable by their client.