博客
关于我
jna 调用c++ dll 返回复杂结构体
阅读量:305 次
发布时间:2019-03-03

本文共 698 字,大约阅读时间需要 2 分钟。

在Java中定义结构体类似于C++中的结构体

通过多次尝试和验证,我们确定在Java中定义与C++类似的结构体是可行的。以下是实现细节和代码示例

结构体定义

在Java中,通过继承Structure类并实现Structure接口,可以定义类似于C++结构体的对象。在本例中,我们定义了一个Location类,其中包含两个字段:numsarrarr字段为一个整数数组,大小为10。我们使用public static class来定义内部类,并通过@Override protected List.getFieldOrder()方法指定字段的访问顺序。

DLL函数定义

DLL中的函数定义使用DLL_EXPORT预处理器指令,并接受Location对象的引用作为参数。返回值为布尔值,表示操作是否成功。以下是函数定义示例:

DLL_EXPORT bool get_location_message(double lat, double lon, Location& location);

引用类型传递

在Java中,Location类实现了Structure接口,确保可以通过引用传递。在调用DLL函数时,我们需要创建一个Location实例,并将其传递给目标函数。以下是调用示例:

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

通过这种方式,我们可以确保Location对象在Java和DLL之间有效传递,并且不会出现数据丢失或引用失效的问题

转载地址:http://rtim.baihongyu.com/

你可能感兴趣的文章
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! fatal: unable to connect to github.com:
查看>>
npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>
npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
查看>>
npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
查看>>
npm install CERT_HAS_EXPIRED解决方法
查看>>
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>