JNA 相关问题
结构体对齐问题
要注意调用的c库字段对齐方式的相关设置。
#pragma pack (push,1)
#pragma pack(pop)
jna中提供了4种对齐方式:
/** Use the platform default alignment. */
public static final int ALIGN_DEFAULT = 0;
/** No alignment, place all fields on nearest 1-byte boundary */
public static final int ALIGN_NONE = 1;
/** validated for 32-bit x86 linux/gcc; align field size, max 4 bytes */
public static final int ALIGN_GNUC = 2;
/** validated for w32/msvc; align on field size */
public static final int ALIGN_MSVC = 3;
需要在相应的结构体构造函数中加入super(ALIGN_NONE);设置对应的对齐方式。
unsigned类型处理
java中没有对应的无符号类型,需要进行相应的转换,以byte类型为例(c中的 unsigned char)
public class Util {
public static byte sendUnsignedByte(int input){
return (byte) (input & 0xFF);
}
public static int receiveUnsignedByte(b