在C#中使用COM DLL [英] Using COM dll in C#

查看:233
本文介绍了在C#中使用COM DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有这是用C ++编写,并已使用VB编写的6.0的应用程序COM DLL。我公司的计划写在.Net平台的应用程序的新版本。

We have COM dll which was written in C++ and has been used by the apps written in vb 6.0. My company plans write the newer versions of apps in .Net platform.

至于表现而言,在C#项目中使用COM DLL时,我应该怎么从下面

As far as the performance is concerned, when using a COM dll in a C# project, what should I choose from the 3 options listed below


  1. 3个选项中选择刚才添加DLL作为一个COM引用

  2. 写包装DLL使用C ++ / CLI

  3. 使用生成一个TLBIMP.EXE包装DLL

或者是还有什么其他的选择?结果
感谢。

Or are there any other options?
Thanks.

推荐答案

在C ++ / CLI编写的包装是不是可能会更快,在CLR的COM互操作编组在很大程度上优化。它会自动生成从您创建当您添加到COM服务器的引用互操作库机器代码存根。一个做了很多工作,这是很无形的,很难做到自己,涉及到的异常。

Writing a wrapper in C++/CLI isn't that likely to be faster, the COM interop marshaller in the CLR is heavily optimized. It auto-generates machine code stubs from the interop library that you create when you add a reference to the COM server. A does a lot more work that's pretty invisible and very hard to do yourself, related to exceptions.

它确保失败的HRESULT被正确地转换为托管异常和管理异常不能泄漏到COM服务器代码。在让快解决你必须这样做时会让你砍喜欢这个角落。现在,你已经得到的东西那是快,但不可靠的。获得在非托管代码托管异常是难上加难诊断,所有的环境消失了。

It makes sure that failure HRESULTs are properly converted to managed exceptions and that managed exceptions cannot leak into the COM server code. The "make it fast" resolve you'll have when you do this will make you cut corners like this. Now you've got something that's fast but unreliable. Getting a managed exception in unmanaged code is brutally hard to diagnose, all the context is gone.

选项1和3是一样的。无论生成interop库时,IDE只需运行TLBIMP为相当于你。

Options 1 and 3 are the same thing. Both generate the interop library, the IDE simply runs the equivalent of Tlbimp for you.

通常指引适用于这里。首先做了简单的事情,互操作的库是难以置信的简单。只考虑做真的很难的事情时,你可以实际测量PERF的问题的有一个现实的想法去做这件事的。我从来没有见过一次有人决定一个C ++ / CLI的包装是必要的。

The usual guidance applies here. Do the simple thing first, the interop library is incredibly simple. Only contemplate doing the really hard thing when you can actually measure perf problems and have a realistic idea what to do about it. I've never once seen anybody decide that a C++/CLI wrapper was necessary.

这篇关于在C#中使用COM DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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