I'm trying to use a function in C using JNA:
C:
int addHoliday(unsigned char* data);
JAVA:
int addHoliday(byte[] data);
I'm passing my byte[] with information, but in C I'm using the same pointer to write a response. Can I catch the same byte[] with the new information?
Yes, primitive arrays work just like memory buffers when used in a direct function call. The native code will see a consistent buffer for the duration of the native call, and your Java code will see in the byte[]
whatever data was written by the native code.
As for the signedness of the data, any unsigned char
elements with the high bit set will appear as negative values in the byte[]
in Java. To properly extract the data, you'll need to mask out the higher bits, e.g.
int unsigned_value = (int)byte_value & 0xFF;