

![]() | 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: |
4 messages in net.java.dev.jna.usersRe: [jna-users] struct containing poi...| From | Sent On | Attachments |
|---|---|---|
| seb bratieres | Jul 17, 2007 7:28 am | |
| Timothy Wall | Jul 17, 2007 9:19 am | |
| j impala | Jul 17, 2007 10:24 am | |
| Timothy Wall | Jul 17, 2007 11:26 am |

![]() | 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] struct containing pointer to struct array | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Jul 17, 2007 9:19:42 am | |
| List: | net.java.dev.jna.users | |
On Jul 17, 2007, at 10:28 AM, seb bratieres wrote:
Hi, I have trouble to correctly construct and pass a struct that contains a pointer to a struct array. Here is the problem case. I have tried two solutions which I could think of, none of which works.
Thank you Sebastien
* C types typedef struct VI_TagEntry_t{ TCHAR* name; VI_Variant value; // another struct } VI_TagEntry;
// tag list storage typedef struct VI_TagList_t{ unsigned long size; VI_TagEntry* list; } VI_TagList;
* JNA types public static class VI_TagEntry extends Structure { public Pointer name;
public VI_Variant value; // another Structure }
public static class VI_TagList extends Structure { public long size;
public Pointer list; // VI_TagEntry* list;
}
* JNA test code private Dll.VI_TagList createSampleVI_TagList() { Dll.VI_TagList tagList = new Dll.VI_TagList();
Structure[] tagEntryArray = (new Dll.VI_TagEntry()).toArray (2); tagEntryArray[0] = createSampleVI_TagEntry();
You're overwriting the first array element, so your array of structures is no longer contiguous in memory. When your C code moves to the second structure, it walks off the end of valid memory.
Change your "createSampleV1..." to "initializeSampleV1..." and pass the existing first array element.
Dll.VI_TagEntry intermediate = createSampleVI_TagEntry(); intermediate.value.data.longVal = 13; tagList.list = tagEntryArray[0].getPointer(); tagEntryArray[1] = intermediate;
tagList.size = 2;
tagList.write(); return tagList; }
public void testVI_TagList() { lib.testVI_TagList(createSampleVI_TagList()); }
* C test code _declspec(dllexport) void __cdecl testVI_TagEntry(VI_TagEntry* tagEntry) { printf("tagEntry.name=%S \n", tagEntry->name); printf("tagEntry.value.d.longVal=%i \n", tagEntry-
value.d.longVal);
}
_declspec(dllexport) void __cdecl testVI_TagList(VI_TagList* tagList) { printf("tagList->size=%i \n", tagList->size); testVI_TagEntry(tagList->list); }
* output tagList->size=2 # # An unexpected error has been detected by HotSpot Virtual Machine: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0af51f43, pid=3500, tid=4004 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_11-b03 mixed mode) etc







