title: Problem in accessing dll file from a Java program through JNA
body: <p>I have a dll file and I am trying to call functions of it through a Java program through <a href="http://jna.dev.java.net" rel="nofollow">JNA</a></p>
  
  <p>But the problem is It is not able to locate my dll file and throwing the following exception:</p>
  
  <pre><code>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.&lt;clinit&gt;(MainClass.java:15)
  Exception in thread "main"  
  </code></pre>
  
  <p>Below is my program:</p>
  
  <pre><code>package com;
  
  import com.sun.jna.Native
  
  public class MainClass {
  
      static {
          Native.register("UsbDll");
      }
  
  public native int method();
  
      public static void main(String[] args) {
      }
  }
  </code></pre>
  
  <p>The name of my dll file is <b>UsbDll.dll</b> and my operating system is Windows.</p>
  
  <p>============================ EDITED ================================</p>
  
  <p>The location of my dll file is "c:\UsbDll.dll"</p>
  
  <p>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.</p>
  
  <p>When I tried to load both the dll files (UsbDll.dll and the another dll) with the following command</p>
  
  <pre><code>System.load("c:\\UsbDll.dll");
  System.load("c:\\another.dll");
  </code></pre>
  
  <p>It loaded the "another.dll" successfully but for "UsbDll.dll", it throws the following exception:</p>
  
  <pre><code>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.&lt;clinit&gt;(MainClass.java:16)
  
  Exception in thread "main" 
  </code></pre>
  
  <p>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.</p>
  
  <p>OR</p>
  
  <p>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?</p>
  
  <p>============================ EDITED #2 ================================</p>
  
  <p>I ran the <a href="http://www.dependencywalker.com/" rel="nofollow">Dependency Walker</a> on my UsbDll.dll file to find the missing dependencies and found the following missing dependencies.</p>
  
  <p><b>WER.DLL</b>       (referred by library <b>WINNM.DLL</b> found in my c:\windows\system32)</p>
  
  <p><b>IESHIMS.DLL</b>   (referred by library <b>WINNM.DLL</b> found in my c:\windows\system32)</p>
  
  <p><b>WDAPI920.DLL</b>  (referred directly by my UsbDll.dll)</p>
  
  <p>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 &amp; IESHIMS.DLL), then I suspect how other applications are working who are using this WINNM.DLL file?</p>
  
  <p>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?</p>