에 참고로 구조를 통과 : 자바방법 I이 함수를 호출 할 JNA
typedef struct
{
int a;
int b;
} mystruct;
등가 코드는 다음과 C에서 정의
extern "C" xxx_SERVICE_API int initSocket(socketStruct* skStruct);
++ dll.socketStruct 아래 정의 구조는 :
public interface MyDllClass extends Library {
public static class MyStructure extends Structure {
public static class ByReference extends MyStructureRef
implements Structure.ByReference{
}
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[]{"a","b"});
}
public int a;
public int b;
}
//Native function
int initSocket (MyStructure.ByReference sks);
MyDllClass INSTANCE = (MyDllClass)Native.loadLibrary("Mydll",
MyDllClass.class);
}
이 기본 함수를 매개 변수로 참조하여 구조체를 호출 할 수 있습니까? 감사합니다.
답장을 보내 주셔서 감사합니다. 당신과 함께 따르면 난 내 구조에 생성자를 추가 네이티브 함수를 호출 할 때
MyStructure mySocket = new MyStructure();
MyDllClass.INSTANCE.initSocket(mySocket);
이 코드 때문에 널 포인터 예외의 실패 :
public interface MyDllClass extends Library {
public static class MyStructure extends Structure {
public MyStructure() {
idModule = 0;
nbModules = 0;
nbQueueInModule = 3;
portList = new int[128];
serverList = new char[128][20];
}
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[]{"a","b","portList","serverList"});
}
public int a;
public int b;
public int[] portList;
public char[][] serverList;
}
//Native function
int initSocket (MyStructure.ByReference sks);
MyDllClass INSTANCE = (MyDllClass)Native.loadLibrary("Mydll",
MyDllClass.class);
}
주에서 나는이 코드를 썼다. 아이디어가 있으십니까?