1

I would like to transfer an old C++ MFC project from Visual Studio 2005 to a newer version. The project uses a multibyte character set that I know is no longer supported in the current Visual Studio. The first step should therefore be to make the project independent of the character set. A colleague at work told me that I can do this if I put a macro _T() around each text. Unfortunately, the project contains a lot of static text and adding the macros should take weeks.

Is there no other way?

Ron
  • 14,674
  • 4
  • 34
  • 47
TalkingCode
  • 13,407
  • 27
  • 102
  • 147
  • This question is unclear. "[A] multibyte character set that I know is no longer supported" makes it sound like there's one specific character set whose support was dropped, but I suspect you're really trying to ask about support for MBCSes in general. Also, since it talks about support from the IDE rather than from the compiler and framework made me wonder whether your concern was that the source files (or .vcproj files) were saved in an MBCS or whether it was actually a code issue. – Adrian McCarthy Dec 28 '17 at 14:47
  • 2
    MBCS is still supported through the core operating system as well as MFC. It may not be desirable to use a broken character encoding, and hasn't been for two decades, but it is still supported. You need to clarify what you mean by *"is no longer supported"*. – IInspectable Dec 28 '17 at 14:50
  • 1
    The `_T()` macros were invented to allow almost the same code base to be compiled for both Windows 95 and Windows NT. Adding these now seems a bit late. – Bo Persson Dec 28 '17 at 15:10
  • **Lot of static text** is a code smell... Does your static text use only ASCII characters (0-127)? At this point (2017), I am not sure if one should still goes with UTF-16 as UTF-8 is becoming the standard almost everywhere. What to do really depends on your application needs and your actual code. – Phil1970 Dec 28 '17 at 15:50
  • 2
    Technically there is nothing you need to do except to download the MBCS library for whatever version of Visual Studio / MFC you are going to use. It's still supported, just not immediately out of the box. Secondly, you should be able to write a script or such to convert to wide characters--make sure you are under source control. I'd suggest putting the strings in resources so that if you ever want to translate it, you can. – Joseph Willcoxson Dec 28 '17 at 16:27
  • 1
    @Phil1970: The standard on Windows is UTF-16. UTF-8 is fine for data *interchange* (e.g. writing files to disk or a network socket, serving data from a web server, etc.). When it comes to Windows programming, you need a **very** good reason to not use UTF-16. – IInspectable Dec 28 '17 at 22:06

1 Answers1

4

There is no other way unfortunately. You can try to automate text editing with regex or some text editor like sed.

But personally I would prefer to check all the code manually that no multibyte char-related code is left: use _tcslen instead of strlen, _TCHAR instead of char, etc.

Other variant to consider is to make code explicitly use widechars: wcslen instead of strlen, wchar_t instead of char, L"some string" instead of _T("some string"), etc.

UPD: also I found some good news "The deprecation warning [MFC support for MBCS deprecated] has been removed from MFC in VC2017 and we will continue to provide MBCS support in future releases." (https://blogs.msdn.microsoft.com/vcblog/2013/07/08/mfc-support-for-mbcs-deprecated-in-visual-studio-2013/), so probably you can just left it as it is.

Anton Malyshev
  • 8,686
  • 2
  • 27
  • 45