Propagating changes from C into Java

I need to interface to an existing library of C functions which have the property of input parameters being used as output.

IE a C function may have the signature: int NWDS_PING(char *node, NWDS_ITEM_LIST *item_list).

The string node is used both as input and output for the function with the int return type indicating status of the request. My problem lies in that I need the java String passed into the native method from my java function to be altered to whatever it is modified to in the C process.

Any ideas on how to do this?

Thanking you kindly,

[599 byte] By [iiq374] at [2007-9-26 6:17:20]
# 1

Hi,

* you can use a Stringbuffer or

* you can use a byte array

(but no String)

1. In Java fill the parameter of your choice with your input string and

pass it to the native method

2. Collect the input string in your JNI function into a newly created

char[] and pass it as char * in the call to the C function

3. After return in your JNI function copy the result back to

the parameter. Free your char[].

That's it.

Have fun,

Klaus

wiedkla at 2007-7-1 15:13:25 > top of Java-index,Java HotSpot Virtual Machine,Specifications...