Java JNA DLL函数调用实现

Java JNA DLL函数调用实现,java,c++,pointers,dll,jna,Java,C++,Pointers,Dll,Jna,我试过了,但失败了!首先,我会向你展示我试图模仿的C++代码,然后我提出了JNA java代码(其中有一半是工作的)。 C++代码 typedef struct { int DeviceType; int Handle; int NumberOfClients; int SerialNumber; int MaxAllowedClients; } NeoDevice; typedef int (__stdcall *FINDNEODEVICES)(u

我试过了,但失败了!首先,我会向你展示我试图模仿的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代码

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");
}
结构实现

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 {

};
}

不带params的函数工作正常,并返回它应该返回的整数。另一个返回“1”,它应该返回,但问题是它也应该写入结构的字段,我传递它,但当我查看它的字段时,所有字段仍然为零

可能重复的问题应编辑原始问题,以澄清或更新新信息。在多个地方问同一个问题是没有帮助的。