• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to convert static String return into JNI

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jhovarie Guiang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic