title: Java use JNA call dll error:Invalid memory access
body: <p>
  I want to call dll to write/read from hardware.However, I get the error below:</p>
  
  <p>
  dll method:</p>
  
  <pre><code>int NewKey(char *room,char *gate,char *stime,char *guestname,char *guestid, int  overflag, int Breakfast, long *cardno,char * track1,char * track2);
  </code></pre>
  
  <p>java method:</p>
  
  <pre><code>int NewKey(String room, String gate,String time,String guestname,String guestid, int overflag, int Breakfast, NativeLongByReference cardno, String track1, String track2);
  </code></pre>
  
  <p>The api document shows cardno as a out parameter  and track1，track2 could be null.</p>
  
  <pre><code>NativeLongByReference cardNo = new NativeLongByReference ();
  
  int res = CLibrary.INSTANCE.NewKey("010001", "00", "201712021200201712031200", "Guest Name","Account No.", 0, 1, cardNo, null, null);
  </code></pre>
  
  <p>It don t work. So I use a simple method:</p>
  
  <pre><code>dll method :
  
  int EraseCard (long  cardno,char * track1,char * track2);
  </code></pre>
  
  <p>java method:</p>
  
  <pre><code>int EraseCard(NativeLong cardno, String  track1, String  track2); 
  
  NativeLong a = new NativeLong(0L);
  
  int res = CLibrary.INSTANCE.EraseCard (a, null, null);
  </code></pre>
  
  
  
  <p>
  It gets the same error again:</p>
  
  <pre><code>Exception in thread "main" java.lang.Error: Invalid memory access
  at com.sun.jna.Native.invokeInt(Native Method)
  at com.sun.jna.Function.invoke(Function.java:383)
  at com.sun.jna.Function.invoke(Function.java:315)
  at com.sun.jna.Library$Handler.invoke(Library.java:212)
  at A90PmsInterface.main(A90PmsInterface.java:104)
  </code></pre>
  
  <p>It seems like the error only occurs when I try to use the dll methods to read/write from/to hardware.</p>
  
  <p>How can I solve the problem?</p>
  
  <p>details: win7 64 bite, jre1.8 32bite, jna4.1</p>