Skip to content
Search

WindowsApi:MultiByteToWideChar

lastmod 2025-05-23created 2016-04-093 edits

Converts a Multi Byte string to a Wide Char string. (char -> wchar_t) The function that converts in the opposite direction is WideCharToMultiByte().

A more precise description is as follows.

Maps a character string to a UTF-16 (wide character) string. The character string is not necessarily from a multibyte character set.

Maps a string to a UTF-16 (wide character) string. The string does not need to consist of characters from a multibyte character set.

Syntax

int MultiByteToWideChar(
  __in       UINT CodePage,
  __in       DWORD dwFlags,
  __in       LPCSTR lpMultiByteStr,
  __in       int cbMultiByte,
  __out_opt  LPWSTR lpWideCharStr,
  __in       int cchWideChar
);
  • CodePage: If CP_ACP is used as the first argument, the ANSI code page is used.

Example

Code that converts a commonly used char (ANSI) to wchar_t (Unicode) is as follows.

int wcs_length = strlen(mbs_string) + 1;
wchar_t * convert_wcs = new wchar_t [wcs_length];
::MultiByteToWideChar(CP_ACP, 0, mbs_string, -1, convert_wcs, wcs_length);
// use convert_wcs varable.
delete [] convert_wcs;

See also

Favorite site