[Win32utils-devel] Fwd: win32-clipboard and Unicode zero bytes

Daniel Berger djberg96 at gmail.com
Fri Feb 3 01:46:59 EST 2006


Park Heesob wrote:

>Hi,
>On Thu, 02 Feb 2006 17:28:59 -0700, Daniel Berger wrote
>  
>
>>Berger, Daniel wrote:
>>
>>    
>>
>>>>-----Original Message-----
>>>>From: win32utils-devel-bounces at rubyforge.org 
>>>>[mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of 
>>>>Park Heesob
>>>>Sent: Thursday, February 02, 2006 5:07 AM
>>>>To: Development and ideas for win32utils projects
>>>>Subject: Re: [Win32utils-devel] Fwd: win32-clipboard and 
>>>>Unicode zero bytes
>>>>   
>>>>
>>>>        
>>>>
>>><snip>
>>>
>>> 
>>>
>>>      
>>>
>>>>Here is some patches of clipboard.c
>>>>
>>>>Line 70:
>>>>  hMem = GlobalAlloc(GHND, strlen(data) + sizeof(TCHAR*));
>>>>to
>>>>  hMem = GlobalAlloc(GHND, RSTRING(rbData)->len + sizeof(TCHAR*));
>>>>
>>>>Line 75:
>>>>  strcpy((TCHAR *)GlobalLock(hMem), data);
>>>>to
>>>>  memcpy((TCHAR *)GlobalLock(hMem), data, RSTRING(rbData)->len);
>>>>
>>>>HTH,
>>>>
>>>>Park Heesob
>>>>   
>>>>
>>>>        
>>>>
>>>Works great, thanks!  Please commit.
>>>
>>>Dan
>>>
>>>      
>>>
>>Nevermind, I'll commit it now and put out a new release shortly.
>>
>>Here's a question for everyone, though - in the age of Unicode, is 
>>strcpy obsolete?  Should we always use memcpy?
>>
>>Dan
>>    
>>
>
>Refer to http://www.tbray.org/ongoing/When/200x/2003/04/26/UTF
>         http://www.i18nguy.com/unicode/c-unicode.html
>         http://www.marin.clara.net/tips/unicode_tips.htm
>
>You can use strcpy and strlen in case of UTF-8, but cannot use in UTF-16, UTF-32 etc.
>In Unicode environment, you should use wcscpy and wcslen instead of strcpy and strlen.
>
>Regards,
>
>Park Heesob
>  
>
But, with UNICODE defined, doesn't _tcscpy and _tcslen use wcscpy and 
wcslen behind the scenes?  Based on a comment from someone else it looks 
like the issue is with multibyte character sets, in which case MBCS 
needs to be defined in order for the tchar functions to handle this 
situation correctly?

Is there any downside to just defining MBCS (instead of UNICODE) in all 
C extensions for Windows?

Thanks for the links, btw.

Regards,

Dan


More information about the win32utils-devel mailing list