JNA:在结构类中getFieldOrder()的目的是什么 [英] JNA:what is the purpose of getFieldOrder() in structure class
问题描述
我试图调用一个dll文件中的C ++函数,C ++函数通过引用将结构对象作为参数,函数将在该函数中赋值,
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,
所以在我的java应用程序中为了传递结构对象到一个函数我写的像这样:
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);
}
我的主类
public class Someclass
{
public static void main(String args[])
{
someinterface.strctclass.ByReference sss=new someinterface.strctclass.ByReference();
someinterface obj=someinterface.instance;
obj.somefunction(sss);
}
}
当我尝试这是给我
java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.lang.Comparable
所以我该怎么办?在getFieldOrder()函数中有什么问题吗?
so what do i do?is there any problem in getFieldOrder() function?
任何人都可以解释一下JNA如何将java中的类对象转换为C ++中的结构对象?
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.
推荐答案
以正确的顺序返回此Structure的字段名称
Return this Structure's field names in their proper order
但是,事实上,你试图将一个JNA 结构
映射到一个C ++类,这根本不会工作。 JNA不提供JNA和C ++类之间的任何自动翻译。
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
显式:
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "xxx", "yyy", "zzz", "www" });
}
这篇关于JNA:在结构类中getFieldOrder()的目的是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!