C++包装本机互操作企业规模
我想知道封装用 C++ 编写的大型库以使其可以在 C# 中访问的最佳方法是什么。
我以前做过互操作方面的工作,我喜欢 IJW。但我不确定如何用一个巨大的库来实现这种方法。我想知道是否有任何模式可以使用,否则我只需为 C++ 库中存在的每个类编写一个包装器,这并不是真正易于管理的。
另外,我不能只为图书馆提供一个单一的立面,因为它非常大,而且在这一点上势不可挡,所以任何想法都将不胜感激。
I want to know what is the best approach to wrapping a massive library written in C++ to make it accessible in C#.
I have done work with interop before, and I love IJW. But I am not sure of how to implement this approach with a huge library. I am wondering if there is any pattern to use, otherwise I just have to write a wrapper around every class that exists in the c++ library which is not really manageable.
Also, I cannot just provide a single facade into the library, as again, it is very big, and overwhelming at this point, so any ideas would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果性能是最关心的问题,请留在 IJW。如果您必须编写包装类或者更喜欢代码的可读性,我建议您创建 COM 包装器,因为有 IDE 向导可以帮助您生成代码,并且本机客户端也可以使用 COM。这就是 Microsoft 公开 Office 和 IE API 的方式。
If performance is a top concern, stay IJW. If you have to write wrapper classes or prefer more readability in your code, I suggest you create COM wrappers as there are IDE wizard to help you on generating code and COM can also be used by native clients. That's how Microsoft expose their APIs for Office and IE.
我经历过与你描述的类似的过程。在我们的情况下,没有简单的方法来包装类(IJW 对于大型 C++ 库来说不是一个可行的解决方案),因此我们确实包装了每个类。
我们首先围绕我们需要在应用程序中使用的核心类编写了一个包装器,并根据需要为其他类添加了包装器。这些东西对我们特别有帮助:
这涉及到很多工作,但是围绕每个类编写包装器是可以管理的,但(显然)只有在获得足够的好处时才值得。 “手动”编写包装器还使我们能够对互操作进行细粒度的控制,这对于我们项目的成功至关重要。
I've been through a process similar to what you describe. In our situation there was no easy way to wrap the classes (IJW isn't a workable solution for a large C++ library), so we did wrap every class.
We wrote a wrapper around first the core classes we needed to consume in our app and added wrappers for other classes as necessary. These things in particular helped us:
There is a lot of work involved, but writing a wrapper around every class is manageable, but (obviously) only worth while if you get sufficient benefit. Writing the wrapper "by hand" also gave us fine-grained control over the interop which was essential to the success of our project.