Is it possible that JNI function return integer or boolean?

14,675

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.

Share:
14,675
MOHAMED
Author by

MOHAMED

Contact me on LinkedIn.

Updated on June 14, 2022

Comments

  • MOHAMED
    MOHAMED almost 2 years

    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?