Saturday, April 20, 2013

jni jnienv GetObjectClass example c c++ java


GetObjectClass


jclass GetObjectClass(JNIEnv *env, jobject obj);

Returns the class of an object.
LINKAGE:
Index 31 in the JNIEnv interface function table.
PARAMETERS of GetObjectClass

env: the JNI interface pointer.

obj: a Java object (must not be NULL).

RETURNS:

Returns a Java class object.
Example - GetObjectClass

/**
 * Get the methodID of an object's method.
 */
jmethodID cbgp_jni_get_object_method(JNIEnv * jEnv, jobject joObject,
         const char * pcMethod,
         const char * pcSignature)
{
  jclass jcObject;
  jmethodID jmObject;

  /* Get the object's class */
  if ((jcObject= (*jEnv)->GetObjectClass(jEnv, joObject)) == NULL)
    return NULL;

  /* Get the method */
  if ((jmObject= (*jEnv)->GetMethodID(jEnv, jcObject, pcMethod,
         pcSignature)) == NULL)
    return NULL;

  return jmObject;
}