Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 使用JNA分配字节数组_Arrays_Pointers_Char_Jna - Fatal编程技术网

Arrays 使用JNA分配字节数组

Arrays 使用JNA分配字节数组,arrays,pointers,char,jna,Arrays,Pointers,Char,Jna,我试图开发一个函数来填充作为实际参数传递的字节数组。我遵循JNA文档的示例,但它不起作用。文件说: // Original C declaration allocate_buffer <br> void (char ** bufp, int * lenp); // Equivalent JNA mapping void allocate_buffer (PointerByReference bufp, IntByReference lenp); // Usage PointerB

我试图开发一个函数来填充作为实际参数传递的字节数组。我遵循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 ());
但在打印数组值时,结果是: 020482

如何正确实现分配缓冲区功能? 还是问题出在Java代码中

谢谢

已解决: 正确的C函数是:

__declspec(dllexport)void allocate_缓冲区(无符号字符*bufp,int lenp)

{

}

__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;
}
    unsigned char *array = (unsigned char *)malloc(4*sizeof(unsigned char));

    array[0] = 0;
    array[1] = 1;
    array[2] = 2;
    array[3] = 3;

    *bufp = array;
    *lenp = 4;