用.NET COM .dll替换本机C ++ COM .dll [英] Replace native C++ COM .dll with .NET COM .dll

查看:62
本文介绍了用.NET COM .dll替换本机C ++ COM .dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的客户有旧的Win32客户端,这些客户端使用我们提供的本机C ++ COM注册的.dll。

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

我们要用.NET版本替换本机.dll。因此,我们构建了.NET dll,并COM对其进行了注册。我们有本机C ++测试客户端,能够处理从旧.dll到新.dll的交换,但是...似乎我们需要对其进行重新编译才能正常工作。

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.

推荐答案

也许您忘记了在接口和类声明上使用[Guid]属性。它们必须匹配IDL中用于旧C ++项目的IID和CLSID。或功能不再相同。或者它们没有相同的DISPID,以防客户端代码晚绑定使用它们。

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.

避免这种情况的最佳方法是在.NET项目中添加对旧类型库的引用,以便可以在代码中使用旧接口。您仍然需要正确实现接口的类的[Guid],以便它具有正确的CLSID。

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.

您可以使用OleView.exe工具View +类型库比较新旧类型库。复制/粘贴生成的IDL并进行比较。您可以从Regasm.exe / tlb获得新的类型库。任何不匹配都可能(并且很可能会)成为问题。

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.

这篇关于用.NET COM .dll替换本机C ++ COM .dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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