加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 05:41:14 所属栏目:Windows 来源:网络整理
导读:我必须调用一个dll方法,我没有来自dll的源代码,我正在阅读有关JNI的内容,并且理解您应该在代码(.h)中输入JNI库. 我的第二次拍摄是JNA,但是我得到了同样的错误,尽管你不需要在DLL中改变任何东西. 我创建了两个要测试的类: 接口: package icom;import com.su
我必须调用一个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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读