自动生成的DLL在Visual Studio 2010速成C#包装类?

自动生成的DLL在Visual Studio 2010速成C#包装类?

问题描述:

我被我的一个同事告诉Visual Studio中允许一个指向的.dll 和自动生成奇迹般地一个C#包装类。这真的可能吗?如果是这样,一个人如何去实现呢?我浏览网页,但都未能拿出任何东西!

I was told by a colleague of mine that Visual Studio allows one to point to a .dll and auto-magically generate a C# wrapper class. Is this really possible? And if so, how does one go about achieving this? I've browsed the web, but have failed to come up with anything!

谢谢大家!

想我会分享这些资源,以及,

Figured I'd share these resources as well,

  • How to: Create COM Wrappers
  • And courtesy of @Darin, Consuming Unmanaged DLL Functions

三种情况:


  1. 的DLL代表托管程序=>您直接引用在您的项目,并用它

  2. 的DLL代表一个COM对象=>你可以使用 tlbimp.exe是实用工具生成的托管包装

  3. 的DLL代表与一些导出函数的非托管库。这是最艰难的。没有工具。您将有咨询库的文档就知道导出的函数名称和参数,并建立管理的P / Invoke包装。您可以使用 DUMPBIN.EXE 实用程序查看导出的函数列表。这里是文章 MSDN上有关的不同步骤。

  1. The DLL represents a managed assembly => you directly reference it in your project and use it
  2. The DLL represents a COM object => you could use the tlbimp.exe utility to generate a managed wrapper
  3. The DLL represents an unmanaged library with some exported functions. That's the toughest one. There are no tools. You will have to consult the documentation of the library to know the exported function names and parameters and build managed P/Invoke wrappers. You could use the dumpbin.exe utility to see a list of exported functions. Here's an article on MSDN about the different steps.