boostunicodeutf-8mfccboost-locale

Can MFC application with Multibyte character-set enable supports UTF-8 encoding strings?


I have a legacy MFC application which is on Multibyte character set enabled. Now requirement is to support UTF-8 character-set too. Changing the whole application in Unicode environment is too big and risky task.

I found Boost.Locale lib which does support UTF-8 conversion. So my question is that, can it work with my existing setting of Multibyte. Or any other way to do it without converting whole application into Unicode. Because it uses lot of legacy Windows API which I don't want to touch. My simple requirement is few of the Functions / Methods can generate and parse UTF-8 characters.


Solution

  • Project parameter "Multibyte character set" defines, how generic text mappings are expanded. For example, SetWindowText is defined as SetWindowTextA in multibyte project, and SetWindowTextW in Unicode project. This doesn't prevent you to use Unicode function in Multibyte project, by specifying its full name, like SetWindowTextW.

    Example. MFC project, Multibyte.

    SetWindowText(_T("abc"));
    

    This line uses generic mapping, which is expanded as:

    SetWindowTextA("abc");
    

    If you change the project settings to Unicode, the same line is expanded as:

    SetWindowTextW(L"abc");
    

    In the same multibyte project you can call Unicode function explicitly:

    SetWindowTextW(L"abc");
    

    So, the answer is "Yes", you can add Unicode functions to Multibyte project, without converting the whole project to Unicode. Use appropriate types like wchar_t, wstring etc. and call string API explicitly.