jna 调用c++ dll 返回复杂结构体

经过折腾,确定,在java中定义同样的结构体,如c++中

struct Location {
	int nums;
	int arr[10];//数组的传递。不能用int *,因为jna的IntByReference.getValue()只能返回一个值
};

在java中的定义为

public static class Location extends Structure{
            public int nums;
            public int[] arr=new int[10];
            @Override protected List getFieldOrder() {
                return Arrays.asList(new String[]{"nums","arr"});
            }
        }

dll中函数定义为、

DLL_EXPORT void get_location_message(double,double,Location &);

返回值用引用类型

java中直接调用

CLibrary.Location l=new CLibrary.Location();
CLibrary.INSTANCE.get_location_message(lat,lon,l);

这样返回的Location就没有问题了。

你可能感兴趣的:(jna 调用c++ dll 返回复杂结构体)