5 messages in net.java.dev.jna.usersRe: [jna-users] Getting IllegalArgume...
FromSent OnAttachments
Niels van EijckJan 21, 2008 3:13 am 
Timothy WallJan 21, 2008 8:07 am 
Niels van EijckJan 22, 2008 4:30 am 
Timothy WallJan 22, 2008 5:59 am 
Niels van EijckJan 22, 2008 7:04 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] Getting IllegalArgumentException when using Structure[] as method argumentActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jan 22, 2008 5:59:18 am
List:net.java.dev.jna.users

Structure.toArray needs to ensure memory is allocated and size calculated before recalculating memory requirements. This has been fixed on the trunk.

You can manually do this by calling "size()" prior to calling "toArray ()".

On Jan 22, 2008, at 7:30 AM, Niels van Eijck wrote:

Thanks to Timothy for solving my initial problems. I now run into another problem where I get an exception using nested Structures:

interface Test extends Library {

class MyNumberPart extends Structure { public int part; }

class MyNumber extends Structure { public int num; public MyNumberPart[] parts;

public MyNumber() { parts = (MyNumberPart[])new MyNumberPart().toArray(2); } }

int calculateSum(MyNumber[] numbers, int arraySize); }

My test method:

public void TestMethod() {

MyNumber[] numbers = (MyNumber[])new MyNumber().toArray(2); numbers[0].num = 4; numbers[0].parts[0].part = 1; numbers[0].parts[1].part = 2;

numbers[1].num = 3; numbers[1].parts[0].part = 3; numbers[1].parts[1].part = 4;

int sum = Test.calculateSum(numbers); }

Then I get this exception:

java.lang.IndexOutOfBoundsException: Bounds exceeds available space : size=12, offset=24 at com.sun.jna.Memory.boundsCheck(Memory.java:149) at com.sun.jna.Memory.share(Memory.java:90) at com.sun.jna.Structure.toArray(Structure.java:977) at com.sun.jna.Structure.toArray(Structure.java:989)

Again, thanks for your help!

regards, Niels.