我有以下 C 函数:
int read(int dev, void* buffer, unsigned int count)
这通常在 C 中调用,例如:
read(data->dev, data->buffer, 32000);
data 是一个结构,具有以下内容:
typedef struct {
ssize_t dev;
char buffer[32000];
} DATA;
我已经将它转换为java,带有以下内容的jna:
public class Data{//not neccesary to extends of Structure, because is only used to package both variables together
public int dev;
public byte[] buffer;//in the constructor of the class set to 32000 elements
}
int read(int playdev, Buffer buffer, int count);
//clib is the class to connect with de C library
ByteBuffer bf = ByteBuffer.wrap(data.buffer);
clib.read(data.dev, bf , READ_SIZE);
当我执行“clib.read”时,它给了我一个“java.lang.Error: Invalid memory access”
知道如何解决这个错误吗???
我试图做一个: int vox_playstr_read(int playdev, Pointer buffer, int count);
和
ByteBuffer bf = ByteBuffer.wrap(data.buffer);
Pointer pbuf = Native.getDirectBufferPointer(bf);
clib.read(data.dev, pbuf, READ_SIZE);
它给了我同样的结果。
请问,有什么想法让它发挥作用吗?