从C#访问COM对象的最佳方式 [英] Best way to access COM objects from C#

查看:272
本文介绍了从C#访问COM对象的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划使用公开为COM对象的各种对象。为了使它们更容易使用,我想将它们包装为C#对象。什么是最好的办法了吗?

I am planning to use various objects that are exposed as COM objects. To make them easier to use, I'd like to wrap them as C# objects. What is the best approach for this?

推荐答案

如果该库已注册,您可以执行以下步骤来有Visual Studio生成一个互操作程序集为您提供:

If the library is already registered, you can perform the following steps to have Visual Studio generate an interop assembly for you:

  • 开启到Visual Studio项目。
  • 右键点击参考文献(就在你的解决方案资源管理器在该项目下),然后选择添加引用。
  • 选择COM选项卡。
  • 选择您要互操作的组件。
  • 选择确定。

这将是一个类或一组C#类的包装所有的COM接口的东西与普通的C#类。然后,你只需要使用它像任何其他C#库。如果参考进口运作良好,你可以探索它像任何其他的参考和方法/结构/班/常量应显示在该命名空间和智能。

This will be a class or set of C# classes that wrap all of the COM interface stuff with a normal C# class. Then you just use it like any other C# library. If the import of the reference worked well, you can explore it like any other reference and the methods/structs/classes/constants should show up in that namespace and intellisense.

这将让您一开始,至少。如果这是部署在企业环境中或者一个你可以控制的,这可能是你所需要的。

This will get you started, at least. If this is deployed in a corporate environment or one you can control, this may be all you need.

这篇关于从C#访问COM对象的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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