title: JNA - Access Violation, JVM terminats
body: <p>I am calling a DLL with passing a callback functio object to it. One of the functions is simple print. I have then, a loop of 100 iterations, just printing the index and a few prints after the loop.</p>
  
  <hr>
  
  <p>Here is the C code</p>
  
  <pre><code>extern "C" int Start(void* callback(CString))
  {
     for(int j=0; j&lt;100; j++)
      callback(AConvertToString(j));
  
     callback("in Start called from Java");
     callback("another line");
  }
  </code></pre>
  
  <hr>
  
  <p>Here is the Java code</p>
  
  <pre><code>public interface MyDll extends Library{
    MyDll INSTANCE = (MyDll) Native.loadLibrary("MyDll",MyDll.class);
       public interface MyCallback extends StdCallCallback {
              public boolean callback(String msg);
       }
       public int Start(MyCallback callback);
    }
  
  //in main:
  ...
    MyDll myDll = (MyDll)MyDll.INSTANCE;
    myDll.Start(new MyDll.MyCallback() {
        public boolean callback(String msg) {
           System.out.println(msg);
            return true;          
        }
  });
  </code></pre>
  
  <p>The output is numbers 0..41 (YES 41!!! not 99) and then "in Start called from Java" followed by a horrible crash:</p>
  
  <pre><code>#
  # An unexpected error has been detected by Java Runtime Environment:
  #
  #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c809823, pid=468, tid=2636
  #
  # Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode, sharing windows-x86)
  # Problematic frame:
  # C  [kernel32.dll+0x9823]
  </code></pre>
  
  <p>I've read alot (here as well) yet I cannot find the problem.
  I am running JRE of Java6. I have 1.5GB of memory on my machine. The DLL is not used by any other process (no concurrency issues).</p>
  
  <p>Thanks,
  Azriel</p>