I'm trying to pass an array of structures to a native function. Though my
test program runs without crashing, the native function receives the wrong
values.
The Java code:
________________________________________
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;
/** Provides access to a native library. */
public class Point extends Structure {
public int x;
public int y;
public interface API extends Library {
API INSTANCE = (API)Native.loadLibrary
("c:/upapps/efm/bin/efms-api.dll", API.class);
void pointTest(Point[] points, int count);
}
public Point() {}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public static void main(String[] unused) {
Point[] points = new Point[2];
points[0] = new Point(1,2);
points[1] = new Point(3,4);
Point[] structures = (Point[])new Point().toArray(points);
API.INSTANCE.pointTest(structures, structures.length);
}}
________________________________________
The native C function the Java code is calling:
#include <stdio.h>
typedef struct {
int x;
int y;
} POINT;
void pointTest(POINT points[], int count) {
int i = 0;
while (i++ < count)
printf("Point %i: %i,%i\n", i, points[i].x, points[i].y);
}
________________________________________
I expected to get:
Point 1: 1,2
Point 2: 3,4
But instead I get:
Point 1: 0,0
Point 2: 196610,34079172