Reputation: 796
I am trying to call a C++ function present within a .dll file. The C++ function takes structure object as parameter by reference,and function will assign values in that function.
In my Java application, in order to pass a structure object to a function, I wrote 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 this error:
java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.lang.Comparable
What do I do? Is there a problem in the getFieldOrder()
function?
How exactly will JNA convert the class object in java to structure object in C++?
The exception is happening when I call the function.
Upvotes: 6
Views: 8298
Reputation: 10069
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.
To be explicit:
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "xxx", "yyy", "zzz", "www" });
}
Upvotes: 1