3 messages in net.java.dev.jna.usersRe: [jna-users] Buffer to Structure
FromSent OnAttachments
Thomas BörkelMar 19, 2008 5:06 am 
Timothy WallMar 19, 2008 5:33 am 
Thomas BörkelMar 19, 2008 8:42 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] Buffer to StructureActions...
From:Thomas Börkel (tho@boerkel.de)
Date:Mar 19, 2008 8:42:00 am
List:net.java.dev.jna.users

HI!

Timothy Wall wrote:

Not sure what you mean by future-proof. I would think declaring a specific structure preferable to a generic buffer. If the parameter accepts different types you can always declare a different method for each acceptable type.

What if the Structure is being extended in the future?

Today, it is 36 bytes. Maybe in the future, it is 50 bytes.

To make the call work, I have to tell the function, that my buffer is 50 bytes then. But what happens, if I pass the old Structure with 36 bytes?

I was thinking, it would be better to allocate the buffer as big as requested and then let fill JNA as much as possible into the (old) Stucture.

The following should do the trick (or something similar; I'm not looking at the javadoc right now):

MyStructure s ...; s.getPointer().write(0, lpBuffer, 0, lpBuffer.length); s.read();

OK, thanks, this works. :-)

Thomas