Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that JNI function return integer or boolean?

JAVA Code

boolean b = invokeNativeFunction();
int i = invokeNativeFunction2();

C code

jboolean Java_com_any_dom_Eservice_invokeNativeFunction(JNIEnv* env, jobject obj) {
    bool bb = 0;
    ...
    return // how can return 'bb' at the end of the function?
}

jint Java_com_any_dom_Eservice_invokeNativeFunction2(JNIEnv* env, jobject obj) {
    int rr = 0;
    ...
    return // how can return 'rr' at the end of the function?
}

Is it possible that JNI function return integer or boolean? If yes, How I can do that?

like image 411
MOHAMED Avatar asked Jan 13 '15 15:01

MOHAMED


1 Answers

Yes, just return the value directly.

JNIEXPORT jint JNICALL Java_com_example_demojni_Sample_intMethod(JNIEnv* env, jobject obj,
    jint value) {
    return value * value;
}

JNIEXPORT jboolean JNICALL Java_com_example_demojni_Sample_booleanMethod(JNIEnv* env,
    jobject obj, jboolean unsignedChar) {
    return !unsignedChar;
}

There is a map relation between Java primitive type and native type, reference here.

like image 116
alijandro Avatar answered Oct 19 '22 23:10

alijandro