I have to pipe in and say that in my work with UNICODE enabling the
controls the two functions proposed here would be very useful. 

If somemone wrote them up as a patch would they go in?

-aric

TAKESHIMA Hidenori wrote:
> 
> > First, I should say that it is a wrong way to fix DBCS. You could note,
> > that work in progress on converting the standard USER controls to unicode.
> > The same should be done for a common controls dll.
> I know using UNICODE is better.
> 
> > Second, you are somewhat strange mixing WtoA/AtoW functions (that should not
> > be used at all IMHO) with WideCharToMultiByte/MultiByteToWideChar.
> In DBCS, strlen(astr) may not be equal to strlenW(wstr).
> to call lstrcpy[n]WtoA(abuf,wstr[,buflen]),
> the buffer size of abuf(buflen) is not equal to lstrlenW(wstr).
> 
> for example: in CP_ACP = codepage 932 (DBCS codepage)
> astr = {0x61,0x81,0x40,0}.
> translated wstr is {0x61,0x3000}.
> lstrlenA(astr) is 3.
> lstrlenW(wstr) is 2.
> WideCharToMultiByte(CP_ACP,0,wstr,-1,NULL,0,NULL,NULL) is 4.
> 
> And, the length of ASCII string buffer for lstrcpyWtoA() is at least 4.
> (not lstrlenW(wstr)+1 but WideCharToMultiByte(CP_ACP,0,wstr,-1,NULL,0,NULL,NULL).)
> 
> If adding two global functions is permitted, adding and using
> follow functions for calculating length of buffers is a solution.
> 
> /* to get buffer size for lstrcpynAtoW and lstrcpynWtoA */
> INT lstrlenAtoW( LPCSTR astr )
> {
>   INT len;
> 
>   len = MultiByteToWideChar(CP_ACP,0,astr,-1,NULL,0);
>   if ( len > 0 )
>     len--; /* '\0' */
>   return len;
> }
> 
> INT lstrlenWtoA( LPCWSTR wstr )
> {
>   INT len;
> 
>   len = WideCharToMultiByte(CP_ACP,0,wstr,-1,NULL,0,NULL,NULL);
>   if ( len > 0 )
>     len--; /* '\0' */
>   return len;
> }


Reply via email to