结束了在Java或.NET中的C ++ API结束了、Java、API、NET

由网友(late summer(夏末))分享简介:有没有人成功地包裹在Java或.NET中的C ++ API?我提供了一个C ++ API编写插件的应用程序。我想要做的是从.NET或Java访问API。Has anyone successfully "wrapped up" a C++ API in Java or .NET? I have an applicati...

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

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.

请问我需要使用COM,还是有更简单/更好的方法?

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

推荐答案

如果你有一个非常简单的方法签名(即方法,这需要返回原始类型,如int,char的[],无效* ...等) ,这是相当容易做到在.NET中,仍然可能的,但有点难以在Java中使用JNI。

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.

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

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.

编辑: 如果该方法有它的会是更有趣的C ++模板参数,因为C ++模板系统是从C#或Java泛型很大的不同,它仅仅是一个编译时的机制。基本上,这意味着该方法的签名或者每次通过不同的数据类型为模板参数时类是不同的。这使得该方法不可能在C#或Java包。

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.

阅读全文

相关推荐

最新文章