0
我有下面的C++结构和功能:结构与结构的数组JNA
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);
现在我想用我的C++库在Java中使用JNA ...所以我做了以下内容:
我试着这样调用库:
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网站上没有分配内存有关,但我无法进一步:/
调用toArray()可以解决Java崩溃问题,但在调用函数之前我不知道数组的大小,但我认为这是我们现在必须讨论的。谢谢! :) – seveves