我正在尝试开发一个函数来填充作为实际参数传递的字节数组。我正在遵循 JNA 文档的示例,但它不起作用。文档说:
// Original C declaration allocate_buffer <br>
void (char ** bufp, int * lenp);
// Equivalent JNA mapping
void allocate_buffer (PointerByReference bufp, IntByReference lenp);
// Usage
PointerByReference PointerByReference pref = new ();
IntByReference IntByReference iref = new ();
lib.allocate_buffer (pref, iref);
Pref.getValue Pointer p = ();
byte [] buffer = p.getByteArray (0, iref.getValue ());
我在 C 中的功能是:
__declspec (dllexport) void allocate_buffer (char ** bufp, int * lenp)
{
char array [4];
array [0] = 0;
array [2] = 1;
array [3] = 2;
array [4] = 3;
* bufp = array;
* lenp = 4;
}
但是当打印数组值时,结果是:0 20 48 2
如何正确实现函数allocate_buffer?还是问题出在Java代码中?
谢谢!