这是我第一次使用 JNA。我想要做的是调用 DLL 中的函数,该函数需要 (C 代码)->(unsigned long DeviceTypes, NeoDevice *pNeoDevice, int *pNumDevices)...(JNA 形式)-> (int, NeoDevice.getPointer( ), int[] myInt) 作为参数。该函数应该写入结构的字段,我想查看更新的字段。
这是我的 JNA 结构'NeoDevice'
import java.util.Arrays;
import java.util.List;
import com.sun.jna.*;
public class NeoDevice extends Structure {
public volatile int DeviceType;
public volatile int Handle;
public volatile int NumberOfClients;
public volatile int SerialNumber;
public volatile int MaxAllowedClients;
public NeoDevice() {
super();
}
protected List<? > getFieldOrder() {
return Arrays.asList("DeviceType", "Handle", "NumberOfClients", "SerialNumber", "MaxAllowedClients");
}
public NeoDevice(int DeviceType, int Handle, int NumberOfClients, int SerialNumber, int MaxAllowedClients) {
super();
this.DeviceType = DeviceType;
this.Handle = Handle;
this.NumberOfClients = NumberOfClients;
this.SerialNumber = SerialNumber;
this.MaxAllowedClients = MaxAllowedClients;
}
protected ByReference newByReference() { return new ByReference(); }
protected ByValue newByValue() { return new ByValue(); }
protected NeoDevice newInstance() { return new NeoDevice(); }
public static class ByReference extends NeoDevice implements Structure.ByReference {
};
public static class ByValue extends NeoDevice implements Structure.ByValue {
};
}
我正在尝试使用“updateStructureByReference(类类型,对象,指向对象的指针)”来更新字段。我不相信我的“类类型”参数是否正确?我做错了什么吗?任何投入将不胜感激。
当我尝试打印这些字段时,它们似乎仍然为零。
在我的主要课程中,我有
NeoDevice.ByReference myDeviceByRef = new NeoDevice.ByReference();
NeoDevice.ByValue myDeviceByVal = new NeoDevice.ByValue();
NeoDevice myDevice = new NeoDevice();
int [] NumDevices;
NumDevices = new int [1];
NumDevices[0] = 1;
int iResult = n40.icsneoFindNeoDevices(65535, myDeviceByRef.getPointer(), NumDevices);
int icsneoGetDLLVersion = n40.icsneoGetDLLVersion();
Object serialN = myDeviceByRef.readField("SerialNumber");
NeoDevice.ByReference myDeviceBy = Structure.updateStructureByReference(NeoDevice.ByReference, myDeviceByRef, myDeviceByRef.getPointer());