问个关于jNI返回结构体的问题
如果要返回两个值则
[code=C/C++][/code]JNIEXPORT jobject JNICALL Java_com_sundy_jnidemo_CMFJ_getStruct
(JNIEnv *env, jobject obj)
{
//获取Java中的实例类
jclass objectClass = (*env)-> FindClass(env,"com/sundy/jnidemo/DiskInfo");
//获取Java中的构造函数
jmethodID init = (*env)->GetMethodID(env, objectClass , "<init>", "(Ljava/lang/String;I)V");
//调用构造函数创建对象,写入名字和序列号
jobject newObj = (*env)->NewObject(env, objectClass, init, (*env)->NewStringUTF(env, "my name is D:"), 10);
//返回创建的对象
return newObj;
}
那如果要返回四个则怎么写呢
[解决办法]
你的意思是那个java类的构造函数有4个参数吗?应该是下面这样子就可以了吧?
jmethodID init = (*env)->GetMethodID(env, objectClass , "<init>", "(Ljava/lang/String;III)V");
jobject newObj = (*env)->NewObject(env, objectClass, init, (*env)->NewStringUTF(env, "my name is D:"), 10, 0, 1);
http://stackoverflow.com/questions/7260376/how-to-create-an-object-with-jni