Replace native C++ COM .dll with .NET COM .dll

╄→尐↘猪︶ㄣ 提交于 2019-12-13 00:05:20

问题


Our customer has old Win32 clients that use a native C++ COM registered .dll that we provide.

We want to replace the native .dll with a .NET version. So we've built the .NET dll and COM registered it. We have native C++ test clients that are able to handle the swap from the old .dll to the new, but... it seems we need to recompile them for it to work.

Is there some logical reason why we need to recompile the test client, or are we doing something wrong?

We cannot require our customer to recompile their clients.


回答1:


Maybe you forgot to use the [Guid] attribute on the interface and the class declarations. They have to match the IIDs and CLSID that were used in the IDL for the old C++ project. Or the functions are not in the same order anymore. Or they don't have the same DISPID, in case the client code uses them late-bound.

The best way to avoid this is to add a reference to the old type library in your .NET project so you can use the old interfaces in your code. You still need to get the [Guid] of the class that implements the interfaces right so it has the correct CLSID.

You can use the OleView.exe tool, View + Type Library to compare the old and the new type library. Copy/paste the generated IDL and diff it. You get the new type library from Regasm.exe /tlb. Any mismatch might (and likely will) be a problem.



来源:https://stackoverflow.com/questions/5502629/replace-native-c-com-dll-with-net-com-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!