On May 31, 2007, at 2:09 PM, Simon BASLE wrote:
Hello,
I'm currently doing a project involving accessing a (linux-based) C
library in Java.
I've tried and messed with JNI shortly then discovered JNA... What
a relief, what a great piece of software... so first of all, Thank
You! ;)
But I'd like to have more information about Strings and array
pointers. Let me explain :
- Strings : I have a function that is supposed to return a string,
with the following signature : int upkstr(char *str)... Trying to
map it to the java int upkstr(String str) doesn't work (String are
immutable objects and a call like upkstr(oneExistingString) leaves
oneExistingString unchanged :( How can I get a String result when
it is not from the return parameter of the C function?
Pass in a byte[] instead, then create a String based on that. If
your C function is depending on the byte array being null-terminated,
then make sure it is. Kind of a pain, and maybe NativeString should
be public or provide some utilities to do it for you.
-Arrays pointers : I'd like to know a little more on how to map
pointers to arrays in C (eg in a function that has following
signature : pkint(int *anArrayOfInts, int arraylength) ? Maybe
there's more details in the examples, haven't looked through them
yet... If so could you point me where to search ;)
int[] jarray;
pkint(jarray, jarray.length);
all primitive array types are supported, as are arrays of struct.
I'll add a section on this to the front page.