I am trying to call C++ function present within a dll file,C++ function takes structure object as parameter by reference,and function will assign values in that function,
So in my java application in order to pass structure object to a function i did write 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 it is giving me
java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.lang.Comparable
so what do i do?is there any problem in getFieldOrder() function?
can anyone explain me how exactly JNA will convert the class object in java to structure object in C++?
actually exception is happening at calling the function but i don't get it why it happening so.
Return this Structure's field names in their proper order
However, you are going to quickly run up against the fact that you're attempting to map a JNA Structure
onto a C++ class, which simply won't work. JNA does not provide any automatic translation between JNA and C++ classes.
EDIT
To be explicit:
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "xxx", "yyy", "zzz", "www" });
}