5 messages in net.java.dev.jna.usersGetting IllegalArgumentException when...
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:Getting IllegalArgumentException when using Structure[] as method argumentActions...
From:Niels van Eijck (nvan@gmail.com)
Date:Jan 21, 2008 3:13:56 am
List:net.java.dev.jna.users

I'm trying to call a native method that has an array of structs as a method argument. I keep getting an IllegalArgumentException: Structure array elements must use contiguous memory (at element index 1)

I've made some example code to illustrate/reproduce my problem. I'm using the latest JNA code from svn (revision 453).

interface Test extends Library {

class MyNumber extends Structure { public short num; }

int calculateSum(MyNumber[] numbers); }

When I link to the DLL and I call calculateSum from a Junit test I get the exception. My C++ code looks like this (although I think the problem doesn't lie there):

typedef struct MyNumber { unsigned short num; } MyNumber;

TEST_API int calculateSum(MyNumber* numbers) { int size = sizeof(numbers) / sizeof(MyNumber); int result = 0;

for (int i = 0; i < size; i++) { result += numbers[i].num; }

return result; }

Did I stumble upon a bug or am I doing something wrong? Any help will be greatly appreciated!

Thanks, Niels.