我开始使用JNA与计算机的RS485接口上的设备进行通信.令我惊讶的是,我很快就取得了良好的效果.但现在我被一个简单的问题所困扰.我使用的库接受指向struct指针的指针.实际的签名是
func(Struct1 **, Struct2 **, Struct3 *, Struct4 *, long)
现在指示库期望最后一个指针为NULL指针的第一个参数的大小.这是失败的.以下代码是我到目前为止所尝试的:
Struct1.ByReference[] s = (Struct1.ByReference[]) new Struct1.ByReference().toArray(size);
int pos = 0;
// ...
// for loop to set the s[pos] struture values
for(pos = 0; pos < size - 1; pos++)
// ...
// Now set the last array element to a null pointer to indicate end-of-list
s[pos].getPointer().setPointer(0, null);// Following does not work: results in zero memoried structure
s[pos] = null; // Following does not work wither: NullPointerException at com.sun.jna.Structure.autoWrite …Run Code Online (Sandbox Code Playgroud)