Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Subject: How to get a String from JNI?

Subject: How to get a String from JNI?

2005-09-09       - By Edward King

 Back
Reply:     1     2  

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{&nbsp; &nbsp;<BR>&nbsp;public String test1(String s){<BR>&nbsp;&nbsp;
return test11(s);<BR>&nbsp;}<BR>&nbsp;private native String test11(String
s);&nbsp;<BR>&nbsp; static{<BR>&nbsp;&nbsp; System.loadLibrary( "MyNative"
);<BR>&nbsp; } <BR>&nbsp;public static void main( String[] args
){<BR>&nbsp;&nbsp;&nbsp; MyNative obj = new MyNative();<BR>&nbsp;&nbsp;&nbsp;
String c=obj.test1("abc");<BR>&nbsp;&nbsp;&nbsp;
System.out.println("--"+c);<BR>&nbsp;&nbsp; }<BR>}</FONT></DIV>
<DIV>&nbsp;</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 &lt;jni.h&gt;<BR>/*
Header for class MyNative */<BR>#ifndef _Included_MyNative<BR>#define
_Included_MyNative<BR>#ifdef __cplusplus<BR>extern "C"
{<BR>#endif<BR>/*<BR>&nbsp;* Class:&nbsp;&nbsp;&nbsp;&nbsp; MyNative<BR>&nbsp;*
Method:&nbsp;&nbsp;&nbsp; test11<BR>&nbsp;* Signature:
(Ljava/lang/String;)Ljava/lang/String;<BR>&nbsp;*/<BR>JNIEXPORT jstring JNICALL
Java_MyNative_test11<BR>&nbsp; (JNIEnv *, jobject, jstring);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#0000ff size=2>#ifdef
__cplusplus<BR>}<BR>#endif<BR>#endif</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#0000ff size=2>//MyNative.c<BR>#include
&lt;stdio.h&gt;<BR>#include "MyNative.h"<BR>JNIEXPORT jstring JNICALL
Java_MyNative_test11<BR>&nbsp; (JNIEnv *env, jobject obj, jstring
s){<BR>&nbsp;&nbsp; //How to realize return String to Java???,such as
&nbsp;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>&nbsp;</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>

©2008 junlu.com - Jax Systems, LLC, U.S.A.