package javabeans;
public class Struct {
public long id;
public int age;
public native static Struct newStruct(long id, int age);
}
package javabeans;
public class MyStruct {
private Struct struct;
static{
System.loadLibrary("struct_test2");
}
public native void setStruct(Struct struct);
public native Struct getStruct();
public void setStruct_J(Struct struct){
this.struct = struct;
}
public Struct getStruct_J(){
return this.struct;
}
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
/* Header for class javabeans_MyStruct */
#ifndef _Included_javabeans_MyStruct
#define _Included_javabeans_MyStruct
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: javabeans_MyStruct
* Method: setStruct
* Signature: (Ljavabeans/Struct;)V
*/
JNIEXPORT void JNICALL Java_javabeans_MyStruct_setStruct
(JNIEnv *, jobject, jobject);
/*
* Class: javabeans_MyStruct
* Method: getStruct
* Signature: ()Ljavabeans/Struct;
*/
JNIEXPORT jobject JNICALL Java_javabeans_MyStruct_getStruct
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
/* Header for class javabeans_Struct */
#ifndef _Included_javabeans_Struct
#define _Included_javabeans_Struct
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: javabeans_Struct
* Method: newStruct
* Signature: (JI)Ljavabeans/Struct;
*/
JNIEXPORT jobject JNICALL Java_javabeans_Struct_newStruct
(JNIEnv *, jclass, jlong, jint);
#ifdef __cplusplus
}
#endif
#endif
Struct_Imp.cpp:
#include "javabeans_Struct.h"
JNIEXPORT jobject JNICALL Java_javabeans_Struct_newStruct
(JNIEnv *env, jclass jc_this, jlong jl_id, jint ji_age){
jmethodID jm_init = env->GetMethodID(jc_this, "<init>", "()V"); //构造器方法
jobject jobj_this = env->NewObject(jc_this, jm_init); //创建新对象
jfieldID jf_id = env->GetFieldID(jc_this, "id", "J");
jfieldID jf_age = env->GetFieldID(jc_this, "age", "I");
env->SetLongField(jobj_this, jf_id, jl_id);
env->SetIntField(jobj_this, jf_age, ji_age);
return jobj_this;
}
MyStruct_Imp.cpp:
#include "javabeans_MyStruct.h"
struct {
long id;
int age;
}Struct;
JNIEXPORT void JNICALL Java_javabeans_MyStruct_setStruct
(JNIEnv *env, jobject obj_this, jobject jobj_mystruct_struct){
jclass jc_mystruct = env->FindClass("javabeans/MyStruct");
jfieldID jf_mystruct_struct = env->GetFieldID(jc_mystruct, "struct", "Ljavabeans/Struct;");
env->SetObjectField(obj_this, jf_mystruct_struct, jobj_mystruct_struct);
}
JNIEXPORT jobject JNICALL Java_javabeans_MyStruct_getStruct
(JNIEnv *env, jobject obj_this){
jclass jc_mystruct = env->FindClass("javabeans/MyStruct");
jfieldID jf_mystruct_struct = env->GetFieldID(jc_mystruct, "struct", "Ljavabeans/Struct;");
jobject jobj_struct = env->GetObjectField(obj_this, jf_mystruct_struct);
return jobj_struct;
}