13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

134Chapter 5The Sun Microsystems Java Software <str<strong>on</strong>g>Development</str<strong>on</strong>g> KitExample 5.8 Header file for GetUser native methods (GetUser.h)/* DO NOT EDIT THIS FILE - it is machine generated */#include /* Header for class GetUser */#ifndef _Included_GetUser#define _Included_GetUser#ifdef __cplusplusextern "C" {#endif/** Class: GetUser* Method: getUserName* Signature: ()Ljava/lang/String;*/JNIEXPORT jstring JNICALL Java_GetUser_getUserName(JNIEnv *, jobject);#ifdef __cplusplus}#endif#endifExample 5.9 Native method’s C implementati<strong>on</strong> file (GetUser.c)#include "GetUser.h"#include JNIEXPORT jstring JNICALLJava_GetUser_getUserName(JNIEnv *jenv, jobject obj){char buffer[L_cuserid + 1];cuserid(buffer);}return (*jenv)->NewStringUTF(jenv, buffer);All of the Java class member data and Java class methods may be reachedthrough the JNIEnv pointer argument. There are also methods provided byJNI itself. One of those is NewStringUTF(). Remember that Java Strings areUnicode, not 8-bit ASCII, so you must c<strong>on</strong>vert to and from Unicode (UTF-8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!