首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

JNA中如何模拟这个结构体,解决再加分!

2012-12-15 
JNA中怎么模拟这个结构体,解决再加分!!急!!!!!!typedef struct _PCI_COMMON_CONFIG {USHORT VendorIDUSHO

JNA中怎么模拟这个结构体,解决再加分!!急!!!!!!
typedef struct _PCI_COMMON_CONFIG {
  USHORT VendorID;
  USHORT DeviceID;
  USHORT Command;
  USHORT Status;
  UCHAR  RevisionID;
  UCHAR  ProgIf;
  UCHAR  SubClass;
  UCHAR  BaseClass;
  UCHAR  CacheLineSize;
  UCHAR  LatencyTimer;
  UCHAR  HeaderType;
  UCHAR  BIST;
  union {
    struct {
      ULONG BaseAddresses[6];
      ULONG Reserved1[2];
      ULONG ROMBaseAddress;
      ULONG Reserved2[2];
      UCHAR InterruptLine;
      UCHAR InterruptPin;
      UCHAR MinimumGrant;
      UCHAR MaximumLatency;
    } type0;
  } u;
  UCHAR  DeviceSpecific[192];
} PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;

其中
typedef unsigned short USHORT;
typedef unsigned char UCHAR;
typedef unsigned long ULONG;

这个结构体在java中怎么对应?我用的JNA,急~~~~~~~~~~~
[最优解释]
你直接把这个structure当成一个byte[]来处理吧
[其他解释]
mark,学习,帮顶
[其他解释]
先在C里面把PCI_COMMON_CONFIG sizeof一下,看看多少个byte,就在JAVA里面 new byte[size]。
你自己心里得清楚这个数组中每个字节对应的PCI_COMMON_CONFIG中的属性。
[其他解释]
谢谢帮顶的大家,我用的是JNA,直接调用dll,不用自己写dll文件了~~~
看了网上的参考资料,我对应的java部分如下:

public static class pciConfig extends Structure {

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

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

public short VendorID;
public short DeviceID;
public short Command;
public short Status;
public byte RevisionID;
public byte ProgIf;
public byte SubClass;
public byte BaseClass;
public byte CacheLineSize;
public byte LatencyTimer;
public byte HeaderType;
public byte BIST;

public static class type0 extends Structure {

public static class ByReference extends type0 implements
Structure.ByReference {
}
public static class ByValue extends type0 implements
Structure.ByValue {
}
public NativeLong[] BaseAddresses = new NativeLong[3];
public NativeLong[] Reserved1 = new NativeLong[2];
public NativeLong ROMBaseAddress;
public NativeLong[] Reserved2 = new NativeLong[2];
public byte InterruptLine;
public byte InterruptPin;
public byte MinimumGrant;
public byte MaximumLatency;
}


public static class union extends Union {

public static class ByReference extends union implements
Union.ByReference {
}
public static class ByValue extends union implements Union.ByValue {
}
public type0 typ;
}
public union u;
public byte[] DeviceSpecific = new byte[192];

}


但是老是报错,网上的例子中结构体都木有这么复杂,我不知道这种嵌套的怎么写,有木有JNA高手呀,求解惑!!!
[其他解释]
唉 现在CSDN这么冷清。。。。最终还是自己解决了,不过还是谢谢楼上的TX~

热点排行