2 messages in net.java.dev.jna.users[jna-users] Re: example of an Array o...
FromSent OnAttachments
MichaelDec 22, 2008 6:19 pm 
MichaelDec 23, 2008 6:05 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:[jna-users] Re: example of an Array of Struct being passed to a callbackActions...
From:Michael (java@nemonik.com)
Date:Dec 23, 2008 6:05:54 pm
List:net.java.dev.jna.users

Here's the answer to my question:

Call the callback from C like so:

struct RegionElement callbackRegionElements[2] = { { 101, { 0.1, 1.1, 2.1, 3.1 } }, { 202, { 4.2, 5.2, 6.2, 7.2 } } };

callback(callbackRegionElements, 2);

In Java

public void callback(RegionElement regionElement, int nRegion) {

System.out.println(((RegionElement[])(regionElement.toArray(nRegion)))[0].regionBox[1]);

I've been hammering my head against this for two days now. Does anyone have a simple example of an Array of Struct being passed to a com.sun.jna.Callback described callback method through JNA that you'd care to share?

Of all the various ways I've tried to shake this loose, I can only seem to get at the first Struct in the array.

The Java version of the struct is quite simple:

public class RegionElement extends Structure { public long frameId; public double[] regionBox = new double[4]; };

The C-verison:

struct RegionElement { long long frameId; double regionBox[4]; };