JNA pointer to unsigned char*

流过昼夜 提交于 2020-01-05 12:09:06

问题


I have an array of bytes and I want to pass it to C function using JNA. However I only found examples which allocated a pointer using new Memory and used write function to copy array data but for me is not acceptable because I have big block of data.

Is there a possibility just to pass my Java array directly to c library ?

I want to do something like this :

MyLib lib = Native.loadLibrary("test");
Pointer p = myByteArray; //I want to make it possible
lib.someFunction(p);

回答1:


Passing a primitive array or a Pointer to memory are equivalent operations, i.e. you can map like this:

public interface MyLibrary extends Library {
    void someFunction(byte[] input);
    void someFunction(Pointer input);
}


来源:https://stackoverflow.com/questions/18104494/jna-pointer-to-unsigned-char

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!