JNA中怎么模拟这个结构体,解决再加分!!急!!!!!!

wsnangua 2012-11-13 05:01:07
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,急~~~~~~~~~~~
...全文
348 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsnangua 2012-11-21
  • 打赏
  • 举报
回复
唉 现在CSDN这么冷清。。。。最终还是自己解决了,不过还是谢谢楼上的TX~
hbwhwang 2012-11-14
  • 打赏
  • 举报
回复
先在C里面把PCI_COMMON_CONFIG sizeof一下,看看多少个byte,就在JAVA里面 new byte[size]。 你自己心里得清楚这个数组中每个字节对应的PCI_COMMON_CONFIG中的属性。
hbwhwang 2012-11-14
  • 打赏
  • 举报
回复
你直接把这个structure当成一个byte[]来处理吧
wsnangua 2012-11-13
  • 打赏
  • 举报
回复
谢谢帮顶的大家,我用的是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高手呀,求解惑!!!
永生天地 2012-11-13
  • 打赏
  • 举报
回复
mark,学习,帮顶

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧