使用 JNA 分配字节数组
我正在尝试开发一个函数来填充作为实际参数传递的字节数组。我正在遵循 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代码中?
谢谢!
I'm trying to develop a function to fill a byte array passed as an actual argument. I am following the example of the documentation of JNA but it is not working. The documentation says:
// 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 ());
My function in C is:
__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;
}
But when printing the array values are the results:
0 20 48 2
How to implement the function allocate_buffer properly?
Or is the problem is in Java code?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决:
正确的 C 函数是:
__declspec(dllexport) void allocate_buffer(unsigned char *bufp, int lenp)
{
}
Resolved:
The correct C function is:
__declspec(dllexport) void allocate_buffer(unsigned char *bufp, int lenp)
{
}