Hi, I'm getting the above exception when I tried to call a method using JNA.
The C function needs to be passed a TermStruc array.
I tried to use Java like following :
Original C method -> Eabc (TERMSTRUC *)
I defined equivalent methof like this --> it takes the current parameter like ABC(XPoint[] cp,
--------------------------------------------------
#define XPOINT
typedef struct
{
FEA_FLT tenor;
FEA_FLT rate;
} XPOINT;
#endif
public class XPoint extends Structure {
public double tenor;
public double rate;
public static class ByReference extends XPoint implements Structure.ByReference {
};
.... }
XPoint[] array = (XPoint[])new XPoint().toArray(2);
typedef struct {
double * abc;
TERMCURVE * h ;
} OUTPUT_STRU;
How should my equivalent Java definition be for Pass By Reference? I
looked at a VB application that's using it and it has defined delta as
an array of double and termcurve also as an array. I need BOTH of them
by reference. Please help. I defined the structure like below :
public class OutputStru extends Structure {
public static class ByReference extends FeaOutput implements
Structure.ByReference {}
public double[] abc;
public TermCurve[] h; // will this work if we use
termCurve.ByReference[] ?
In general, within a Structure define pointer types with type Pointer until you need something more specific.
In your case below, if Java is providing the data, then the "abc" field must be either com.sun.jna.Memory or an NIO buffer.
If the field "h" is a pointer to an array of structures, then you should first create an appropriate array of structures (using Structure.toArray()), then assign the address of the first element of that array to "h" (either with Structure.getPointer() or by converting the first element into an instance of Structure.ByReference).
If "h" is of type Pointer, the underlying structure will *not* be automatically synched with native memory before/after the call; if it is of type Structure.ByReference, then the structure (and any associated array) will be synched automatically.