2011/11/22

Get Thread JNIEnv

This is an example shows how:

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { cached_jvm = jvm; /* cache the JavaVM pointer */ return JNI_VERSION_1_2; } static void Some_Function() { (*cached_jvm)->AttachCurrentThread(cached_jvm, &env, NULL); (*env)->MonitorEnter(env, callbackInst); jclass cls = (*env)->GetObjectClass(env, callbackInst); jmethodID id = (*env)->GetMethodID(env, cls, "callback", "(I)V"); (*env)->CallVoidMethod(env, callbackInst, id, (int)l); (*env)->MonitorExit(env, callbackInst); }

No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...