Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JNA直接调用不使用参数结构[] 我有C++函数: struct Result { //... }; bool doSomething(Result[]);_Java_Native_Jna - Fatal编程技术网

Java JNA直接调用不使用参数结构[] 我有C++函数: struct Result { //... }; bool doSomething(Result[]);

Java JNA直接调用不使用参数结构[] 我有C++函数: struct Result { //... }; bool doSomething(Result[]);,java,native,jna,Java,Native,Jna,如果使用以下JNA绑定,函数调用可以正常工作: public class Result extends Structure { //... } public interface CPPLibrary extends Library { public static final CPPLibrary INSTANCE = (CPPLibrary)Native.loadLibrary("dllname"); boolean doSomething(Result[]); }

如果使用以下JNA绑定,函数调用可以正常工作:

public class Result extends Structure {
    //...
}

public interface CPPLibrary extends Library {
    public static final CPPLibrary INSTANCE = (CPPLibrary)Native.loadLibrary("dllname");
    boolean doSomething(Result[]);
}
但在使用直接调用时,我遇到了一个IllegalArgumentException,表示类[Lcom.usta.Result;不是类com.usta.CPPLibrary中方法calcPV01中支持的参数类型。我的直接调用映射JNA代码:

public class CPPLibrary implements Library {
    Native.register("dllname");
    public static native boolean doSomething(Result[]);
}

我可以在com.sun.jna.FunctionconvertArgument中看到显式处理结构[],但直接调用映射使用的com.sun.jna.NativegetConversion不处理结构[]。

如果我使用不同的方法签名:

boolean doSomething(Pointer results);

它确实可以工作。但是我必须将Result[]转换为我自己的指针。

如果我使用不同的方法签名:

boolean doSomething(Pointer results);

它确实有效。但是我必须将Result[]转换为指针。

转换很简单,只要在结构数组的第一个元素上调用Structure.getPointer,假设首先从Structure.toArray获得数组

实际上,在使用直接映射时,这样做会更好;当传递非原语、非指针类型时,JNI层必须回调到VM中以派生适当的本机数据


请随时提交问题以支持结构[]直接映射中的参数。JNA文档注意到,不支持指针/String/WString/NativeMapped数组。转换很简单,只要在结构数组的第一个元素上调用Structure.getPointer,假设首先从Structure.toArray获得数组

实际上,在使用直接映射时,这样做会更好;当传递非原语、非指针类型时,JNI层必须回调到VM中以派生适当的本机数据

请随意提出一个问题,以支持直接映射中的结构[]参数。这应该得到支持。JNA文档注意,不支持指针/String/WString/NativeMapped数组