Pointers JNA:指向指向结构的指针的指针

Pointers JNA:指向指向结构的指针的指针,pointers,struct,pass-by-reference,jna,jnaerator,Pointers,Struct,Pass By Reference,Jna,Jnaerator,我有一个函数调用: long foo(mystruct**list) 其中mystruct的定义为 typedef struct { otherstruct *bar[64]; } mystruct; 我试图得到对应于bar的(JNA)结构[]。我当前的函数定义是intfoo(PointerByReference列表)

我有一个函数调用:

long foo(mystruct**list)

其中
mystruct
的定义为

typedef struct {
    otherstruct *bar[64];
} mystruct;
我试图得到对应于bar的(JNA)结构[]。我当前的函数定义是
intfoo(PointerByReference列表)
在C中,代码的使用方式如下:

mystruct *list;
foo(&list);
for (i=0; i<64; i++)
    doStuff(list->bar[i]);
mystruct*列表;
foo&list;
对于(i=0;ibar[i]);
  • PointerByReference
    是合适的;使用
    getValue()
    获取
    指针
    价值观
  • 使用该值初始化“mystruct”结构
  • 由于“
    otherstruct*bar[64]
    ”表示
    struct*
    的数组,因此需要显式使用
    Structure类型的字段。通过引用[]
    强制JNA将数组视为指针,而不是内联结构
  • 代码:

    JNA应该隐式地调用Structure.read()和Structure.write(),必要时围绕本机函数调用,但除此之外,您可能需要根据使用情况显式地进行这些调用

    class OtherStruct extends Structure {
        class ByReference extends OtherStruct implements Structure.ByReference { }
        ...
    }
    class MyStructure extends Structure {
        public OtherStruct.ByReference[] bar = new OtherStruct.ByReference[64];
    }