我尝试过但都失败了!首先生病了你的c ++代码我试图模仿然后我想出的JNA java代码(其中一半有效)。
C ++代码
typedef struct
{
int DeviceType;
int Handle;
int NumberOfClients;
int SerialNumber;
int MaxAllowedClients;
} NeoDevice;
typedef int (__stdcall *FINDNEODEVICES)(unsigned long DeviceTypes, NeoDevice *pNeoDevice, int *pNumDevices);
extern FINDNEODEVICES icsneoFindNeoDevices;
bool LoadDLLAPI(HINSTANCE &hAPIDLL){
icsneoFindNeoDevices = (FINDNEODEVICES) GetProcAddress(hAPIDLL, "icsneoFindNeoDevices");
}
Java代码
struct implementation ...
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 {
};
}
主类代码......
System.setProperty("jna.library.path", "C:\\WINDOWS\\system32");
icsneo40 n40 = icsneo40.INSTANCE;
NeoDevice.ByReference myDeviceByRef = new NeoDevice.ByReference();
int icsneoGetDLLVersion = n40.icsneoGetDLLVersion();
int iResult = n40.icsneoFindNeoDevices(65535, myDeviceByRef.getPointer(), NumDevices);
myDeviceByRef.read();
没有params的函数工作正常并返回它应该的整数。另一个返回&#39; 1&#39;它本应该但问题是它也应该写入结构的字段我传递它但是当我看它的字段时,所有仍然是零。