

![]() | 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: |
11 messages in net.java.dev.jna.usersRe: [jna-users] char* versus wchar_t ...| From | Sent On | Attachments |
|---|---|---|
| Dale...@coats.com | May 13, 2008 5:17 am | |
| Timothy Wall | May 13, 2008 6:00 am | |
| Timothy Wall | May 13, 2008 6:05 am | |
| Dale...@coats.com | May 13, 2008 8:55 am | |
| Timothy Wall | May 13, 2008 9:06 am | |
| Dale...@coats.com | May 13, 2008 11:46 am | .zip |
| Daniel Kaufmann | May 13, 2008 5:16 pm | |
| Dale...@coats.com | May 14, 2008 5:02 am | |
| Timothy Wall | May 14, 2008 6:10 am | |
| Dale...@coats.com | May 15, 2008 6:33 am | |
| Timothy Wall | May 15, 2008 12:38 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] char* versus wchar_t * in a Structure | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | May 13, 2008 9:06:54 am | |
| List: | net.java.dev.jna.users | |
On May 13, 2008, at 11:56 AM, Dale...@coats.com wrote:
When I use a single primative char, it works. In fact, I can define structure like this, and get the tool tip to say 'Tim'.
public static class NOTIFYICONDATA extends Structure { public int cbSize; public HANDLE hWnd; public int uID; public int uFlags; public int uCallbackMessage; public HANDLE hIcon; public char szTip = 'T'; public char szTip2 = 'i'; public char szTip3 = 'm'; }
If I didn't care how it looked, I could define 64 char primitives and a goofy setter and be done with it. But I couldn't live with myself if I did that.
If you just want the Structure to "print" pretty, redefine its toString(). Otherwise, char[64] will occupy the same memory natively as would 64 consecutive "char" fields.
No problem sizing the array beforehand and treading lightly when working with that array.
The problem seems to revolve around some items in the structure need to be by-value and others not. The handles work fine the way it is, but under that scenario, unless I use a primitive char, it's getting the pointer to the char[] or to the WString instead the sequence of chars they contain.
Primitive arrays are inlined. WStrings are converted to a pointer value.
Here's a "by value" example that I got WORKING, but it's only got one field in the structure:
public static class TestStruct extends Structure {}
public static class ByValTestStruct extends TestStruct implements Structure.ByValue{
Bzzzt. Structure.ByValue (cf Structure.ByReference) is a tagging interface used to indicate that when used as an argument or return value, the structure should be passed by value instead of by reference. The default behavior is to pass or return by reference (struct *), since passing structures or returning them by value is less common usage in C.
But if I try that same technique with the rest of the items from the real structure, it gives:
Unsupported structure field type class com.test.ti.W32API$HANDLE
That's a recently fixed bug (unable to use NativeMapped types in a ByValue structure). However, I don't think you need a ByValue structure in the first place.








.zip