有没有办法从 C# 应用程序调用非托管(非 COM)dll?
有没有办法在我的 C# 应用程序中使用(引用)以非托管 C++(不是 COM 库)编写的 DLL?
当我尝试从 Visual Studio 中引用它时,收到“不是 COM 对象”错误消息。
也许有某种转换器\路由器可以 COMify 我的 DLL 引用? 我不知道 COM 和 COM 互操作是如何工作的,因为当我开始编程时,这对我来说已经没有必要了。
谢谢。
Is there a way to use (reference) a DLL written in an unmanaged C++ (not a COM library) in my C# application?
When I try to reference it from within Visual Studio, I get 'not a COM object' error message.
Maybe there is some kind of translator\router that would COMify my DLL reference?
I have no clue how COM and COM interop work, since I started programming when this was already unnecessary for me.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 DllImport 属性。 下面是 Win32 PostMessage 函数的示例:
You need to use the DllImport attribute. Here's an example for the Win32 PostMessage function:
请参阅 MSDN 上的“使用非托管 DLL 函数”主题:
http://msdn.microsoft.com/en-us/library/26thfadc.aspx
无需添加任何COM代理,.NET可以使用[DllImport] 属性。 您还可以通过指定其他属性来完全控制 .NET 和非托管 DLL 之间的编组。
See "Consuming unmanaged DLL functions" topic on MSDN:
http://msdn.microsoft.com/en-us/library/26thfadc.aspx
There is no need to add any COM proxy, .NET can consume DLLs directly using the [DllImport] attribute. You also have full control over the marshalling between .NET and the unmanaged DLL by specifying additional attributes.
Joe 已经回答了这个问题,所以我要补充一下 - 为了节省自己一些时间,而不必挖掘和破坏函数签名,P/Invoke 有一个相当完整的 Win32 签名库,以 wiki 的形式还有一个 Visual Studio 插件!
请访问 P/Invoke 查看
Joe already answered this, so I'm going to tack this on - to save yourself some time and not having to dig up and mangle function signatures, P/Invoke has a pretty complete library of Win32 signatures, in the form of both a wiki AND a Visual Studio plugin!
Check it out at P/Invoke