jni/cyberlevel9.c:17:31: error: request for member 'NewDirectByteBuffer' in something not a structure or union
jni/cyberlevel9.c:18:28: error: request for member 'NewGlobalRef' in something not a structure or union
这是代码的问题部分:
JNIEXPORT jobject JNICALL Java_com_cyberbg_natcamlevel9_NativeCameraLevel9Start_allocNativeBuffer(JNIEnv* env, jobject this, jlong size)
{
void* buffer = malloc(size);
jobject directBuffer = env->NewDirectByteBuffer(buffer, size);
jobject globalRef = env->NewGlobalRef(directBuffer);
return globalRef;
//return (NewDirectByteBuffer*)(*env)->NewDirectByteBuffer(buffer, size);
}
答案 0 :(得分:6)
来自C程序的JNI调用看起来像
(*env)->fun(env, p1, ...)
您的调用样式在C ++中是可以的,其中jni.h
中定义了一个特殊的包装类:
env->fun(p1, ...)
您只需将jni/cybrrlevel9.c
重命名为jni/cyberlevel9.cpp
或者,
jobject directBuffer = (*env)->NewDirectByteBuffer(env, buffer, size);
jobject globalRef = (*env)->NewGlobalRef(env, directBuffer);