Android (Java) Learning Note 258:jni hello.c (c code function Implementation) Pointer syntax parsing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.