JNA: what is the purpose of getFieldOrder () in the structure class

I am trying to call a C ++ function present in a DLL file, a C ++ function takes a structure object as a parameter by reference, and the function assigns values ​​to this function,

So, in my java application, to pass the structure object of the function that I wrote, like this:

interface someinterface extends Library{ public static class strctclass extends Structure { public static class ByReference extends tTIDFUDeviceInfo implements Structure.ByReference {} public short xxx=0; public char yyy='0'; public boolean zzz=false public String www=new String(); protected ArrayList getFieldOrder() { // TODO Auto-generated method stub ArrayList fields = new ArrayList(); fields.add(Arrays.asList(new short{xxx})); fields.add(Arrays.asList(new char{yyy})); fields.add(Arrays.asList(new boolean{zzz})); fields.add(Arrays.asList(new String{www})); return fields; } someinterface instance=(someinterface) Native.loadLibrary("mydll", someinterface.class); int somefunction(strctclass.ByReference strobject); } 

my main class

 public class Someclass { public static void main(String args[]) { someinterface.strctclass.ByReference sss=new someinterface.strctclass.ByReference(); someinterface obj=someinterface.instance; obj.somefunction(sss); } } 

when i tried this he gives me

 java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.lang.Comparable 

so what am i doing are there any problems in the getFieldOrder () function?

can someone explain to me exactly how JNA will convert the class object to java to structure the object in C ++?

The actual exception occurs when the function is called, but I do not understand why this is happening.

+6
source share
1 answer

From JavaDoc:

Return these structure field names in their proper order

However, you will soon find yourself trying to map the JNA Structure to a C ++ class that just won't work. JNA does not provide automatic translation between JNA and C ++ classes.

EDIT

To be explicit:

 protected List<String> getFieldOrder() { return Arrays.asList(new String[] { "xxx", "yyy", "zzz", "www" }); } 
+1
source

All Articles