求助Java调用jna如何模拟这个结构体

原生结构体如下:

typedef struct iodbpmc {
short type_a ; /* Kind of PMC address /
short type_d ; /
Type of the PMC data /
short datano_s ; /
Start PMC address number /
short datano_e ; /
End PMC address number /
union {
char cdata[N] ;/
The PMC data(byte type) /
short idata[N] ;/
(word type) /
long ldata[N] ;/
(long type) /
} u ; /
N is the number of written data */
} IODBPMC ;

java 模拟如下:
public class IODBPMC extends Structure {

public short type_a; // Kind of PMC address
public short type_d; // Type of the PMC data
public short datano_s; // Start PMC address number
public short datano_e; // End PMC address number
public union u  ;

public static class ByReference extends IODBPMC implements Structure.ByReference {
}

public static class ByValue extends IODBPMC implements Structure.ByValue {
}

public static class union extends Union {
    public byte[] cdata = new byte[5];
    public short[] idata = new short[5] ;
    public NativeLong[] ldata = new NativeLong[5]; 

    public static class ByReference extends union implements Union.ByReference {
    }

    public static class ByValue extends union implements Union.ByValue {
    }
    protected List<String> getFieldOrder() {

        return Arrays.asList(new String[] { "cdata", "idata", "ldata" });
    }
}

protected List<String> getFieldOrder() {

    return Arrays.asList(new String[] { "type_a", "type_d", "datano_s", "datano_e", "u" });
}

}

测试结果智能写入0,使用C#写的小程序就能完成写入

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!