1. Let's take a look at the code for the implementation of the C feature in the previous lecture:
(1) HELLO.C:
1#include <jni.h>2 3 Char*Gethello ()4 {5 ////////6 return "Hello Android from C";7 }8 9 Ten //JNI protocol to Java calls One //return type method name (Java_ package name (using "_" to split the package name) _ Class Name _ Method name (parameter) A - //jnienv* ENV JNI structure data, JNI system implementation; Obj Java object calls the object of the Jni method -Jstring JAVA_COM_HIMI_HELLOWORLD_MAINACTIVITY_GETHELLOFROMC (jnienv*env, Jobject obj) the { - Char* res = Gethello ();//get to C code string result - /** - * (**env). GetVersion (env); + * (*env)->getverison (env); - */ + //jstring (*newstringutf) (jnienv*, const chat*); AJstring JREs = (* *env). Newstringutf (env,res); at - returnJREs; -}
jstring : Data type is void* (pointer to an empty area, initialized)
Under the jni.h file:
typedef void* Jobject;
typedef jobject Jclass;
typedef jobject Jstring;
• jnienv* env :
Jninativeinterface struct: Description jninativeinterface is a struct
typedef const struct JNINATIVEINTERFACE* jnienv;: Description jnienv is a struct pointer (this struct is jninativeinterface)
This time jnienv* env is equivalent to:
jninativeinterface** env;: That is, the Env is defined as a pointer to a struct pointer (double pointer)
If you want to use Env to access the members of the Jninativeinterface struct newstringutf ( except Newstringutf Here is a function pointer ) .
(**env). NEWSTRINGUTF (jnienv*, const char*);
Android (Java) Learning Note 258:jni hello.c (c code function Implementation) Pointer syntax parsing