title: Call a C varargs function from Java through JNA
body: <p>By the looks of <a href="https://github.com/java-native-access/jna/issues?q=vararg" rel="nofollow noreferrer">these past issues</a> and <a href="https://java-native-access.github.io/jna/4.2.1/com/sun/jna/Function.html#invoke-java.lang.Class-java.lang.Object:A-java.util.Map-" rel="nofollow noreferrer">this documentation</a> it appears doable, But how ?</p>
  <p>My trials:</p>
  <p>C</p>
  <pre><code>extern &quot;C&quot; GATEWAY_API void callIntoNative(LPCSTR evt_name, ...);
  
  
  void callIntoNative(LPCSTR evt_name, ...)
  //void callIntoNative(char* evt_name)
  {
      std::cout &lt;&lt; evt_name &lt;&lt; std::endl;
      va_list vargs;
      va_start(vargs, evt_name);
      std::cout &lt;&lt; va_arg(vargs, int) &lt;&lt; &quot;   &quot; &lt;&lt; va_arg(vargs, double) &lt;&lt; std::endl;
      va_end(vargs);
  }
  </code></pre>
  <p>Java</p>
  <pre><code>  // public static native void callIntoNative(String evtName, Object[] varargs);
    //  public static native void callIntoNative(String evtName, Object... varargs);
  //GateWay.callIntoNative(&quot;give me love&quot;, new Object[] {24, new String()});
  
  Function callIntoNative = Function.getFunction(&quot;gateway.dll&quot;, &quot;callIntoNative&quot;);
  callIntoNative.invoke(new Object[]{new String(&quot;give me love&quot;), new Integer(24), new Double(3.14)});
  </code></pre>
  <p>The output from Java program:</p>
  <pre><code>give me love
  1374389535   1.18576e-322
  </code></pre>