2 messages in net.java.dev.jna.usersRe: [jna-users] zero-terminated Strin...
FromSent OnAttachments
Vito IngrassiaAug 8, 2007 9:04 am 
Timothy WallAug 8, 2007 9:45 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] zero-terminated String conversionActions...
From:Timothy Wall (twal@dev.java.net)
Date:Aug 8, 2007 9:45:26 am
List:net.java.dev.jna.users

On Aug 8, 2007, at 12:04 PM, Vito Ingrassia wrote:

Hello,

my C callback function is

void Function(const AType* val);

where AType is

typedef char AType[15];

Assuming that all your const char* are C strings, your callback is expecting an array of C strings, not just one C string. The ideal equivalent would ideally be String[] in java, but since the JNA library has no way of knowing the length of the array it is receiving, you have to extract the data yourself. You should simply declare the argument as Pointer and use Pointer methods to extract the bits you need, e.g.

void Function(Pointer ptr) { Pointer[] array = ptr.getPointerArray(0, C_ARRAY_LENGTH); for (int i=0;i < array.length;i++) { System.out.println("index " + i + "=" + array[i].getString(0)); } }