這些沒有一個struct
字段。請記住,[]
與*
綁定更緊密(更高的優先級),您分別有一個指向short的指針數組,指向struct
的指針(或更可能指向連續數組struct
的指針),以及一組數組指向struct
。
指針類型的最簡單映射是Pointer
。一旦你得到這個工作,你可以將其改進爲更具體的類型。
struct*
應該使用Structure.ByReference
作爲字段類型,並且這些的數組應該是Structure.ByReference[]
。
如在描述的JNA FAQ(省略getFieldOrder()
並且爲了簡潔的構造函數):
public class algorithm_list extends Structure {
public static class ByReference extends algorithm_list implements Structure.ByReference { }
public byte num_of_alg;
public Pointer[] algorithm_guid = new Pointer[1];
public algorithm_list(Pointer p) {
super(p);
int count = (int)readField("num_of_alg") & 0xFF;
algorithm_guid = new Pointer[count];
super.read();
}
public class key_data extends Structure {
public static class ByReference extends key_data implements Structure.ByReference { }
public Pointer key;
public short key_length;
public algorithm_list.ByReference algorithms;
public key_data(Pointer p) {
super(p);
super.read();
// NOTE: if algorithms points to a contiguous block of struct,
// you can use "algorithms.toArray(count)" to get that array
}
}
public class key_array {
public byte read_byte;
public byte number_of_keys;
public key_data.ByReference[] keys = new key_data.ByReference[1];
public key_array(Pointer p) {
super(p);
int count = (int)readField("number_of_keys") & 0xFF;
keys = new key_data.ByReference[count];
super.read();
}