4 messages in net.java.dev.jna.usersRe: [jna-users] question about String...
FromSent OnAttachments
Simon BASLEMay 31, 2007 11:08 am 
Timothy WallMay 31, 2007 11:29 am 
Simon BASLEJun 8, 2007 7:41 am 
Timothy WallJun 8, 2007 11:39 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] question about Strings and array pointersActions...
From:Timothy Wall (twal@dev.java.net)
Date:May 31, 2007 11:29:18 am
List:net.java.dev.jna.users

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.