title: Using winapi in java application
body: <p>I've tried to invoke the MessageBoxA function in a JAVA code. What is wrong with the following approaches, so that my program throws a lot of errors?</p>
  
  <pre><code>package loading.libraries;
  
  public class User32
  {
      //first case:public native int MessageBoxA(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType);
      //second: public native int MessageBoxA(int hWnd,String lpText,String lpCaption,int uType);
      static  
      {
          System.loadLibrary("User32");
      }        
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>package loading.libraries;
  
  public class LoadingLibraries 
  {
      public static void main(String[] args) 
      {
          User32 hwapi = new User32();
  
          hwapi.MessageBoxA(0,"Hello","World",0);               
      }
  }
  </code></pre>
  
  <p>1-st:</p>
  
  <blockquote>
    <p>run: Exception in thread "main" java.lang.ClassFormatError: Code
    attribute in native or abstract methods in class file
    loading/libraries/MessageBox  at
    java.lang.ClassLoader.defineClass1(Native Method)     at
    java.lang.ClassLoader.defineClass(ClassLoader.java:791)   at
    java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)     at
    java.net.URLClassLoader.access$100(URLClassLoader.java:71)    at
    java.net.URLClassLoader$1.run(URLClassLoader.java:361)    at
    java.net.URLClassLoader$1.run(URLClassLoader.java:355)    at
    java.security.AccessController.doPrivileged(Native Method)    at
    java.net.URLClassLoader.findClass(URLClassLoader.java:354)    at
    java.lang.ClassLoader.loadClass(ClassLoader.java:423)     at
    sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)     at
    java.lang.ClassLoader.loadClass(ClassLoader.java:356)     at
    loading.libraries.LoadingLibraries.main(LoadingLibraries.java:8) Java
    Result: 1 BUILD SUCCESSFUL (total time: 2 seconds)</p>
  </blockquote>
  
  <p>2-nd:</p>
  
  <blockquote>
    <p>run: Exception in thread "main" java.lang.UnsatisfiedLinkError:
    loading.libraries.User32.MessageBoxA(ILjava/lang/String;Ljava/lang/String;I)I
      at loading.libraries.User32.MessageBoxA(Native Method)  at
    loading.libraries.LoadingLibraries.main(LoadingLibraries.java:10) Java
    Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)</p>
  </blockquote>