此文版权属于作者所有,任何人、媒体或者网站转载、借用都必须征得作者本人同意!
例子用一个实例:通过 jni 接口读取 java 对象。
#include <jni.h>
//=============================================================
// 场景 1,最常见
namespace t1 {
//=============================================================
#if 0
// java 类
public class Frame {
public int width = 0;
public int height = 0;
}
#endif
class Frame1 {
public:
jint width;
jint height;
};
//-------------------------------------------------------------
void getFrame(JNIEnv* env, jobject jframe, Frame1& frame) {
jclass cls = env->GetObjectClass(jframe);
{
jfieldID field = env->GetFieldID(cls, "width", "I");
frame.width = env->functions->GetIntField(env, jframe, field);
}
{
jfieldID field = env->GetFieldID(cls, "height", "I");
fr