6 messages in net.java.dev.jna.usersRe: [jna-users] how to set a pointer
FromSent OnAttachments
Glick, Gene (GE Indust, Security)Sep 19, 2007 2:02 pm 
Timothy WallSep 19, 2007 2:55 pm 
Glick, Gene (GE Indust, Security)Sep 20, 2007 9:00 am 
Albert StrasheimSep 20, 2007 9:23 am 
Timothy WallSep 20, 2007 9:30 am 
Glick, Gene (GE Indust, Security)Sep 20, 2007 11:23 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] how to set a pointerActions...
From:Albert Strasheim (full@gmail.com)
Date:Sep 20, 2007 9:23:23 am
List:net.java.dev.jna.users

Modify the JNA interface for the library you are wrapping to look like this:

void foo(Buffer buffer);

and call it as:

byte[] buf = new byte[]{0, 1, 2}; YourLib.INSTANCE.foo(ByteBuffer.wrap(buf));

Depending on what you're doing, you might want to use a ByteBuffer created using ByteBuffer#allocateDirect instead of wrapping a ByteBuffer around an existing byte[].

On 9/20/07, Glick, Gene (GE Indust, Security) <gene@ge.com> wrote:

I'm confused. ByteBuffer is an abstract class. To use it means writing all its
methods first, right? Seems like a lot of work.

Let me be a little more specific in what I'm trying to do:

1. In some java code, I have created a 'byte[] buf' of data. 2. In some c shared library (.dll) the method is looking for a passed parameter
of 'uint8_t *buf' 3. The jna header file (not written by me, but could be modified if need be) is
looking for type 'Pointer buf'.

in C it goes something like this: a) byte buf[10]; b) byte *ptrBuf; c) ptrBuf = &buf[0]; d) someMethod(uint8_t *ptrBuf); in Java, using the JNA it goes something like this: a) byte [] buf = new byte[10]; b) Pointer ptrBuf = new Pointer(); c) *** here's where I am lost *** d) someInstance.someMethod(Pointer ptrBuf);

So, how to get the Pointer to be set to &buf[0]?

thanks,

gene