6

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?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Amit
  • 33,847
  • 91
  • 226
  • 299
  • It is quite possible 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). – Favonius Jan 26 '11 at 18:20
  • Somehow I am unable to post comment with links :(. I am adding it as ans. – Favonius Jan 26 '11 at 18:27
  • Just try out if the downloaded DLL fixes it, but it would be better to find out which software provides it, and to install excatly that software. It might help to download the DLL and the look into the property page of the DLL file, where the Vendor and Software name are given (or at least should be for reasonable well developed DLLs). – Daniel Jan 26 '11 at 21:19
  • Which windows version are you using?? See my updated ans for the missing dll, but it depends on the Win and IE version. – Favonius Jan 27 '11 at 04:21
  • Didn't know the dependency walker. Thanks a lot for that! :) – brimborium Jun 12 '13 at 15:03

2 Answers2

1

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.

Community
  • 1
  • 1
Favonius
  • 13,959
  • 3
  • 55
  • 95
  • I am using windows XP and IE-8. I asked my vendor and he told me that he is running one application using the same dll on Windows XP only. What I need to do as he has told me that the same dll is working fine for him. – Amit Jan 27 '11 at 18:24
0

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.

Daniel
  • 27,718
  • 20
  • 89
  • 133
  • I have also tried to place the dll file in the same directory in which my MainClass is i.e under package com. It is throwing the same exception – Amit Jan 26 '11 at 14:40
  • What about C:\Windows ? C:\Windows\System32 ? – Daniel Jan 26 '11 at 14:54
  • System.loadLibrary() can load the lib? JNA often doesn't show the real error messages. System.load(absPath) can load the library? If both fail, its not JNAs fault. – Daniel Jan 26 '11 at 15:47