Click to See Complete Forum and Search --> : WideChar / MultiByte
Bengi
December 21st, 2002, 04:52 AM
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
Amn
December 21st, 2002, 12:37 PM
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.
Bengi
December 21st, 2002, 03:58 PM
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
stober
December 22nd, 2002, 08:08 AM
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.
Andreas Masur
December 22nd, 2002, 08:14 AM
You might want to take a look at this FAQ entry (http://www.codeguru.com/FAQS/#212) as well which covers both functions... :cool:
Cheesus
January 2nd, 2003, 10:20 AM
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;
}
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.