wood burning stoves*
The moose likes Java in General and the fly likes JNI problem, pasing String to native (C function) by reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JNI problem, pasing String to native (C function) by reference" Watch "JNI problem, pasing String to native (C function) by reference" New topic
Author

JNI problem, pasing String to native (C function) by reference

Marko Filipovic
Greenhorn

Joined: Dec 01, 2009
Posts: 6
How can I pass String type from java to C by reference, in other words I want inout String parametar but i have a problem
how to assign it's value in c++ and to see this changes back in Java?
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
I don't know how to do that with a string parameter in JNI, Strings themselves are immutable.

even in Java, we can not





now you could pass an object (structure) into the JNI function., or an array of strings.

Here is an example of this on sun's forum http://forums.sun.com/thread.jspa?threadID=5395533


Error: Keyboard not attached. Press F1 to continue.
Marko Filipovic
Greenhorn

Joined: Dec 01, 2009
Posts: 6
Travis Hein wrote:I don't know how to do that with a string parameter in JNI, Strings themselves are immutable.

even in Java, we can not





now you could pass an object (structure) into the JNI function., or an array of strings.

Here is an example of this on sun's forum http://forums.sun.com/thread.jspa?threadID=5395533


Jea right, I forgot about that this was a realy stupid question, my profesor told me yesterday the same
Ok I'll try to pass the char array... Thanks anyway
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

just out of curiosity, does it work for chars ?
I mean you have a char array in java, you sent it to C program which changes this array,
is it reflected back into the java program ?


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Marko Filipovic
Greenhorn

Joined: Dec 01, 2009
Posts: 6
salvin francis wrote:just out of curiosity, does it work for chars ?
I mean you have a char array in java, you sent it to C program which changes this array,
is it reflected back into the java program ?




yes it's works just fine
in c++ code I just copy chars from my function result to inout chararray parameter and it's is changes char[] back in Java..
but there is a small problem only... I must give the size of array in java which in c++ is not nessery...

Du you know how to define dynamic array in Java something like char[] array = new char[] ?
(is it posible without char[] array = new char[ARRAY_SIZE]) )
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

clueless,


but i guess you could use multidimensional arrays for that ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNI problem, pasing String to native (C function) by reference