aspose file tools*
The moose likes I/O and Streams and the fly likes how to convert static String return into JNI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how to convert static String return into JNI" Watch "how to convert static String return into JNI" New topic
Author

how to convert static String return into JNI

Jhovarie Guiang
Greenhorn

Joined: Jul 13, 2011
Posts: 15
Hello i now this is basic and i hope some one helps please read.

Sample #1
--> Start
//this is a java code that calls the JNI to print "Hello World"
class HelloWorld {
static {
//System.loadLibrary("HelloWorld");
System.load("C:/HelloWorld.dll");
}
private native void print();

public static void main(String[] args) {
new HelloWorld().print();
}
}

#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"

JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
printf("Hello Java Native Interface.\n");
return;
}
--> End

And i want to do is that java will get the value of string variables from JNI and it will print hello world. for example in using java like this.

Sample #2
--> Start
public class classOne {
public static void main(String[]args){
String stringfrom_classTwo = classTwo.pblic_static_str();
System.out.println(stringfrom_classTwo);
}
}

// how to convert classTwo into a JNI?
public class classTwo {
public static String public_static_str(){
String str = "Hello World";
return str;
}
}
--> End
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Hi,

Welcome to JavaRanch!

You want to use the NewStringUTF() function, which you can see an example of here. That link is to an online copy of the JNI programmer's manual and guide -- it should answer any questions you have.


[Jess in Action][AskingGoodQuestions]
Jhovarie Guiang
Greenhorn

Joined: Jul 13, 2011
Posts: 15
i cant understand the tutorials from that link can any one post a sample code using NewStringUTF() and access it on java string variable?

im telling that code like this

//java code


JNI code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to convert static String return into JNI