Unicode Programming in MFC


Unicode characters are invented to accommodate additional international characters  part from English. Earlier characters were represented in ASCII formats with each character occupying 1 byte of memory. But with Unicode, each character is represented with 2 bytes.

There is one more type of character set using 2 bytes i.e.MBCS (Multi Byte Character Set) or DBCS (Double Byte Character Set). In fact any article about MFC Unicode programming,
will have a reference to the MBCS and DBCS. This character set is used for single locale specific programming i.e., it can support only one locale set in an application. But using Unicode will enable the programs to use multiple locale character sets simultaneously.

As the benefits of Unicode programming looks immense as described above, it is imperative for any application to give support to Unicode. MFC supports Unicode in a very flexible way by providing a single line macro to convert between a Unicode and non-Unicode application.

MFC Unicode Macro:

The macro,

 #define _UNICODE   


will make the application Unicode enabled. But a mere use of the macro will not be  enough to make an application Unicode enabled. Some of the important things the application should take care of are listed below.

  • The entry point of the application should be set as wWinMainCRTStartup
  • Strings should be declared and used as TCHAR type.
  • The Length of the string should be passed as Length * sizeof(TCHAR)
  • Use string functions declared in TCHAR.H viz., _tcscat, __tcscpy, _tcscmp etc.,


Using the TCHAR programming set will enable the compiler to choose between Unicode C Runtime library and non-Unicode library. If the program is defined to be a UNICODE program, it will expand the TCHAR routines to ASCII functions. If the program does not have any UNICODE macro defined, it will be built as an ASCII application.

MFC Unicode – Points to be Noted:  

  1. Using Unicode makes Windows NT/2000 efficient as Unicode is the
    standard character set used in processing characters. Any non-Unicode literals will be converted back and forth for manipulations.
  2. Win 98 platforms do not support Unicode.