title: JNA How to pass struct from Java to C++ method?
body: <p>I am using JNA for accessing DLL library (C++) methods. </p>
  
  <p>Method I want to access has following signature: <code>int DownloadData(DateTime dateTime);</code></p>
  
  <pre><code>Return Values
    COM_ERROR if an error occurs.
    0 if no new records to download.
    # of records transferred, if successful.
  </code></pre>
  
  <p>, DateTime is a structure (C++ code):</p>
  
  <pre><code>struct DateTime
  {
    int minute;
    int hour;
    int day;
    int month;
    int year;
  };
  </code></pre>
  
  <p>I am doing in follow way:</p>
  
  <pre><code>import com.sun.jna.FunctionMapper;
  import com.sun.jna.Library;
  import com.sun.jna.Native;
  import com.sun.jna.NativeLibrary;
  import com.sun.jna.Structure;
  import java.lang.reflect.Method;
  import java.util.HashMap;
  import java.util.Map;
  
  class JavaApplication1
  {
       public static class DateTime extends Structure {
          public int minute;
          public int hour;
          public int day;
          public int month;
          public int year;
       }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>     public interface CLibrary extends Library
       {
          CLibrary INSTANCE = (CLibrary) Native.loadLibrary("LibPro", CLibrary.class, options);
          int DownloadData(DateTime dateTime);
       }
  </code></pre>
  
  <p>...  </p>
  
  <pre><code>     public static void main(String[] args)
       {
          DateTime dateTime = new DateTime();
            dateTime.day=1;
            dateTime.hour=0;
            dateTime.minute=0;
            dateTime.month=1;
            dateTime.year=2012;
          System.out.println("Record count : "+CLibrary.INSTANCE.DownloadData(dateTime));
       }
  }
  </code></pre>
  
  <p>But my code doesn't return how many record are transferred, but it returns -32704. Library usually returns such a value then something gone wrong.</p>
  
  <p>Am I doing right in JNA terms? What else can I try?</p>
  
  <p>Thanks for help!</p>
  
  <p><strong>UPD</strong>. If I send null value <code>CLibrary.INSTANCE.DownloadData(null)</code> I have the same result</p>