java - JNA passed values not updating -


i'm new jna. im having issue im passing structure library call updates variables. when directly in c code main method works, when try access using jna values not updated.

the values im trying are: ser, sername, hw, hwname, oem, oemname

the method i'm trying access in jna:

__declspec(dllexport) bool _cdecl getsn(         devprograminfo           * pdevproginfo,         unsigned char              sessionid) {       unsigned char                   * pcmd;     unsigned short                    cmdlen = 0;     platform_access_get_sn_payload     * pbufgetsn;      pcmd = (unsigned char *)&cmd;     pbufgetsn = (platform_access_get_sn_payload *)&payload;      clearmsgheader((message *)pcmd);      platform_get_sn(pcmd, sessionid, &cmdlen, (unsigned char *)pbufgetsn);     usbwritetodevice(&pdevproginfo->deviceinfo, pcmd, &cmdlen);     usbreadfromdevice(&pdevproginfo->deviceinfo, pcmd);     platform_get_sn(pcmd, sessionid, &cmdlen, (unsigned char *)pbufgetsn);      pdevproginfo->sn.sn.ser = pbufgetsn->resp.ser;     strcpy((char *)pdevproginfo->sn.sn.sername, (char *)pbufgetsn->resp.sername);     pdevproginfo->sn.sn.hw = pbufgetsn->resp.hw;     strcpy((char *)pdevproginfo->sn.sn.hwname, (char *)pbufgetsn->resp.hwname);     pdevproginfo->sn.sn.oem = pbufgetsn->resp.oem;     strcpy((char *)pdevproginfo->sn.sn.oemname, (char *)pbufgetsn->resp.oemname);      return true; } 

my jna declaration of method is

public boolean getsn(devprograminfo devinfo, byte sessionid); 

i built structure in java, here "sn.sn" creating in java

public class mysn extends union {     /// c type : field_struct      public field_struct field;     /// c type : sn_struct     public sn_struct sn;     /// <i>native declaration : line 3</i>     /// <i>native declaration : line 3</i>      public static class field_struct extends structure {         /// unique each pid+version+variant          public nativelong sequence;         public byte variant;         public byte version;         public short pid;          public field_struct() {             super();         }          protected list getfieldorder() {             return arrays.aslist("sequence", "variant", "version", "pid");         }          public field_struct(nativelong sequence, byte variant, byte version, short pid) {             super();             this.sequence = sequence;             this.variant = variant;             this.version = version;             this.pid = pid;         }          public static class byreference extends field_struct implements structure.byreference {         };          public static class byvalue extends field_struct implements structure.byvalue {         };          public boolean copy(field_struct fieldinfo) {             this.sequence = fieldinfo.sequence;             this.variant = fieldinfo.variant;             this.version = fieldinfo.version;             this.pid = fieldinfo.pid;             return true;         }     };     /// <i>native declaration : line 9</i>     /// <i>native declaration : line 9</i>      public static class sn_struct extends structure {          public nativelong ser;         public byte[] sername = new byte[20];         public nativelong hw;         public byte[] hwname = new byte[20];         public nativelong oem;         public byte[] oemname = new byte[20];          public sn_struct() {             super();         }          protected list getfieldorder() {             return arrays.aslist("ser", "sername", "hw", "hwname", "oem", "oemname");         }         public sn_struct(nativelong ser, byte sername[], nativelong hw, byte hwname[], nativelong oem, byte oemname[]) {             super();             this.ser = ser;             if (sername.length != this.sername.length) {                 throw new illegalargumentexception("wrong array size !");             }             this.sername = sername;             this.hw = hw;             if (hwname.length != this.hwname.length) {                 throw new illegalargumentexception("wrong array size !");             }             this.hwname = hwname;             this.oem = oem;             if (oemname.length != this.oemname.length) {                 throw new illegalargumentexception("wrong array size !");             }             this.oemname = oemname;         }          public static class byreference extends sn_struct implements structure.byreference {         };          public static class byvalue extends sn_struct implements structure.byvalue {         };     };      public mysn() {         super();     }     /// @param sn c type : sn_struct      public mysn(sn_struct sn) {         super();         this.sn = sn;         settype(sn_struct.class);     }     /// @param field c type : field_struct      public mysn(field_struct field) {         super();         this.field = field;         settype(field_struct.class);     }      public static class byreference extends mysn implements structure.byreference {     };      public static class byvalue extends mysn implements structure.byvalue {     }; } 

when use code

myjna.getsn(devinfo, (byte) 0); 

all of variables (ser, sername, hw, hwname, oem, oemname) 0's. ive been stumped on issue week , cant seem figure out issue.

when add printf's dll correct values generated structures there, not values in objects in java.

any appreciated!

you're using union. unless set "active" type, jna can automatically read primitive fields (you wouldn't want read 'const char*` field of union if integer value zero).

call union.settype(class) before call if know it; otherwise call after native call followed structure.read().


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -