WideChar / MultiByte

heya,
someone have examples of using these APIs: ?
WideCharToMultiByte()
MultiByteToWideChar ()
since its an WinAPI section, i am not expecting C++ stuff :)
thn x in advance.
Ben
[212 byte] By [Bengi] at [2007-11-18 0:20:38]
# 1 Re: WideChar / MultiByte
They are almost identical to the wcstombs and mbstowcs from CRT libraries. In other words:

WideCharToMultiByte converts a sequence of wide-char characters (UNICODE) to a sequence of multibyte characters (ASCII in this case). So if you have WideCharToMultiByte(..., L"Helo") you will have "Helo" as result.

MultiByteToWideChar is the opposite ;) I used it many times when dealing with GDI+, since it only accepts UNICODE strings, even if my project uses ANSI strings. Very useful ;)

Hope this helped.
Amn at 2007-11-9 13:02:18 >
# 2 Re: WideChar / MultiByte
yeah also VB uses unicode for its text format.
i'll try work on it when i got some spare time,
but if u got a code snippet, it would be better than just error & trial
Bengi at 2007-11-9 13:03:28 >
# 3 Re: WideChar / MultiByte
look the functions up in MSDN and you will find several examples. wcstombs and mbstowcs are the easiest to use, but I don't think they work with languages such as Chinese where characters are represented by two bytes instead of one.
stober at 2007-11-9 13:04:27 >
# 4 Re: WideChar / MultiByte
You might want to take a look at this FAQ entry ( http://www.dev-archive.com/FAQS/#212) as well which covers both functions... :cool:
Andreas Masur at 2007-11-9 13:05:23 >
# 5 Re: WideChar / MultiByte
int Wc2Str( WCHAR* pwcBuf, char* pBuf, int BufLen )
{
if( pwcBuf == NULL || pBuf == NULL )
return -1;

// If zero then assume the user has allocated enough
if( BufLen == 0 )
BufLen = wcslen(pwcBuf)+1;

if( WideCharToMultiByte(CP_ACP, 0, pwcBuf, -1, pBuf, BufLen, NULL, NULL) == 0 )
return -1;

pBuf[wcslen(pwcBuf)] = 0;

return 0;
}
Cheesus at 2007-11-9 13:06:22 >