我在这里看到了这个问题的一个很好的答案,但是我对我的确切实现以及在结构内部和外部传递布尔值之间的区别有点不确定。我正在解决一个我已经问过很多问题的问题,但是此时我正在解决可能的错误。在我的结构中,我当前将布尔值简单地作为布尔值传递,而在外部,我正在使用 IntByReference 传递指向我的布尔值的指针。在阅读了其他问题和文档后,我开始意识到这可能不是那么直截了当,而且这很可能是错误的。我的结构是 Matlab 结构 emxArray_char_T,它包含一个布尔值 canFreeData。官方结构定义:
struct emxArray_char_T
{
char *data;
int *size;
int allocatedSize;
int numDimensions;
bool canFreeData;
};
我的班级/结构
@Structure.FieldOrder({ "str", "size", "allocatedSize", "numDimensions", "canFreeData"})
public class emxArray_char_T extends Structure implements Structure.ByReference{
public Pointer str;
private int numVals;
public Pointer size;
public int allocatedSize;
public int numDimensions;
public boolean canFreeData;
//Static
public emxArray_char_T(Pointer str, Pointer size) {
this.str = str;
this.size = size;
}
//Dynamic
public emxArray_char_T(Pointer str, Pointer size, int allocatedSize, int numDimensions, boolean canFreeData) {
this.str = str;
this.size = size;
this.allocatedSize = allocatedSize;
this.numDimensions = numDimensions;
this.canFreeData = canFreeData;
}
public emxArray_char_T() {
}
}
在此范围内,布尔值作为我不确定是否正确的值被传递,并希望对此提出建议?
我有另一个问题,因为我通过与传入该结构的初始化函数相同的初始化函数在结构外部传递了一个布尔值:
extern void Initialise(const emxArray_char_T *cStatic, const
emxArray_char_T *cDynamic, int b_angleDeg, double
b_offset, int b_number, int
b_angleDeg, int b_mode, bool *status, bool
*pStatus);
通过这种方法给我带来了问题,我需要把它做好。当我映射到这个函数时,我这样做:
void Initialise(emxArray_char_T cStatic, emxArray_char_T cDynamic, int b_angleDeg, double
b_offset, int b_number, int b_angleDeg, int b_mode, IntByReference status, IntByReference pStatus);
如前所述,下面链接了一个非常好的问题/答案,但是我很难理解这是否是我需要实现的东西,如果是的话,我将如何处理我的功能。我是 JNA 的新手,正在努力快速学习。我感谢所有的帮助。