gpt4 book ai didi

java - JNA从java调用没有源代码的DLL

转载 作者:搜寻专家 更新时间:2023-11-01 03:42:04 26 4
gpt4 key购买 nike

我必须调用一个 dll 方法,但我没有 dll 的源代码,我正在阅读有关 JNI 的内容,并了解到您应该拥有在代码 (.h) 中输入 JNI 库的源代码。

我的第二次拍摄是 JNA,但我遇到了同样的错误,尽管您不必更改 DLL 中的任何内容。

我创建了两个类来测试:

接口(interface):

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 twoways to do this:

  1. The preferred method is to set the jna.library.path system property tothe path to your target library. This property is similar tojava.library.path, but only applies to libraries loaded by JNA.

  2. Change the appropriate library access environment variable before launchingthe VM. This is PATH on Windows, LD_LIBRARY_PATH on Linux, andDYLD_LIBRARY_PATH on OSX.

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

关于java - JNA从java调用没有源代码的DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11942230/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com