17 messages in net.java.dev.jna.users[jna-users] Array of Structures in a ...
FromSent OnAttachments
RWAD...@UP.COMJul 18, 2008 8:39 am 
Timothy WallJul 18, 2008 9:26 am 
RWAD...@UP.COMJul 18, 2008 9:46 am 
Timothy WallJul 18, 2008 10:18 am 
RWAD...@UP.COMJul 18, 2008 11:07 am 
RWAD...@UP.COMJul 18, 2008 11:19 am 
Timothy WallJul 18, 2008 11:35 am 
Timothy WallJul 18, 2008 11:40 am 
Timothy WallJul 18, 2008 11:44 am 
Timothy WallJul 18, 2008 11:46 am 
RWAD...@UP.COMJul 18, 2008 12:01 pm 
RWAD...@UP.COMJul 18, 2008 12:07 pm 
RWAD...@UP.COMJul 18, 2008 12:09 pm 
RWAD...@UP.COMJul 18, 2008 12:28 pm 
Timothy WallJul 18, 2008 12:46 pm 
RWAD...@UP.COMJul 18, 2008 12:55 pm 
RWAD...@UP.COMJul 18, 2008 1:16 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] Array of Structures in a StructureActions...
From:RWAD...@UP.COM (RWAD@UP.COM)
Date:Jul 18, 2008 8:39:12 am
List:net.java.dev.jna.users

I'm having trouble properly initializing a C structure which contains an array of other structures. The C structure definition is:

typedef struct op_and_ornt_struct { Obj_Pnt_Struct obj_pnt; short int num_rpls; struct { Rail_Path_Loca_Struct rpl; Ropo_Struct ropo; double dist_from; } ornt[3]; } Op_And_Ornt_Struct;

____________________________________________________________

The Java code I'm using to emulate this structure is as follows:

package com.uprr.efm.nativ.struct; import java.util.List; import com.uprr.net.Orientation; import com.uprr.point.ObjectPointOrientation;

public class ObjectPointAndOrientationStructure extends Structure {

public ObjectPointStructure obj_pnt ; public int num_rpls ; public OrientationStructure[] orientations ;

/** Default constructor. */ public ObjectPointAndOrientationStructure() { orientations = (OrientationStructure[])new OrientationStructure().toArray(3); } }

____________________________________________________________

I then create a 2-element array of these structures & pass it to a C function as follows:

final ObjectPointAndOrientationStructure opo = new ObjectPointAndOrientationStructure() ; final ObjectPointAndOrientationStructure[] opos = (ObjectPointAndOrientationStructure[])opo.toArray(2); myFunction(opos);

____________________________________________________________

The C function then tries to fill the 2-element "opos" array with zeroes, but crashes. Apparently the Java structure size differs from the C structure size.

I'm guessing that may that the "orientations" array in the structure is not being inlined as intended, & that the Java constructor above is not creating it correctly. Does this make sense? If so, how do i instantiate the 3-element orientation array correctly so that it's inline inside of its parent structure?