Unicode Encoding Conversions Between ATL and STL Strings

At the Windows platform-specific level, when using C++ frameworks like ATL (or MFC), it makes sense to represent strings using CString (CStringW in Unicode builds, which should be the default in modern Windows C++ code).

On the other hand, in cross-platform C++ code, using std::string makes sense as well.

The same Unicode text can be encoded in UTF-16 when stored in CString(W), and in UTF-8 for std::string.

So, there’s a need to convert between those two Unicode representations. I discussed the details of such conversions in my MSDN Magazine article: “Unicode Encoding Conversions with STL Strings and Win32 APIs”However, the C++ code associated to that article used std::wstring for UTF-16 strings.

I’ve created a new repository on GitHub, where I uploaded reusable code (in the form of a convenient header-only module) for converting between UTF-16 and UTF-8, using CStringW for UTF-16, and std::string for UTF-8. Please feel free to check it out!


Open-Sourcing MFC: What Do You Think?

There is an idea on Visual Studio User Voice about open-sourcing MFC.

What do you think about it? Would it be good or bad for the development of MFC and for the MFC community?

For new C++ projects there are several options available. For example: using Qt to develop cross-platform C++ applications, or WTL for something more Windows-specific, just to name a few.

But MFC is still used in several C++ legacy projects (including very large enterprise applications) still active in maintenance mode. With MFC open source, the community and Microsoft could submit new code and patches while Microsoft could monitor the quality of the submitted code and support an official branch.

My original Visual C++ 6 box.
My original Visual C++ 6 box (…memories from the MFC’s “Golden Days” 🙂 )

Please feel free to share your opinions on Visual Studio User Voice, or leave comments here.

Please try to develop a civilized discussion, and be courteous and kind even when you disagree.