I'm having trouble finding the right documentation for passing a char buffer from JNI method to Java method. Here's the code
jint JNICALL Java_foo_package_MyJavaClass_myNativeMethod(JNIEnv *jenv, jobject jobj)
{
jclass clazz = (*jenv)->GetObjectClass(jenv, jobj);
// MyJavaClass method: private void addData(byte[] data)
jmethodID mid = (*jenv)->GetMethodID(jenv, clazz, "addData", "([B)V");
assert(mid);
const char buf[] = { 0, 1, 2, 3, 42 };
const size_t buf_len = sizeof buf;
(*jenv)->CallVoidMethod(jenv, jobj, mid, buf /* obviously wrong */ );
return 0;
}
Is CallVoidMethod the right function to use here, what's the correct thing to pass to it, how to allocate it, and how (if at all) it should be freed?
A code snippet would probably be the most compact answer, with a few words explaining how ownership of objects goes.
Cis Javachar, which is 16 bits and represents a unicode character. Ccharrepresents a native byte (8 bits assumed in this case), often (but not here) used to represent 8 bit character of any 8 bit encoding.charholds a UTF-16 code-unit; One or two of which represents a Unicode character. Character.toChars(int) provides a succinct explanation.