11 messages in net.java.dev.jna.usersRe: [jna-users] char* versus wchar_t ...
FromSent OnAttachments
Dale...@coats.comMay 13, 2008 5:17 am 
Timothy WallMay 13, 2008 6:00 am 
Timothy WallMay 13, 2008 6:05 am 
Dale...@coats.comMay 13, 2008 8:55 am 
Timothy WallMay 13, 2008 9:06 am 
Dale...@coats.comMay 13, 2008 11:46 am.zip
Daniel KaufmannMay 13, 2008 5:16 pm 
Dale...@coats.comMay 14, 2008 5:02 am 
Timothy WallMay 14, 2008 6:10 am 
Dale...@coats.comMay 15, 2008 6:33 am 
Timothy WallMay 15, 2008 12:38 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:Re: [jna-users] char* versus wchar_t * in a StructureActions...
From:Daniel Kaufmann (dani@gmail.com)
Date:May 13, 2008 5:16:10 pm
List:net.java.dev.jna.users

Hi Daniel,

I believe this is not what Timothy was saying. I think he was saying something like this:

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 = new char[64]; }

NOTIFYICONDATA n = NOTIFYICONDATA(); n.szTip[0] = 'T'; n.szTip[1] = 'i'; n.szTip[2] = 'm';

Of course you can use System.arraycopy to copy from a different array. The important thing is that the array size is 64. Window will know the actual length of the string by looking for a NUL char (In java '\0' or just number 0) In your code you was provided a smaller array so the structure will be smaller than what it should, so if the Windows funtion tries to access there it will get garbage and might even get a segmentation fault.

Thanks, Daniel

----- Original Message ----- From: <Dale@coats.com> To: <use@jna.dev.java.net> Sent: Tuesday, May 13, 2008 3:46 PM Subject: [jna-users] char* versus wchar_t * in a Structure

On Tue, 13 May 2008 12:07:17 -0400 Timothy Wall wrote:

On May 13, 2008, at 11:56 AM, Dale@coats.com wrote:

When I use a single primitive 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.

Primitive arrays are inlined. WStrings are converted to a pointer value.

It sounds like you're saying the following should be the same as what's shown above: 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','i','m'}; // <<Diff }

But that produces different results. Specifically, the OS makes a spot for the icon, but no icon shows-up.

--Dale--

(See attached file: TrayIcon.zip) *************************************************** This communication may be confidential and privileged and the views expressed herein may be personal and are not necessarily the views of Coats plc. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s), please note that any distribution, copying or use of this communication or the information in it is strictly prohibited. If you have received this communication in error, please notify us by email (Apps@coats.com) or telephone our technical support helpdesk at Coats plc. +44 (0)20 8210 5100 (UK 0830H - 1800H, Mon-Fri, GMT) and then delete the email and any copies of it. ***************************************************

--------------------------------------------------------------------------------