[英]JNA to call a DLL without source code from java
I have to call a dll method and I don't have the source code from dll, I was reading about JNI and understood that you should have the source to input the JNI library in the code (.h). 我必须调用一个dll方法,我没有来自dll的源代码,我正在阅读有关JNI的内容,并且理解您应该在代码(.h)中输入JNI库。
My second shoot is JNA, but I am getting the same error, although you don't have to change anything in DLL. 我的第二次拍摄是JNA,但是我得到了同样的错误,尽管你不需要在DLL中改变任何东西。
I created two classes to test: 我创建了两个要测试的类:
interface: 接口:
package icom;
import com.sun.jna.Library;
public interface IConectorT extends Library {
int StartConector(byte[] conectorStatus, String icomPath);
}
DLL method call: DLL方法调用:
package icom;
import com.sun.jna.Native;
public class ConectorTJna {
public static void main(String args[]) {
IConectorT lib = (IConectorT) Native.loadLibrary("ConectorT", IConectorT.class);
int teste = lib.StartConector(null, "C:\\ICOM");
System.out.println("RESULT: " + teste);
}
}
When I call the lib.StartConector
method I get this: 当我调用
lib.StartConector
方法时,我得到这个:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'StartConector': The specified procedure could not be found.
线程“main”中的异常java.lang.UnsatisfiedLinkError:查找函数'StartConector'时出错:找不到指定的过程。 at com.sun.jna.Function.(Function.java:179) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:350) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:330) at com.sun.jna.Library$Handler.invoke(Library.java:203) at $Proxy0.StartConector(Unknown Source) at icom.ConectorTJna.main(ConectorTJna.java:10)
at com.sun.jna.Function。(Function.java:179)at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:350)at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:330) at com.sun.jna.Library $ Handler.invoke(Library.java:203)位于icom.ConectorTJna.main的$ Proxy0.StartConector(未知来源)(ConectorTJna.java:10)
Did you specify path to the library, eg using system property? 您是否指定了库的路径,例如使用系统属性?
Here are the details from "Getting Started with JNA" guide: 以下是“JNA入门”指南中的详细信息:
Make your target library available to your Java program.
使目标库可用于Java程序。 There are two ways to do this:
有两种方法可以做到这一点:
The preferred method is to set the jna.library.path system property to the path to your target library.
首选方法是将jna.library.path系统属性设置为目标库的路径。 This property is similar to java.library.path , but only applies to libraries loaded by JNA.
此属性类似于java.library.path ,但仅适用于JNA加载的库。
Change the appropriate library access environment variable before launching the VM.
在启动VM之前更改相应的库访问环境变量。 This is PATH on Windows, LD_LIBRARY_PATH on Linux, and DYLD_LIBRARY_PATH on OSX.
这是PATH在Windows,Linux上的LD_LIBRARY_PATH,和DYLD_LIBRARY_PATH在OSX。
Taken from: https://github.com/twall/jna/blob/master/www/GettingStarted.md 摘自: https : //github.com/twall/jna/blob/master/www/GettingStarted.md
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.