简体   繁体   English

如何从JNA中的C字节指针获取字节数组作为返回

[英]How to get byte array as return from C byte pointer in JNA

I am using JNA for access to native functions. 我正在使用JNA访问本机功能。 In my native function one my method is returning byte pointer. 在我的本机函数中,我的方法是返回字节指针。 How could I get same byte array values as return in JNA? 我怎样才能得到与JNA中相同的字节数组值? I have tried by getting as string and convert it to bytes but it's not working. 我尝试通过获取字符串并将其转换为字节来尝试,但是它不起作用。

This is my code: 这是我的代码:

BYTE* GetImageDate(); // in C++

Return a pointer, then use Pointer.getByteArray(0, size) to extract size bytes from the corresponding memory location. 返回一个指针,然后使用Pointer.getByteArray(0, size)从相应的内存位置提取size字节。

Note that you'll have to somehow figure out what size is, unless the function is returning a NUL-terminated C string. 请注意,除非函数返回以NUL结尾的C字符串,否则您必须以某种方式弄清楚size是多少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM