title: Passing parameter in JNA
body: <p>This code fills a generated data structure SCANNER_FULL_PLUS_EX and then calls a function ScanReadFull_PlusEx(). Both are generated by <strong>JNAerator</strong> and supposed to create some files like Scan_F.bmp etc.</p>
  
  <p>For <strong>64 bit java</strong> on windows 10 6-bit the file names in byte[512] do not pass properly to the dll. Most of the time file names are <strong>null</strong></p>
  
  <pre><code>    public short SCANTEST(String fileName) {
  
          StringBuilder BitmapNameF = new StringBuilder();
          StringBuilder BitmapNameR = new StringBuilder();
          StringBuilder BitmapNameF_IR = new StringBuilder();
          StringBuilder BitmapNameR_IR = new StringBuilder();
          StringBuilder BitmapNameF_UV = new StringBuilder();
          StringBuilder BitmapNameR_UV = new StringBuilder();
  
          SCANNER_FULL_PLUS_EX m_ScanFullPlusEx = new SCANNER_FULL_PLUS_EX();
  
          m_ScanFullPlusEx.Version = 0;
          m_ScanFullPlusEx.BrightnessFront = 100;
          m_ScanFullPlusEx.ThresholdFront = 100;
          m_ScanFullPlusEx.BrightnessRear = 100;
          m_ScanFullPlusEx.ThresholdRear = 100;
          m_ScanFullPlusEx.BitsPerPixel = 8;
          m_ScanFullPlusEx.ScanMode = 2;
  
          m_ScanFullPlusEx.ScanModeIR = 0;
          m_ScanFullPlusEx.ScanModeUV = 0;
  
          m_ScanFullPlusEx.dwImageWidth = 0;
          m_ScanFullPlusEx.dwImageHeight = 0;
  
          m_ScanFullPlusEx.pImageFront = new NativeLong(0);
          m_ScanFullPlusEx.dwImageSizeFront = 0;
          m_ScanFullPlusEx.pImageRear = new NativeLong(0);
          m_ScanFullPlusEx.dwImageSizeRear = 0;
          m_ScanFullPlusEx.pIR_ImageFront = new NativeLong(0);
          m_ScanFullPlusEx.dwIR_ImageSizeFront = 0;
          m_ScanFullPlusEx.pIR_ImageRear = new NativeLong(0);
          m_ScanFullPlusEx.dwIR_ImageSizeRear = 0;
          m_ScanFullPlusEx.pUV_ImageFront = new NativeLong(0);
          m_ScanFullPlusEx.dwUV_ImageSizeFront = 0;
          m_ScanFullPlusEx.pUV_ImageRear = new NativeLong(0);
          m_ScanFullPlusEx.dwUV_ImageSizeRear = 0;
  
          BitmapNameF.append(fileName + "F.bmp");
          BitmapNameR.append(fileName + "R.bmp");
          BitmapNameF_IR.append(fileName + "F_IR.bmp");
          BitmapNameR_IR.append(fileName + "R_IR.bmp");
          BitmapNameF_UV.append(fileName + "F_UV.bmp");
          BitmapNameR_UV.append(fileName + "R_UV.bmp");
  
          m_ScanFullPlusEx.ImageNameRear = Native.toByteArray(BitmapNameR.toString());
          m_ScanFullPlusEx.ImageNameFront = Native.toByteArray(BitmapNameF.toString());
          m_ScanFullPlusEx.IR_ImageNameFront = Native.toByteArray(BitmapNameF_IR.toString());
          m_ScanFullPlusEx.IR_ImageNameRear = Native.toByteArray(BitmapNameR_IR.toString());
          m_ScanFullPlusEx.UV_ImageNameFront = Native.toByteArray(BitmapNameF_UV.toString());
          m_ScanFullPlusEx.UV_ImageNameRear = Native.toByteArray(BitmapNameR_UV.toString());
  
          // wrap in 512 buffer
          byte[] f1 = new byte[512]; for (int i=0; i&lt;m_ScanFullPlusEx.ImageNameRear.length;i++) f1[i]=m_ScanFullPlusEx.ImageNameRear[i]; m_ScanFullPlusEx.ImageNameRear = f1;
          byte[] f2 = new byte[512]; for (int i=0; i&lt;m_ScanFullPlusEx.ImageNameFront.length;i++) f2[i]=m_ScanFullPlusEx.ImageNameFront[i]; m_ScanFullPlusEx.ImageNameFront = f2;
          byte[] f3 = new byte[512]; for (int i=0; i&lt;m_ScanFullPlusEx.IR_ImageNameFront.length;i++) f3[i]=m_ScanFullPlusEx.IR_ImageNameFront[i]; m_ScanFullPlusEx.IR_ImageNameFront = f3;
          byte[] f4 = new byte[512]; for (int i=0; i&lt;m_ScanFullPlusEx.IR_ImageNameRear.length;i++) f4[i]=m_ScanFullPlusEx.IR_ImageNameRear[i]; m_ScanFullPlusEx.IR_ImageNameRear = f4;
          byte[] f5 = new byte[512]; for (int i=0; i&lt;m_ScanFullPlusEx.UV_ImageNameFront.length;i++) f5[i]=m_ScanFullPlusEx.UV_ImageNameFront[i]; m_ScanFullPlusEx.UV_ImageNameFront = f5;
          byte[] f6 = new byte[512]; for (int i=0; i&lt;m_ScanFullPlusEx.UV_ImageNameRear.length;i++) f6[i]=m_ScanFullPlusEx.UV_ImageNameRear[i]; m_ScanFullPlusEx.UV_ImageNameRear = f6;
  
          short ret = MB2Library.INSTANCE.ScanReadFull_PlusEx(ByteBuffer.wrap(Native.toByteArray(gPort.Global)), m_ScanFullPlusEx, MB2Library.SCAN_OUTPUT_FORMAT_FILE_BMP);
  
          return ret;
      }
  </code></pre>
  
  <p>C header file for the structure.</p>
  
  <pre><code>typedef struct
  {
          int Version;
          int BrightnessFront;
          int ThresholdFront;
  
          int BrightnessRear;
          int ThresholdRear;
          int BitsPerPixel;
  
          int ScanMode;   // Front/Rear/Front-Rear
          int ScanModeIR; // ( not yet implemented ) IR Front/Rear/Front-Rear
          int ScanModeUV; // ( not yet implemented ) UV Front/Rear/Front-Rear
  
          DWORD dwImageWidth;
          DWORD dwImageHeight;
  
          // Front CIS Image
          HANDLE pImageFront;
          DWORD dwImageSizeFront;
  
          // Rear CIS Image
          HANDLE pImageRear;
          DWORD dwImageSizeRear;
  
          // Front IR Image
          HANDLE pIR_ImageFront;
          DWORD dwIR_ImageSizeFront;
  
          // Rear IR Image
          HANDLE pIR_ImageRear;
          DWORD dwIR_ImageSizeRear;
  
          // Front UV Image
          HANDLE pUV_ImageFront;
          DWORD dwUV_ImageSizeFront;
  
          // Rear UV Image
          HANDLE pUV_ImageRear;
          DWORD dwUV_ImageSizeRear;
  
          // images path
          TCHAR ImageNameFront[512];
          TCHAR ImageNameRear[512];
          TCHAR IR_ImageNameFront[512];
          TCHAR IR_ImageNameRear[512];
          TCHAR UV_ImageNameFront[512];
          TCHAR UV_ImageNameRear[512];
  
  } SCANNER_FULL_PLUS_EX;
  
  typedef SCANNER_FULL_PLUS_EX *PSCANNER_FULL_PLUS_EX;
  </code></pre>
  
  <p>EDIT 1:</p>
  
  <pre><code>package mb2;
  
  import java.util.StringTokenizer;
  
  import java.util.Arrays;
  import java.util.List;
  
  import com.sun.jna.Library;
  import com.sun.jna.Native;
  import com.sun.jna.NativeLibrary;
  import com.sun.jna.NativeLong;
  import com.sun.jna.Pointer;
  import com.sun.jna.Structure;
  import com.sun.jna.ptr.ByReference;
  import com.sun.jna.ptr.PointerByReference;
  import com.sun.jna.ptr.IntByReference;
  import com.sun.jna.ptr.ByteByReference;
  import com.sun.jna.ptr.DoubleByReference;
  import com.sun.jna.ptr.FloatByReference;
  import com.sun.jna.ptr.LongByReference;
  import com.sun.jna.ptr.NativeLongByReference;
  import com.sun.jna.ptr.ShortByReference;
  
  public class SCANNER_FULL_PLUS_EX extends Structure {
      public int Version;
      public int BrightnessFront;
      public int ThresholdFront;
      public int BrightnessRear;
      public int ThresholdRear;
      public int BitsPerPixel;
      /** Front/Rear/Front-Rear */
      public int ScanMode;
      /** ( not yet implemented ) IR Front/Rear/Front-Rear */
      public int ScanModeIR;
      /** ( not yet implemented ) UV Front/Rear/Front-Rear */
      public int ScanModeUV;
      public int dwImageWidth;
      public int dwImageHeight;
      /**
       * Front CIS Image&lt;br&gt;
       * C type : HANDLE
       */
      public NativeLong pImageFront;
      public int dwImageSizeFront;
      /**
       * Rear CIS Image&lt;br&gt;
       * C type : HANDLE
       */
      public NativeLong pImageRear;
      public int dwImageSizeRear;
      /**
       * Front IR Image&lt;br&gt;
       * C type : HANDLE
       */
      public NativeLong pIR_ImageFront;
      public int dwIR_ImageSizeFront;
      /**
       * Rear IR Image&lt;br&gt;
       * C type : HANDLE
       */
      public NativeLong pIR_ImageRear;
      public int dwIR_ImageSizeRear;
      /**
       * Front UV Image&lt;br&gt;
       * C type : HANDLE
       */
      public NativeLong pUV_ImageFront;
      public int dwUV_ImageSizeFront;
      /**
       * Rear UV Image&lt;br&gt;
       * C type : HANDLE
       */
      public NativeLong pUV_ImageRear;
      public int dwUV_ImageSizeRear;
      /**
       * images path&lt;br&gt;
       * C type : TCHAR[512]
       */
      public byte[] ImageNameFront = new byte[512];
      /** C type : TCHAR[512] */
      public byte[] ImageNameRear = new byte[512];
      /** C type : TCHAR[512] */
      public byte[] IR_ImageNameFront = new byte[512];
      /** C type : TCHAR[512] */
      public byte[] IR_ImageNameRear = new byte[512];
      /** C type : TCHAR[512] */
      public byte[] UV_ImageNameFront = new byte[512];
      /** C type : TCHAR[512] */
      public byte[] UV_ImageNameRear = new byte[512];
      public SCANNER_FULL_PLUS_EX() {
          super();
      }
      protected List&lt;String&gt; getFieldOrder() {
          return Arrays.asList("Version", "BrightnessFront", "ThresholdFront", "BrightnessRear", "ThresholdRear", "BitsPerPixel", "ScanMode", "ScanModeIR", "ScanModeUV", "dwImageWidth", "dwImageHeight", "pImageFront", "dwImageSizeFront", "pImageRear", "dwImageSizeRear", "pIR_ImageFront", "dwIR_ImageSizeFront", "pIR_ImageRear", "dwIR_ImageSizeRear", "pUV_ImageFront", "dwUV_ImageSizeFront", "pUV_ImageRear", "dwUV_ImageSizeRear", "ImageNameFront", "ImageNameRear", "IR_ImageNameFront", "IR_ImageNameRear", "UV_ImageNameFront", "UV_ImageNameRear");
      }
      public SCANNER_FULL_PLUS_EX(Pointer peer) {
          super(peer);
      }
      public static class ByReference extends SCANNER_FULL_PLUS_EX implements Structure.ByReference {
  
      };
      public static class ByValue extends SCANNER_FULL_PLUS_EX implements Structure.ByValue {
  
      };
  }
  </code></pre>