

![]() | 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: |
9 messages in net.java.dev.jna.usersRE: [jna-users] Need help for beginner| From | Sent On | Attachments |
|---|---|---|
| Hao Jiang | Feb 10, 2009 3:16 pm | |
| Daniel Kaufmann | Feb 10, 2009 4:58 pm | |
| Timothy Wall | Feb 10, 2009 5:00 pm | |
| Hao Jiang | Feb 11, 2009 9:08 am | |
| Hao Jiang | Feb 11, 2009 12:53 pm | |
| Timothy Wall | Feb 11, 2009 2:09 pm | |
| Timothy Wall | Feb 11, 2009 2:11 pm | |
| Hao Jiang | Feb 11, 2009 2:35 pm | |
| Hao Jiang | Feb 12, 2009 9:41 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] Need help for beginner | Actions... |
|---|---|---|
| From: | Hao Jiang (hji...@intermap.com) | |
| Date: | Feb 12, 2009 9:41:39 am | |
| List: | net.java.dev.jna.users | |
Now I figured out this it's not data type (unsigned short) issue I thought, it's actually a nested ally of structure trouble
Before I simplified my data structure, really it is
typedef struct { char* a; StructA sa; StructB* sb; double c; double d; } Info;
typedef struct { short x; short y; short z; StructC w[16] } StructA;
typedef struct { short sh; double do } StructC;
I searched mail list archive found many talks about such issue, but couldn't find a clear solution, my java code as below
public static class Info extends Structure{ public String a; public StructA sa; public Pointer sb; public double c; public double d; }
public static class StructA extends Structure{ public short x; public short y; public short w; public StructC sc = new StructC[16];
public StructA(){ allocateMemory(); } }
public static class StructC extends Structure{ public short sh; public double do; }
I always got "invalid memory access" error, however, if I 1. comment out one of element from StructC ( short sh OR double do), it runs fine. 2. if I don't have array, just one of StructC in StructA, it's OK.
So seems it can't allocate enough memory for an array of StructC.
Moreover, I tried to change the "double" in StructC to "int", it runs OK, just I can't get the result I want.
I'm sure must be someone had this issue before, and helps please
Hao
Hao
-----Original Message----- From: Timothy Wall [mailto:twal...@dev.java.net] Sent: Wednesday, February 11, 2009 3:12 PM To: use...@jna.dev.java.net Subject: Re: [jna-users] Need help for beginner
Use Structure.toString and set -Djna.dump_memory=true to see the raw contents of the structure memory. This can help you figure out where the structure alignment is going awry.
On Feb 11, 2009, at 3:53 PM, Hao Jiang wrote:
Hi All
I made some progress, I think it's a data type issue (unsigned short in C), my code
typedef struct { char* a; StructA sa; StructB* sb; double c; double d; } Info;
One data type in StructA is unsigned short, I use short in java code
public static class StructA extends Structure{ public int x; public short y}
public static class Info extends Structure{ public String a; public StructA sa; public Pointer sb; public double c; public double d; }
I got error message when run the above code: Invalid memory access
But after comment out y, like this public static class StructA extends
Structure{ public int x; // public short y}
I can run the code, and be able to read String a in Info and X in StructA, but I got 0.0 for both c and d which shouldn't be.
How can I mapping unsigned short in java?
Thanks
Hao
********************************************************************** ***
PRIVILEGE AND CONFIDENTIALITY NOTICE:
The information in this email is intended for the named recipients only.
It may contain privileged and confidential information. If you have
received this communication in error, any use, copying or dissemination
of its contents is strictly prohibited. Please erase all copies of the
message along with any included attachments and notify Intermap
Technologies or the sender immediately by telephone at the number
indicated on this page.
********************************************************************** ***







