我需要使用 JNA 传递一个结构。
我拥有的文档包含以下信息:
int rdGetStatusHardware (struct StatusHardware *stat)
struct StatusHardware{
unsigned char SerialNumber[12];
unsigned long HWVersion;
unsigned long FWVersion;
unsigned long MemorySize;
unsigned short BootVersion;
unsigned short FPGAVersion;
unsigned long Devices;
unsigned char Reserved[8];
};
我将结构映射为:
public class StatusHardware extends Structure {
public byte SerialNumber[] = new byte[12];
public byte HWVersion[] = new byte[4];
public byte FWVersion[] = new byte[4];
public byte MemorySize[] = new byte[4];
public byte BootVersion[] = new byte[2];
public byte FPGAVersion[] = new byte[2];
public byte Devices[] = new byte[4];
public byte Reserved[] = new byte[8];
public StatusHardware(Pointer p){
super(p);
}
}
这是我界面中的方法:
int rdGetStatusHardware(Pointer p);
调用库:
Pointer ptr = new Memory(40);
int result = CLibrary.INSTANCE.rdGetStatusHardware(ptr);
使用这种方法,我收到以下错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000, pid=3108, tid=5492
#
# JRE version: 6.0_24-b50
# Java VM: Java HotSpot(TM) Client VM (19.1-b02 mixed mode windows-x86 )
# Problematic frame:
# C 0x00000000
尝试了我在互联网上找到的其他方法......结果和错误相同。
是结构问题还是接口问题?