Java程序通过JNA访问dll文件的问题

发布于 2024-10-14 02:10:07 字数 2630 浏览 4 评论 0原文

我有一个 dll 文件,我试图通过 JNA 通过 Java 程序调用它的函数,

但是问题它无法找到我的 dll 文件并引发以下异常:

java.lang.UnsatisfiedLinkError: Unable to load library 'UsbDll': The specified module could not be found.

at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:199)
at com.sun.jna.Native.register(Native.java:1018)
at com.MainClass.<clinit>(MainClass.java:15)
Exception in thread "main"  

下面是我的程序:

package com;

import com.sun.jna.Native

public class MainClass {

    static {
        Native.register("UsbDll");
    }

public native int method();

    public static void main(String[] args) {
    }
}

我的 dll 文件的名称是 UsbDll.dll,我的操作系统是 Windows。

===========================已编辑===================== ===========

我的 dll 文件的位置是“c:\UsbDll.dll”

当我将另一个 dll 文件放在同一位置时,JNA 已找到它,所以我认为问题出在我的仅“UsbDll.dll”文件。

当我尝试使用以下命令加载两个 dll 文件(UsbDll.dll 和另一个 dll)时,

System.load("c:\\UsbDll.dll");
System.load("c:\\another.dll");

它成功加载了“another.dll”,但对于“UsbDll.dll”,它抛出以下异常:

java.lang.UnsatisfiedLinkError: C:\UsbDll.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1699)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1003)
at com.MainClass.<clinit>(MainClass.java:16)

Exception in thread "main" 

Q1。看起来它没有找到一些依赖库。但由于我对这些 dll 完全陌生,是否有任何我遗漏的东西,或者我需要要求供应商为我提供依赖库。

或者

它是否取决于我可以从互联网下载的一些标准库?如果是,那么如何找到它所依赖的库名称呢?

============================ 已编辑 #2 =================== =============

我在 UsbDll.dll 文件上运行了 Dependency Walker查找缺少的依赖项并发现以下缺少的依赖项。

WER.DLL(由在我的 c:\windows\system32 中找到的库 WINNM.DLL 引用)

IESHIMS.DLL(由库 WINNM.DLL 引用) >WINNM.DLL 在我的 c:\windows\system32 中找到)

WDAPI920.DLL(由我的 UsbDll.dll 直接引用)

Q1。由于 WINNM.DLL 在我的 system32 文件夹中找到,它似乎是标准 dll。如果这个标准 dll 引用了 2 个缺失的 dll(WER.DLL 和 IESHIMS.DLL),那么我怀疑其他正在使用这个 WINNM.DLL 文件的应用程序是如何工作的?

Q2。我在 google 上搜索 WDAPI920.dll(直接引用了我的 UsbDll.dll),许多搜索结果都出现了相同的 dll 名称。所以它看起来也像一些标准库。那么如何修复这些依赖关系呢?从哪里下载它们?下载后,我可以将它们放在我的主 dll (UsbDll.dll) 所在的同一目录中吗?或者我需要做一些额外的事情才能成功加载我的 dll (UsbDll.dll)?

I have a dll file and I am trying to call functions of it through a Java program through JNA

But the problem is It is not able to locate my dll file and throwing the following exception:

java.lang.UnsatisfiedLinkError: Unable to load library 'UsbDll': The specified module could not be found.

at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:199)
at com.sun.jna.Native.register(Native.java:1018)
at com.MainClass.<clinit>(MainClass.java:15)
Exception in thread "main"  

Below is my program:

package com;

import com.sun.jna.Native

public class MainClass {

    static {
        Native.register("UsbDll");
    }

public native int method();

    public static void main(String[] args) {
    }
}

The name of my dll file is UsbDll.dll and my operating system is Windows.

============================ EDITED ================================

The location of my dll file is "c:\UsbDll.dll"

When I placed another dll file at the same location, JNA has located it so I think that the problem is with my "UsbDll.dll" file only.

When I tried to load both the dll files (UsbDll.dll and the another dll) with the following command

System.load("c:\\UsbDll.dll");
System.load("c:\\another.dll");

It loaded the "another.dll" successfully but for "UsbDll.dll", it throws the following exception:

java.lang.UnsatisfiedLinkError: C:\UsbDll.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1699)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1003)
at com.MainClass.<clinit>(MainClass.java:16)

Exception in thread "main" 

Q1. It looks like it is not finding some dependent libraries. But as I am totally new to these dlls, Is there anything I am missing or I need to ask the vendor to provide me the dependent libraries.

OR

Is it depends on some standard libraries which I can download from internet? If it is, then how to find the libraries name on which it depends?

============================ EDITED #2 ================================

I ran the Dependency Walker on my UsbDll.dll file to find the missing dependencies and found the following missing dependencies.

WER.DLL (referred by library WINNM.DLL found in my c:\windows\system32)

IESHIMS.DLL (referred by library WINNM.DLL found in my c:\windows\system32)

WDAPI920.DLL (referred directly by my UsbDll.dll)

Q1. As WINNM.DLL was found in my system32 folder, it seems as the standard dll. And if this standard dll is referring to 2 missing dlls (WER.DLL & IESHIMS.DLL), then I suspect how other applications are working who are using this WINNM.DLL file?

Q2. I googled for WDAPI920.dll (that was referred my UsbDll.dll directly) and many search results appeared with the same dll name. So it also looks like some standard library. So how to fix these dependencies? From where to download them? After downloading, Can I place them in the same directory in which my main dll (UsbDll.dll) is or I need to do something extra to load my dll (UsbDll.dll) sucessfully?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妳是的陽光 2024-10-21 02:10:07

从您编辑的代码中可以明显看出,UsbDll.dll 依赖于您系统上不存在的一些标准模块(例如,如果它使用 ATL 并且您没有适当的运行时,那么它肯定会失败)。要解决此问题,您将需要适当的运行时环境。

此外所涉及的 dll 可能依赖于某些供应商特定的模块。对于您来说,最好的选择是(最快的选择是)联系供应商。否则,尝试从微软网站安装正确的运行时(但更多的是尝试)


Update

使用以下链接查找有关 DLL 依赖项的更多信息:

  1. 如何如何确定 .NET 应用程序的依赖项?
  2. http:// /msdn.microsoft.com/en-us/library/ms235265.aspx
  3. 查找 Dll 依赖项的命令行工具

Update 2

请参阅下面提到的链接以获取缺少的 dll 详细信息(但它特定于 Windows 版本)

  1. Dependency Walker 报告 IESHIMS.DLL 和 WER.DLL 丢失?
  2. http://social.msdn.microsoft.com/Forums/en/vsx/thread/6bb7dcaf-6385-4d24-b2c3-ce7e3547e68b

从几个简单的谷歌查询,WDAPIXXX.dll似乎是一些与win驱动程序相关的东西(尽管我不太确定)。检查此链接,他们对 WDAPI 有话要说 http://www.jungo .com/st/support/tech_docs/td131.html

From your edited code it is quite evident that the UsbDll.dll depends on some standard modules which are not there on your system (for example if it uses ATL and if you have don't have proper runtime then it is guaranteed to fail). To resolve this you will need proper runtime environment.

Also it is possible that the dll in concern depends on some vendor specific module. For you the best option is (and fastest option would be) to contact the vendor. Otherwise, try to install proper runtime from the microsoft site (but its more of hit-and-trial)


Update

Use the below links for finding more about DLL dependency:

  1. How do I determine the dependencies of a .NET application?
  2. http://msdn.microsoft.com/en-us/library/ms235265.aspx
  3. Command line tool to find Dll dependencies


Update 2

See the below mentioned link for the missing dll details (but it is specific to the windows version)

  1. Dependency Walker reports IESHIMS.DLL and WER.DLL missing?
  2. http://social.msdn.microsoft.com/Forums/en/vsx/thread/6bb7dcaf-6385-4d24-b2c3-ce7e3547e68b

From few simple google queries, WDAPIXXX.dll appears to be some win driver related thing (although i am not too sure). Check this link, they have something to say about WDAPI http://www.jungo.com/st/support/tech_docs/td131.html.

寒尘 2024-10-21 02:10:07

DLL 必须位于 LD_LIBRARY_PATH 指定的路径中(请参阅您的环境),或者,对于 JNA,位于当前目录中。

The DLL must by in the Path specified by LD_LIBRARY_PATH (see your env), or, in the case of JNA, in the current directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文