c++ - java使用jna调用
怪我咯
怪我咯 2017-04-17 11:56:43
[Java讨论组]

现在有一个获取机器码的c++开发好的dll,java程序需要调用这个dll获取到机器码;
1)、dll里面有个int getMacCode(char *p)这个函数;
2)、让p这个指针指向的地址空间保存了机器码;
3)、用java如何实现这个调用过程?
ps:目前用jna来调用,但是一直报找不到函数的错误,“java.lang.UnsatisfiedLinkError: Error looking up function 'getMacCode':xxxx”;估计认为是参数传递上错误了,请大神赐教

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
大家讲道理

参数应该是byte[]类型的

PHPz

再看了下问题,貌似不是这个原因。可能需要你帖点代码出来才晓得了
下面的东西先留着,等找到真正的原因了再来改吧


看样子是 DLL 没加载到,JNA 的文档里有设置路径的办法

Make your target library available to your Java program. There are several ways to do this:

  • The preferred method is to set the jna.library.path system property to the path to your target library. This property is similar to java.library.path, but only applies to libraries loaded by JNA.
  • Change the appropriate library access environment variable before launching the VM. This is PATH on Windows, LD_LIBRARY_PATH on Linux, and DYLD_LIBRARY_PATH on OSX.
  • Make your native library available on your classpath, under the path {OS}-{ARCH}/{LIBRARY}, where {OS}-{ARCH} is JNA's canonical prefix for native libraries (e.g. win32-x86, linux-amd64, or darwin). If the resource is within a jar file it will be automatically extracted when loaded.

大概就是需要你把 DLL 所在目录设置在系统的 PATH 路径里,或者通过 java 的参数 jna.library.path 指定目录,

java -Djna.library.path=PATH_TO_YOUR_DLL ClassName
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号