我是否应该为非托管 C++ 创建一个 C++/CLI 包装器 DLL? DLL?
我获得了一个包含多个类的非托管 C++ DLL。
我需要能够在 C# 中使用其中一些类。根据我迄今为止的研究,听起来我需要创建一个 C++/CLI 包装器 DLL 来处理托管类型和非托管类型之间的转换。我见过一些示例,其中有人基本上会创建每个类的 C++/CLI 版本,并且它将包含非托管 C++ 类型的实例。实施我在这里尝试做的事情的最佳方法是什么?非托管 DLL 中可能提供了 10-15 个类。现在我只需要使用其中的一些,但将来可能需要使用更多。谢谢!
I have been provided with an unmanaged C++ DLL that contains several classes.
I need to be able to use some of these classes in C#. Based on my research so far, it sounds like I need to create a C++/CLI wrapper DLL that would handle converting between managed and unmanaged types. I have seen some examples where someone would basically create a C++/CLI version of each class and it would contain an instance of the unmanaged C++ type. What is the best way to implement what I am trying to do here? There are maybe 10-15 classes provided in the unmanaged DLL. Right now I only need to use a few of them but may need to use more in the future. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您需要为此库创建 C++/CLI 包装器,并在此包装器内部使用非托管类。对于公开 C 风格 API 的非托管库,还有 PInvoke 选项,但它不适用于 C++ 类。
如果您想在本机 COM 客户端和 .NET 中使用该库,您还可以考虑制作 COM 包装器。但我认为制作 C++/CLI 包装器是更简单的任务。
Yes, you need to create C++/CLI wrapper for this library, and use unmanaged classes internally in this wrapper. For unmanaged library which exposes C-style API, there is also PInvoke option, but it doesn't work for C++ classes.
You can also think about making COM wrapper, it you want to use this library both in native COM clients and .NET. But making C++/CLI wrapper is more simple task, I think.