Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Marko Filipovic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marko Filipovic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1263
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Marko Filipovic
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1263
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
clueless,


but i guess you could use multidimensional arrays for that ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic