2 messages in net.java.dev.jna.usersRe: [jna-users] Mapping a call to a C...
FromSent OnAttachments
Rui CaridadeDec 17, 2007 8:43 pm 
Timothy WallDec 18, 2007 8:13 pm 
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] Mapping a call to a C function that returns an array of StringsActions...
From:Timothy Wall (twal@dev.java.net)
Date:Dec 18, 2007 8:13:52 pm
List:net.java.dev.jna.users

On Dec 17, 2007, at 11:44 PM, Rui Caridade wrote:

Hello. I have a function that returns a list of Strings with the cdrom id names on the pc (below)

char ** getCDRomDevices();

But whenever i try to call it from java , whether with byte [ ] [ ] or String [ ] i get this error (the error below refers when i say within java the function returns a byte [ ] [ ] )

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported return type class [[B at com.sun.jna.Function.invoke(Function.java:335) at com.sun.jna.Function.invoke(Function.java:229) at com.sun.jna.Library$Handler.invoke(Library.java:170) at $Proxy0.getCDRomDevices(Unknown Source) at test.main(test.java:43)

This is because there is no way to know automatically how big is the returned array. If you return Pointer, then you can use Pointer.getPointerArray(0, length) if you know the length or Pointer.getPointer(Pointer.SIZE * index) until you're done reading individual values.

One other thing. I'm getting a file from the cdrom into something like this (char * file), what would be the best way to map this.I later want to transfer this data to a ByteBuffer (Direct).

You can pass a Buffer as an argument, so you can create your direct ByteBuffer and pass it in.