当使用BridJ生成JNAerator代码时,它将无符号类型(例如windows的ULONG)映射到普通的long:
// c code
typedef struct _S {
USHORT a;
ULONG b;
ULONG64 c;
} S;
// generated java code
class S extends StructObject {
@Field(0)
public short a() {
return this.io.getShortField(this, 0);
}
@Field(0)
S setA(short a) {
this.io.setShortField(this, 0, a);
return this;
}
@CLong
@Field(1)
public long b() {
return this.io.getCLongField(this, 2);
}
@CLong
@Field(1)
S setB(long b) {
this.io.setCLongField(this, 2, b);
return this;
}
// ULONG64 is ignored and not generated at all但是,Java类型是有符号的,而不是无符号的。如果需要手动更正,需要使用哪些类型?像这样的字节数组?
@Field(0)
public byte[] a() { ... };
@Field(0)
public byte[] setA(byte[] a) { // check correct length };发布于 2015-02-19 11:34:53
有符号类型和无符号类型的大小相同,只是语义不同。您肯定应该使用JNAerator选择的类型,并使用处理Java 8中介绍的 (例如,Integer.divideUnsigned)之类的无符号类型的Java原语。
如果Java 8对您来说不是一个选项,那么您可以只使用明智地使用转换和操作位。
https://stackoverflow.com/questions/28581703
复制相似问题