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 14, 2008 6:10:22 am
List:net.java.dev.jna.users

On May 14, 2008, at 8:02 AM, Dale@coats.com wrote:

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.

Does Structure.size() return the same thing as sizeof(NOTIFYICONDATA) in native code? If not, you may be missing some field definitions.

You should null-terminate any of the szXXX fields, unless you know the array is already zeroed.

Also remember that Java objects will be GC'd if you don't keep a reference to them; structures will be freed, and callbacks will become no-ops.