Subject: How to get a String from JNI? 2005-09-09 - By Edward King
Back I want to get a returned String from JNI, but I don't know how to do it, my code are follows: //MyNative.java public class MyNative{ public String test1(String s){ return test11(s); } private native String test11(String s); static{ System.loadLibrary( "MyNative" ); } public static void main( String[] args ){ MyNative obj = new MyNative(); String c=obj.test1("abc"); System.out.println("--"+c); } }
//MyNative.h /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class MyNative */ #ifndef _Included_MyNative #define _Included_MyNative #ifdef __cplusplus extern "C" { #endif /* * Class: MyNative * Method: test11 * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_MyNative_test11 (JNIEnv *, jobject, jstring);
#ifdef __cplusplus } #endif #endif
//MyNative.c #include <stdio.h> #include "MyNative.h" JNIEXPORT jstring JNICALL Java_MyNative_test11 (JNIEnv *env, jobject obj, jstring s){ //How to realize return String to Java???,such as return a string "hello world",how to realize this function,please give example code. }
Thanks in advance!
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <META content="MSHTML 6.00.2800.1515" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face="Times New Roman" color=#0000ff size=2>I want to get a returned String from JNI, but I don't know how to do it, my code are follows:</FONT><FONT face="Times New Roman" color=#0000ff size=2><BR>//MyNative.java<BR>public class MyNative{ <BR> public String test1(String s){<BR> return test11(s);<BR> }<BR> private native String test11(String s); <BR> static{<BR> System.loadLibrary( "MyNative" );<BR> } <BR> public static void main( String[] args ){<BR> MyNative obj = new MyNative();<BR> String c=obj.test1("abc");<BR> System.out.println("--"+c);<BR> }<BR>}</FONT></DIV> <DIV> </DIV> <DIV><FONT face="Times New Roman" color=#0000ff size=2>//MyNative.h<BR>/* DO NOT EDIT THIS FILE - it is machine generated */<BR>#include <jni.h><BR>/* Header for class MyNative */<BR>#ifndef _Included_MyNative<BR>#define _Included_MyNative<BR>#ifdef __cplusplus<BR>extern "C" {<BR>#endif<BR>/*<BR> * Class: MyNative<BR> * Method: test11<BR> * Signature: (Ljava/lang/String;)Ljava/lang/String;<BR> */<BR>JNIEXPORT jstring JNICALL Java_MyNative_test11<BR> (JNIEnv *, jobject, jstring);</FONT></DIV> <DIV> </DIV> <DIV><FONT face="Times New Roman" color=#0000ff size=2>#ifdef __cplusplus<BR>}<BR>#endif<BR>#endif</FONT></DIV> <DIV> </DIV> <DIV><FONT face="Times New Roman" color=#0000ff size=2>//MyNative.c<BR>#include <stdio.h><BR>#include "MyNative.h"<BR>JNIEXPORT jstring JNICALL Java_MyNative_test11<BR> (JNIEnv *env, jobject obj, jstring s){<BR> //How to realize return String to Java???,such as return a string "hello world",how to realize this function,please give example code.</FONT></DIV> <DIV><FONT face="Times New Roman" color=#0000ff size=2>}</FONT></DIV> <DIV><FONT face="Times New Roman" color=#0000ff size=2></FONT> </DIV> <DIV><FONT face="Times New Roman" color=#0000ff size=2>Thanks in advance!</DIV> <DIV><BR></DIV></FONT></BODY></HTML> =========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help". <p>
|
|