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 {
SomeInterface instance = (SomeInterface) Native.loadLibrary("mydll", SomeInterface.class);
int someFunction(StructClass.ByReference strobject);
public static class StructClass 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;
}
}
}
my main class
public class Someclass {
public static void main(String args[]) {
SomeInterface.StructClass.ByReference sss=new SomeInterface.StructClass.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.
From the JavaDoc:
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" });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With