10 messages in net.java.dev.jna.usersRe: [jna-users] Problem with Structur...
FromSent OnAttachments
Rob CopeSep 13, 2007 9:22 pm 
Rob CopeSep 13, 2007 9:36 pm 
Rob CopeSep 13, 2007 9:37 pm 
Rob CopeSep 13, 2007 9:59 pm 
Timothy WallSep 14, 2007 4:50 am 
Timothy WallSep 14, 2007 4:58 am 
Rob CopeSep 14, 2007 8:17 am 
Rob CopeSep 14, 2007 9:17 am 
Timothy WallSep 14, 2007 9:27 am 
Rob CopeSep 14, 2007 7:19 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] Problem with Structure[] field in StructureActions...
From:Rob Cope (ro@eclipseservices.com)
Date:Sep 14, 2007 7:19:13 pm
List:net.java.dev.jna.users

Thanks, that worked great!

Rob

On Sep 14, 2007, at 12:27 PM, Timothy Wall wrote:

On Sep 14, 2007, at 12:17 PM, Rob Cope wrote:

So I apparently I was using the wrong syntax in Java. The native struct is defined like this:

struct SecKeychainAttributeList { UInt32 count; SecKeychainAttribute *attr; };

What I need on the native side is an array of pointers to SecKeychainAttributes. So once the Pointer[] is working, that should do the trick, right?

When defining Structure fields, you should only use an array in java if an array is used in the native code. In this case, you want a Pointer, not an array.

However, since your API is expecting the pointer to be an array of structs, you can use Structure.toArray() to obtain an array of structs contiguous in memory, then use Structure.getPointer() on the first element to initialize the structure field.

Also make sure you keep a reference to the structure array until your native code is done with it, to avoid GC on the Java side.