JNA在没有源代码的情况下调用DLL

前端之家收集整理的这篇文章主要介绍了JNA在没有源代码的情况下调用DLL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_0@
@H_301_0@
我必须调用一个dll方法,我没有来自dll的源代码,我正在阅读有关JNI的内容,并且理解您应该在代码(.h)中输入JNI库.

我的第二次拍摄是JNA,但是我得到了同样的错误,尽管你不需要在DLL中改变任何东西.

我创建了两个要测试的类:

接口:

package icom;

import com.sun.jna.Library;

public interface IConectorT extends Library {
    int StartConector(byte[] conectorStatus,String icomPath);
}

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);
    }
}

当我调用lib.StartConector方法时,我得到这个:

Exception in thread “main” java.lang.UnsatisfiedLinkError: Error
looking up function ‘StartConector’: The specified procedure could not
be found. 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)

解决方法

您是否指定了库的路径,例如使用系统属性

以下是“JNA入门”指南中的详细信息:

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

  1. 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.

  2. 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.

取自:https://github.com/twall/jna/blob/master/www/GettingStarted.md

@H_301_0@

猜你在找的Windows相关文章