最近接到一个项目,用Java调用Delphi编写的dll文件,经过百般求索终于搞定,用JNA的 Native.loadLibrary ();方法来调用。
Java调用dll其实跟简单,主要是参数要对应。比如:
Delphi | Java |
ref |
IntByReference |
StringBuilder |
byte[] |
String | String |
常规方法如下(但是有坑,程序部署后会导致jvm崩溃,需要注意!!!):
public interface RtcPubLibrary extends Library { // 解决dll路径乱码 String filePath = RtcPubLibrary.class.getResource("").getPath().replaceFirst("/", "").replaceAll("%20", " ")