VC++ Code Build in VS2013
I am trying to build VC++ legacy code in VS2013. Initially I was not able to build the code because of error :
error MSB8031: Building an MFC project for a non-Unicode character set is deprecated. You must change the project property to Unicode or download an additional library.
For resolving this issue I have changed the following settings: Project->Properties->Configuration Properties->General->Project Default->Character Set ->Use Unicode Character Set.
This has resolved my problem of building the code where as I started recieving errors inappropraite Type Casting error for all my message boxes and for other User defined strings: Sample Code for MessageBox:
MessageBox (NULL, "Some String","Some String", MB_OK | MB_ICONSTOP);
Error: error C2664: 'int MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT)' : cannot convert argument 2 from 'String' to 'LPCWSTR'.
It was all working for VS2010.
Is there any setting I can turn on or off in VS2013 so that I should not recieve such type casting or Do I have to manually type cast for every error.
You have set the project to use Unicode, so you need to have wide char strings as your literals. With MFC, you can use the _T() macro to automatically do the correct thing based on your project settings.
For your example, try this:
MessageBox (NULL, _T("Some String"), _T("Some String"), MB_OK | MB_ICONSTOP);
On a Unicode build, the macro will expand to make the literals wide chars:
MessageBox (NULL, L"Some String", L"Some String", MB_OK | MB_ICONSTOP);
The _T() macro is identical to the _TEXT macro and these and other Unicode tips are documented on MSDN.
If you have too much code to convert everything to Unicode (it's not trivial), you may wish to carry on using MBCS, which it is possible to do by downloading the optional Multibyte Library for VS2013 and changing your project properties back to the way they were originally.