Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2005, 01:00 AM
Authorized User
 
Join Date: Jul 2003
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get a String from JNI?

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!



 
Old December 19th, 2005, 03:34 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

return (*env)-> NewStringUTF(env,"Hello World");






Similar Threads
Thread Thread Starter Forum Replies Last Post
apache tomcat and JNI elixiradeel Apache Tomcat 0 June 5th, 2008 09:55 PM
syntax to find a string in a string cole SQL Server 2000 2 October 10th, 2005 06:06 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM
its about the jni API ogriddmut Dreamweaver (all versions) 1 June 29th, 2004 03:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.