Multibyte string is the name for ASCII strings and wide character is the name for unicode. We can convert these wide character to multibyte or vice versa. We can do it with Win32 API or C standard library or by ATL/MFC macros. We can choose any of the mechanism depending on our application or component framework.
Win32 API
UNICODE String => [WideCharToMultiByte] => ASCII string
ASCII string => [MultiByteToWideChar] => UNICODE String
MultiByteToWideChar
The MultiByteToWideChar function maps a character string to a wide-character (Unicode) string. The character string mapped by this function is not necessarily from a multibyte character set.
int MultiByteToWideChar( UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar );Parameters:
CodePage - code page
dwFlags - character-type options
lpMultiByteStr - address of string to map
cchMultiByte - number of bytes in string
lpWideCharStr - address of wide-character buffer
cchWideChar - size of buffer
WideCharToMultiByte
The WideCharToMultiByte function maps a wide-character string to a new character string. The new character string is not necessarily from a multibyte character set.
int WideCharToMultiByte( UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cchMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar );Parameters:
CodePage - code page
dwFlags - performance and mapping flags
lpWideCharStr - address of wide-character string
cchWideChar - number of characters in string
lpMultiByteStr - address of buffer for new string
cchMultiByte - size of buffer
lpDefaultChar - address of default for unmappable characters
lpUsedDefaultChar - address of flag set when default char. used
C STDIO library
UNICODE String => [wcstombs] => ASCII string
ASCII string => [mbstowcs] => UNICODE String
ATL/MFC macros
UNICODE String => [W2A/W2CA] => ASCII string
ASCII string => [A2W/A2CW] => UNICODE String
About our authors: Team EQA
You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.
Most popular topics (must visit)
Useful links for students
Discussion forum |
#1 webmaster Sat 26 Apr/2014 23:38:24(GMT) | 0 | 0 |
Dear Users,
We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.
Regards,
Webmaster
Your message goes here: