用.NET实现替换C ++ ActiveX组件? [英] Replacing a C++ ActiveX component with a .NET implementation?

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

问题描述

我有现有的托管和非托管软件使用由第三方提供的ActiveX组件来执行一些通信,但现在要求通过我的应用程序路由此通信。



理想情况下,我可以安装一个.NET组件,它将暴露完全相同的界面,并且可以作为替换使用。



但是




  • 如何最好地确保我的


  • 如何确保应用程序使用我的实现接口而不是旧实现?是否只需要注册我的实现,并取消注册旧版本?


  • 如何确保它是插入替换,


  • 如何确保非托管代码可以正常使用?




注意:我可以要求使用.NET 4.0,如果这样做会更简单。



编辑 using-my-net-activex-control-does-not-registe>如何调试为什么使用我的.NET ActiveX控件的VB6应用程序不会注册事件? 2天后。

解决方案


  1. 使用ActiveX组件的类型库。使用Tlbimp.exe导入它以获取互操作库,如果你自己使用这个组件,你可能已经有了。


  2. 您的实现必须使用与ActiveX组件完全相同的GUID和ProgID。使用OleView.exe,File + View Typelib并选择ActiveX DLL以查看GUID。 ProgID更困难,最好的事情是看注册表如何修改与SysInternals的ProcMon实用程序,当您注册ActiveX DLL与Regsvr32.exe。


  3. 如第2点所述。

  4. 最后,Regasm.exe需要完成相同的更改。


    使这项工作进展顺利,您真的必须知道接口做什么。如果ActiveX组件实际上是一个进程外服务器(EXE),则不能使此工作。


    I have existing managed and unmanaged software using an ActiveX component supplied by a third party to perform some communications, but it is now required that this communication be routed through my application.

    Ideally I'd be able to install a .NET component which will expose exactly the same interface, and will be usable as a drop-in replacement.

    However, I am running into the limits of my understanding of COM, which admittedly is quite minimal.

    • How best to ensure that my implementation of the interface is 100% binary compatible with the existing object?

    • How do I ensure that applications use my implementation of the interface instead of the legacy implementation? Is it simply a matter of registering my implementation, and unregistering the legacy one?

    • How do I ensure it's a "drop-in" replacement, and requires no changes to existing software?

    • How do I ensure unmanaged code can use it without issue?

    Note: I am able to require that .NET 4.0 be used, if that will make things simpler.

    Edit: Bounty will be moved here How to debug why a VB6 application using my .NET ActiveX control does not register for events? after 2 days.

    解决方案

    1. Use the type library of the ActiveX component. Import it with Tlbimp.exe to get the interop library, you probably already have it if you use this component yourself. Implement your own code by inheriting the interfaces in that type library.

    2. Your implementation must use the exact same GUIDs and ProgIDs as the ActiveX component. Use OleView.exe, File + View Typelib and select the ActiveX DLL to see the GUIDs. The ProgIDs are more difficult, best thing to do is to watch how the registry is modified with the SysInternals' ProcMon utility when you register the ActiveX DLL with Regsvr32.exe. Ultimately, the exact same changes need to be made by Regasm.exe when you register your replacement.

    3. As point 2.

    4. Same, the registration gets unmanaged code to use yours instead.

    To make this work out well, you really have to know what the interfaces do. You cannot make this work if the ActiveX component is actually an out-of-process server (an EXE).

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

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