我需要使用JNA傳遞一個結構。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
試過,我發現在互聯網上......同樣的結果和錯誤等方式。
結構或接口有問題嗎?
呼籲'rdGetStatusHardware'或試圖訪問結構/內存的內容時,當你得到的錯誤? – technomage