How can i pass string from C++ DLL to Java via JNI?

Hi everybody. I made a DLL with Borland C++.I must pass a string from this dll to Java via JNI.Namely i define a string variable in C++ DLL and i send this variable's value to Java via JNI. I can pass integers but i couldnt Strings. . How can i do this? is there any sample?
[289 byte] By [c_atlantis@yahoo.coma] at [2007-10-3 10:59:43]
# 1

Hi,

You can see a sample in the sources of JNative here : http://jnative.cvs.sourceforge.net/jnative/JNativeCpp/org_xvolks_jnative_JNative.cpp?revision=1.9&view=markup

at line 458. The JNU_SetFieldByName is defined here :

http://jnative.cvs.sourceforge.net/jnative/JNativeCpp/jni_util.c?revision=1.1&view=markup

at line 1108.

--Marc (http://jnative.sf.net)

mdentya at 2007-7-15 6:26:12 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Thanx for answer but unfortunately it didnt solve my problem.

Let me tell what i am trying do ..

i define a native function in Java whit under code

public static native int get_text();

after i compile a header file with javah , i define a string in C++

string myString="abcdefghi";

then i wrote

JNIEXPORT jint JNICALL Java_dll_get_text

Java_firstJNI_getLine(JNIEnv *env)

//Here, what must i write for send myString to JAVA ?

After this Now. what must i write to send myString variable in JAVA ?

i couldnt find anything. when i get any integer value , i dont see any problem but if i try to get string, i coudnt :((

c_atlantis@yahoo.coma at 2007-7-15 6:26:12 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Hi,

So your function should be private static native String get_text();

(It's often a good idea to make native methods private since when you change signatures you generally have to change java wrapper methods only).

I know nothing about C++ strings but I'm pretty sure that you can convert it to char*, so

do :

char* szMyString = myString.toChar*();

Then return from native with JNU_NewStringPlatform(env, szMyString)

(see my 1st answer for JNU_NewStringPlatform() description).

--Marc (http://jnative.sf.net)

mdentya at 2007-7-15 6:26:12 > top of Java-index,Java HotSpot Virtual Machine,Specifications...