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

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
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

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
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

Further readings

Where is WinMain() function in MFC application ?

MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.

What is the utility of CWinApp class?

This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...

Basic steps in Win32 GUI Application with source code.

Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.

What is a Window CallBack procedure and what is its utility?

DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.

What are LPARAM and WPARAM in window proc function?

LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.

What are the basic steps of a typical MFC based application?

We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...