title: JNA: char array as function parameter
body: <p>Using JNA, I am loading a dll written in C++ and calling function present within that C++ function:</p>
  
  <pre><code> int xxfunction(Char* ptr){...}
  </code></pre>
  
  <p>Here I need to send a char array so that function will assign value to it. Basically I need to pass char array by reference.</p>
  
  <p>According to the JNA documentation, C++ <code>char*</code> equivalent in Java is <code>String</code>, so I created a String object and passed it to the function like shown below:</p>
  
  <p><strong>Java function declaration:</strong></p>
  
  <pre><code>interface foo extends Library
  {
   ....//loading dll and other work
    int xxfunction(String chararray);//function declaration
  }
  </code></pre>
  
  <p><strong>Java function call:</strong></p>
  
  <pre><code>public static void main(String args[]) 
  {
   String str="abcd";
   int i=fooinstance.xxfunction(str);//function call
  }
  </code></pre>
  
  <p>but when I executed this code it is giving me:</p>
  
  <blockquote>
    <p>A fatal error has been detected by the Java Runtime Environment:
    Failed to write core dump. Minidumps are not enabled by default on
    client versions of Windows</p>
  </blockquote>
  
  <p>The crash happened outside of the Java Virtual Machine in native code. See problematic frame for where to report the bug.</p>
  
  <p>So is it the correct way to pass String as an argument where function expects char pointer?
  C++ char equivalent in java is byte, so do I need to pass byte array as a parameter?</p>
  
  <p>I can't even pass Pointer object from JNA to function because it gives me <code>IllegalargumentException</code>.</p>