

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
7 messages in net.java.dev.jna.usersRe: [jna-users] [HELP] How to pass st...| From | Sent On | Attachments |
|---|---|---|
| schin | Apr 28, 2009 1:03 am | |
| schin | Apr 30, 2009 1:00 am | |
| Timothy Wall | Apr 30, 2009 4:20 am | |
| schin | Apr 30, 2009 5:42 pm | |
| Timothy Wall | May 1, 2009 4:07 am | |
| schin | Oct 8, 2009 9:47 pm | |
| schin | Oct 8, 2009 9:49 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] [HELP] How to pass structure arrays in structure from java to c++ | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Apr 30, 2009 4:20:46 am | |
| List: | net.java.dev.jna.users | |
To obtain a block of structures contiguously allocated in memory, use Structure.toArray(). You can then use Structure.getPointer() on the first element to obtain the starting address of the block.
On Apr 30, 2009, at 4:00 AM, schin wrote:
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++.
Best regards, Schin.







