Wednesday, April 24, 2013

jni jnienv UnregisterNatives example c c++ java


UnregisterNatives


jint UnregisterNatives(JNIEnv *env, jclass clazz);

Unregisters native methods of a class. The class goes back to the state before it was linked or registered with its native method functions.

This function should not be used in normal native code. Instead, it provides special programs a way to reload and relink native libraries. (UnregisterNatives)
LINKAGE:
Index 216 in the JNIEnv interface function table.
PARAMETERS of UnregisterNatives

env: the JNI interface pointer.

clazz: a Java class object.

RETURNS of UnregisterNatives

Returns “0” on success; returns a negative value on failure.
Example of UnregisterNatives
jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
 JNIEnv *env;
 if ( vm->GetEnv((void **)&env, JNI_VERSION_1_6) ) return JNI_ERR;

 jclass clazz = env->FindClass(gClassName);
 env->RegisterNatives(clazz, gMethods, NELEM(gMethods));

 return JNI_VERSION_1_6;
}

void JNI_OnUnload(JavaVM* vm, void* reserved)
{
 JNIEnv *env;
 if (vm->GetEnv((void **)&env, JNI_VERSION_1_6)) return;
 jclass cls = env->FindClass(gClassName);
 env->UnregisterNatives(cls);
}