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