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:Timothy Wall (twal@dev.java.net)
Date:May 13, 2008 6:05:59 am
List:net.java.dev.jna.users

On May 13, 2008, at 8:18 AM, Dale@coats.com wrote:

I worked through many theories (ByteBuffer, WString, Structure.ByValue, Pointer, etc) but nothing I've tried got me very far with being able to supply a wchar_t into a Structure. I figure that one of the things I've been trying will work if I just get some more implementation details right.

'x' shows as the "tool tip" if I do this:

public static class NOTIFYICONDATA extends Structure { public int cbSize; public HANDLE hWnd; // HWND.setPointer(aJWindow) keeps XP happy, btw! public int uID; public int uFlags; public int uCallbackMessage; public HANDLE hIcon; public char szTip = 'x'; }

Since the native definition indicates:

TCHAR szTip[64]; // or 128, depending on some preprocessor constants

you need to use (assuming windows unicode flavor):

public char[] szTip = new char[SZ_TIP_SIZE]; // field initialization is important to sizing the struct

Then use Native.toString(s.szTip) to convert back to Java String. Don't assign szTip to a new array unless it's the same size as the original; it's better to copy values in.