title: Calling CreateFile using JNA gives UnsatisfiedLinkError: Error looking up function 'CreateFile': The specified procedure could not be found
body: <p>I'm trying to call Win32's <code>CreateFile</code> function on Windows 7 using JNA with the aim being to do a Java implementation of <a href="https://stackoverflow.com/questions/409325/check-if-a-file-is-open-from-another-process/411672#411672">this answer</a> to checking if a file is in use by another process.</p>
  
  <p>The code I have so far is:</p>
  
  <pre><code>import com.sun.jna.Native;
  import com.sun.jna.examples.win32.Kernel32;
  
  public class CreateFileExample {
  
      static int GENERIC_ACCESS = 268435456;
      static int EXCLUSIVE_ACCESS = 0;
      static int OPEN_EXISTING = 3;
  
      public static void main(String[] args) {
          Kernel32 kernel32 = 
              (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
          kernel32.CreateFile("c:\\file.txt", GENERIC_ACCESS, EXCLUSIVE_ACCESS,
              null, OPEN_EXISTING, 0, null);
      }
  }
  </code></pre>
  
  <p>However, running this raises the exception:</p>
  
  <p><code>java.lang.UnsatisfiedLinkError: Error looking up function 'CreateFile': The specified procedure could not be found.</code></p>
  
  <p>If I change <code>"kernel32"</code> in the <code>loadLibrary</code> call to something invalid then instead I get <code>The specified module could not be found</code> so this suggests that the DLL is being found correctly from the library path, but there's something wrong with the way I'm calling <code>CreateFile</code>.</p>
  
  <p>Any ideas what I'm doing wrong?</p>
  
  <hr>
  
  <p><code>CreateFile</code> is defined in <code>com.sun.jna.examples.win32.Kernel32</code> as:</p>
  
  <pre><code>public abstract com.sun.jna.examples.win32.W32API.HANDLE CreateFile(
      java.lang.String arg0,
      int arg1,
      int arg2,
      com.sun.jna.examples.win32.Kernel32.SECURITY_ATTRIBUTES arg3,
      int arg4,
      int arg5,
      com.sun.jna.examples.win32.W32API.HANDLE arg6);
  </code></pre>