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];
}