11 messages in net.java.dev.jna.users[jna-users] char* versus wchar_t * in...
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:[jna-users] char* versus wchar_t * in a StructureActions...
From:Dale...@coats.com (Dale@coats.com)
Date:May 14, 2008 5:02:01 am
List:net.java.dev.jna.users

On Tue, 13 May 2008 21:16:33 -0300, Daniel Kaufmann wrote:

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';

Thanks for the reply. That's "the idea" I was trying to capture in my example. And you're right, it's different than what I had (the ending null and length).

I tried your example, but it continues to exhibit the same issue as my example: the icon does not show.

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.

Good point. I noticed that too, but the way I pasted it here is not really the way I coded it the first time through.

Here's what I originally had in my code, but simplified for "forum consumption":

int SZ_TIP_SIZE = 64; public byte[] szTip = new byte[SZ_TIP_SIZE];

public void setSzTip(String str) { int len = (str.length() <= SZ_TIP_SIZE ? str.length() : SZ_TIP_SIZE); byte[] temp = str.getBytes(); System.arraycopy(temp, 0, szTip, 0, len); }

Actually, I had a "char" version of the above, that I must have trashed.

But the above doesn't work, whereas individual char or byte primitives do work (with or without a null termination character).

I thought maybe the problem was the size() method was returning the wrong number, but I set that manually and it didn't improve things.

--Dale--