用Java或.NET包装C ++ API(Wrapping up a C++ API in Java or .NET)

编程入门 行业动态 更新时间:2024-10-28 08:30:59
用Java或.NET包装C ++ API(Wrapping up a C++ API in Java or .NET)

有没有人用Java或.NET成功“包装”了C ++ API? 我有一个应用程序提供了用于编写插件的C ++ API。 我想要做的是从.NET或Java访问该API。

我需要使用COM吗,还是有更简单/更好的选择?

Has anyone successfully "wrapped up" a C++ API in Java or .NET? I have an application that provides a C++ API for writing plug-ins. What I'd like to do is access that API from .NET or Java.

Would I need to use COM, or are there simpler/better alternatives?

最满意答案

如果你有一个非常直接的方法签名(即接受和返回基本类型,如int,char [],void * ...等)的方法,在.NET中这样做相当容易,但仍然可能,但有点用JNI在Java中更难。

但是,如果您的类方法使用现代C ++编程技术,例如boost共享指针和STL容器,那么这是一个非常不同的故事。 在这种情况下,你需要非常小心内存管理。

编辑:如果方法有C ++模板参数,它会更有趣,因为C ++模板系统与C#或Java泛型非常不同,因为它只是编译时机制。 基本上这意味着每次将不同的数据类型传递给模板参数时,方法或类的签名都不相同。 这使得该方法无法用C#或Java进行封装。

If you have a very straight forward method signatures (i.e. methods that takes and returns primitive types such as int, char[], void* ... etc), it is reasonably easy to do so in .NET and still possible but a bit harder in Java with JNI.

However, if your class methods uses modern C++ programming techniques such as boost shared pointers and STL containers then it is a very different story. You will need to be really careful with memory management in this case.

EDIT: It is gonna be even more interesting if the method has C++ template arguments because C++ template system is very different from C# or Java generics in that it is only a compile time mechanism. Basically this means the signature of the method or class is different every time you pass a different data type to the template argument. This made the method impossible to wrap in C# or Java.

更多推荐

本文发布于:2023-08-05 12:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1432315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   Java   Wrapping   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!