6 messages in net.java.dev.jna.usersRe: [jna-users] Pointer to structure ...
FromSent OnAttachments
Jean-Baptiste BugeaudMay 16, 2007 7:08 am 
Timothy WallMay 17, 2007 10:40 am 
Timothy WallMay 17, 2007 11:20 am 
Jean-Baptiste BugeaudMay 18, 2007 5:55 am 
Timothy WallMay 18, 2007 6:51 am 
Jean-Baptiste BugeaudMay 18, 2007 1:11 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] Pointer to structure arrays ?Actions...
From:Jean-Baptiste Bugeaud (buge@gmail.com)
Date:May 18, 2007 5:55:57 am
List:net.java.dev.jna.users

Hello Tim,

The example you have given (overriding of constructor) is not working with the existing toArray either ! Simply because, the allocateMemory is overriding the size field, which will make an ArrayIndexOutOfBoundsException on the second iteration inside the structure.toArray.

I hope next versions will support array of Structures. But this may lead to limitation of current memory mapping (to be verified).

JNA has realy gone much further than nlink on native feature support and is much stable on "tricky things" according to my experience. But there are some little things that make nlink still more appealing : - genericity : Did I say this is becoming mandatory nowadays ? You bet it is, for instance toArray would be really simpler. - annotation : cool ones are those for name overriding on members and class. This is way more convenient & clean than a lookup Map, IMHO ;-) - cleaner Java API integration (for instance using java.nio.Buffer's allocate instead of malloc/free, and less native interraction points between java and native ==> less JNI points opened ==> easier to secure & port ) - on win32 by default call to unicode/W methods for method existing in both ascii and unicode (yes, Java is unicode too !) - cleaner code (maybe because NLink is Win32 only at this time ?!?), this would ease code understanding

FYI, to see the code I am using the web SVN server at this time.

Let's hope kohsuke will have time to responde anytime soon ;-) Because realy, merging the two could realy make a keystone for nextgen Java/Native interraction !

And could open bright opportunities...

Best Regards, JB

2007/5/17, Timothy Wall <twal@dev.java.net>:

I think the simplest way to represent this would be to pass in an array of structure, leaving JNA to actually initialize the individual elements if not already.

To make this work with the current code, you would initialize the desired structure type and force its size to be N times the size for a single structure, then use toArray() to construct the appropriate array of structures.

public MyStructure(int nelements) { allocateMemory(size()*nelements); }

As for integrating with nlink, I've sent email to kohsuke, but haven't heard any response. At any rate, at this point I don't think there are any nlink features that are not yet covered by jna.

Do you have any specific annotations that you think would be useful? At the moment, I don't have any cases that are truly compelling and useful in the general case (ditto for generics).

If you have specific examples of cases where generics and/or annotations would help or simplify things, please share them.

Next time we post a release I'll include the javadocs and a source jar; are you unable to do a subversion checkout?

On May 16, 2007, at 10:09 AM, Jean-Baptiste Bugeaud wrote:

Hello all,

I am trying to access the GetRawInputDeviceList from Windows's User32.dll

see http://msdn2.microsoft.com/en-us/library/ms645598.aspx

What is the prefered equivalence of the p/invoke Marshal.PtrToStructure under JNA ? IE, getting a Structure from a raw Pointer, enabling some pointer computation to get an structure array, given a number of element ?

I am able to access the pRawInputDeviceList "array" using a Memory with signature : int GetRawInputDeviceList(Pointer pRawInputDeviceList, IntByReference puiNumDevices, int cbSize); doing manual field access (direct offset computing)... working, but very painfull and dumping lots of interrest of using JNA :(

But neither accesing with a Structure like : int GetRawInputDeviceList(RAWINPUTDEVICE pRawInputDeviceList, IntByReference puiNumDevices, int cbSize); nor with an array structure like : int GetRawInputDeviceList(RAWINPUTDEVICE[] pRawInputDeviceList, IntByReference puiNumDevices, int cbSize); is working (assuming the array is filled to the right size) !

When passing a Structure, I am able to get the first one (of index 0), but requesting toArray() on the Structure would then fail (even making the underlying memory of the structure allocated to the array required size).

Any ideas/solutions ?

Second question, is there any formal plan to integrate nlink to JNA ? IE, use annotations, genericity ... to get simpler and more intuitive code ?

Last question, coud you provide the sources and the javadocs as JAR files on the website ? This would be very handy ;-)

Regards, Jean-Baptiste BUGEAUD