I have the following C function:
int read(int dev, void* buffer, unsigned int count)
This is usually call in C like:
read(data->dev, data->buffer, 32000);
data is a struct, with the following:
typedef struct {
ssize_t dev;
char buffer[32000];
} DATA;
And I have convert this to java, with jna with the following:
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);
And it gives me a "java.lang.Error: Invalid memory access" when I do the "clib.read"
Any idea how to go through this error???
I have tried to make a: int vox_playstr_read(int playdev, Pointer buffer, int count);
with
ByteBuffer bf = ByteBuffer.wrap(data.buffer);
Pointer pbuf = Native.getDirectBufferPointer(bf);
clib.read(data.dev, pbuf, READ_SIZE);
and it gives me the same result.
Please, any ideas to make it work?