如何在 .NET 中使用托管 DLL 中的非托管类?
我有一个非托管类,我试图从托管 DLL 文件中导出它。 我正在尝试在另一个托管 DLL 文件中使用非托管类。 但是,当我尝试执行此操作时,我收到链接错误。
我已经多次使用非托管 DLL 文件执行此操作,因此我知道它是如何工作的。 我知道如何在托管类中使用“公共引用”等。
我需要在某个地方设置一些标志吗? 或者我必须做一些 DllImport 魔法吗?
这是在 .NET 2.0 和 Visual Studio 2005 上。
I have an unmanaged class that I'm trying to dllexport from a managed DLL file. I'm trying to use the unmanaged class in another managed DLL file. However, when I try to do this I get link errors.
I've done this lots of times with unmanaged DLL files, so I know how that works. I know how to use "public ref", etc. in managed classes.
Is there some flag somewhere I need to set? Or do I have to do some DllImport magic?
This is on .NET 2.0 and Visual Studio 2005.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想从托管代码中使用非托管类,您可以:
如果您需要有关第二个选项的更多信息,我可以查找一些旧链接来更多地解释此技术。
If you want to use an unmanaged class from managed code, you can:
If you need more information on the second option, I could look up some old links that explained this technique more.
您需要对非托管库或 COM 组件使用互操作程序集。 这是一个链接,其中包含有关此内容的详细信息。
You need to use an interop assembly for unmanaged libraries or COM components. Here is a link with good information regarding this.
如果它是 COM DLL 文件,那么您可以使用 COM .NET 互操作性。 Stack Overflow 问题是否有访问 C++ 本机 COM 函数以与 C# 进行互操作的最佳实践? 是另一个问题回答这个问题的问题。
If it is a COM DLL file then you can use COM .NET interoperability. Stack Overflow question Is there a best practice for accessing C++ native COM functions to interop from C#? is another question which answers this.