7 messages in net.java.dev.jna.users[jna-users] [HELP] How to pass struct...
FromSent OnAttachments
schinApr 28, 2009 1:03 am 
schinApr 30, 2009 1:00 am 
Timothy WallApr 30, 2009 4:20 am 
schinApr 30, 2009 5:42 pm 
Timothy WallMay 1, 2009 4:07 am 
schinOct 8, 2009 9:47 pm 
schinOct 8, 2009 9:49 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[jna-users] [HELP] How to pass structure arrays in structure from java to c++Actions...
From:schin (sch@sdg.mdd.ricoh.co.jp)
Date:Apr 30, 2009 1:00:28 am
List:net.java.dev.jna.users

Hi all:

I had sent email for help in Apr. 27, I has not got the answer. Please help me.

I want to pass a structure arrays in structure from java to c. The code is like as: C++ code: typedef struct { int searchType; char* name; DETAIL* details; int detailSize; } SEARCHCONDITION;

typedef struct { char* name; int value; } DETAIL;

int search(SEARCHCONDITION* condition);

Java code: public interface JnaServerLibrary extends Library {

public static class _Detail extends Structure { public String name; public int value; } public static class _SearchCondition extends Structure { public int searchType; public String name; public Pointer details; // DETAIL arrays public int detailSize; }

int search(_SearchCondition condition); }

And I use DetailArray class to make Pointer to pass to C++. public class DetailArray extends Memory {

private static final Integer DETAILSTRUCTURESIZE = 8;

public DetailArray (JnaServerLibrary._Detail[] datas) { super((datas.length + 1) * DETAILSTRUCTURESIZE);

for (int i=0;i < datas.length;i++) { Pointer p = null; if (datas[i] != null) { p = datas[i].getPointer(); setPointer(DETAILSTRUCTURESIZE * i, p); } else { setPointer(DETAILSTRUCTURESIZE * i, null); }

} setPointer(DETAILSTRUCTURESIZE * datas.length, null); } }

Pass to c++:

_SearchCondition searchCondition = new SearchCondition(); searchCondition.searchType = 0; searchCondition.name = "name"; searchCondition.detailSize = n;

_Detail[] details = new _Detail[n]; details[0] = new _Detail(); details[0].name = "entryDate"; details[0].value = "2009/04/30"; ......

DetailArray detailArray = new DetailArray(details); searchCondition.details = detailArray.getPointer(0); jna.search (searchCondition);

I can run it, and no error, but can't pass details value to C++. The pointer value is as same as c++.