问题描述
如何从C ++应用程序调用Java函数?
我知道从CMD(或类似技术)调用它们,但我不想使用它们。
例如,选中。它显示了创建JVM和调用方法的示例过程。如果JVM已经存在;例如你的C程序被Java程序调用(回调情况),你可以缓存JNIEnv *指针。
作为一个建议,从C / C ++小心缓存指向JVM的指针,有一些语义涉及到什么可以缓存,以后可以调用。为此,正如Brian Agnew指出的,检查JNI参考。
How can I call Java functions from a C++ application?
I know about calling them from CMD (or similar techniques), but I would rather not use them.
As an example, check Creating a JVM from C. It shows a sample procedure to create a JVM and invoke a method. If the JVM already exists; e.g. your C program is invoked by the Java program (callback situation), you can cache the JNIEnv* pointer.
As an advice, be careful caching pointers to the JVM from C/C++, there are some semantics involved as to what you can cache and it could be invoked later on. For that, as Brian Agnew pointed out, check the JNI reference.
这篇关于如何从C ++调用Java函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!