如何从C ++调用Java函数? [英] How to call Java functions from C++?

查看:115
本文介绍了如何从C ++调用Java函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从C ++应用程序调用Java函数?



我知道从CMD(或类似技术)调用它们,但我不想使用它们。

解决方案

例如,选中从C创建JVM 。它显示了创建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函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆