2016-09-21 15 views
0

を含む構造体は、私はできませんよ、それぞれの構造は、変数別の構造を含むC構造のJAVA JNA相当JNA:C構造と同等のJava、別の構造変数

コード

typedef struct algorithm_list { 

    unsigned char num_of_alg; 
    unsigned short *algorithm_guid[]; 

} algorithm_list_t; 

typedef struct key_data { 

    unsigned char *key; 

    unsigned short key_length; 

    algorithm_list_t *algorithms; 

} key_data_t; 


    typedef struct key_array { 

    unsigned char read_byte; 

    unsigned char number_of_keys; 

    key_data_t *keys[]; 

} key_array_t; 

を定義する上で助けを必要と私が実装したものが私に無効なメモリアクセスエラーを与えるようにこれらの構造のJAVA JNA等価物を適切に定義する。

答えて

0

これらのどれもstructフィールドはありません。 []*よりも緊密に(より高い優先順位)バインドすることを覚えておいてください。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(); 
} 
関連する問題