次の C++ 構造体と関数があります。
typedef struct _Phase_Information
{
char infoMessage[MAX];
} INFORMATION;
typedef struct _Informations
{
int infoCount;
INFORMATION *infoArray;
} INFORMATIONS ;
int GetInformations(INFORMATIONS *pInfos);
私はそれらを次のように使用します:
INFORMATIONS informations;
INFORMATION * informationArray = new INFORMATION[MAX_INFOS];
informations.info = informationArray;
int error = GetInformations(&informations);
JNAを使用してJavaでC++ライブラリを使用したいので、次のことを行いました。
public class Information extends Structure {
public char[] infoMessage = new char[MAX];
public Information () { super(); }
protected List<? > getFieldOrder() {
return Arrays.asList("infoMessage ");
}
public Information (char infoMessage []) {
super();
if ((infoMessage .length != this.infoMessage .length))
throw new IllegalArgumentException("Wrong array size !");
this.infoMessage = infoMessage ;
}
public static class ByReference extends Information implements Structure.ByReference {};
public static class ByValue extends Information implements Structure.ByValue {};
}
public class Informations extends Structure {
public int infoCount;
public Information.ByReference infoArray;
public Informations () { super(); }
protected List<? > getFieldOrder() {
return Arrays.asList("infoCount", "infoArray");
}
public Informations(int infoCount, Information.ByReference infoArray) {
super();
this.infoCount= infoCount;
this.infoArray= infoArray;
}
public static class ByReference extends Informations implements Structure.ByReference {};
public static class ByValue extends Informations implements Structure.ByValue {};
}
私はこのようにライブラリを呼び出そうとしました:
Informations.ByReference informations = new Informations.ByReference();
informations.infoArray= new Information.ByReference();
int error = CLib.GetInformations(Informations);
Information[] test =(Information[])informations.infoArray.toArray(Informations.infoCount);
配列の最初の要素のみを取得することもありますが、残りの時間は Java がクラッシュします...したがって、Java サイトにメモリを割り当てていないことに関連していると思いますが、それ以上取得できません:/