Case in point. When I tried to compile a small test unit, I got a cornball error that said:
I stared at my four line WinMain() like a monkey working a math problem.error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [6]' to 'LPCWSTR'
Tell-tale hint, and easy to read past, is the bit that says "MessageBoxW". I eventually noticed that my program used MessageBox.
Turns out that there are three versions of MessageBox, each one depends on compile time flags. There is: an ANSI version, "MessageBoxA"; a unicode version, "MessageBoxW"; and a TCHAR version, "MessageBox".
ANSI
Code: Select all
MessageBoxA(NULL, "Hello!", "Hello World", MB_OK | MB_ICONEXCLAMATION);
Code: Select all
MessageBoxW(NULL, L"Hello!", L"Hello World", MB_OK | MB_ICONEXCLAMATION);
Code: Select all
MessageBox(NULL, _T("Hello!"), _T("Hello World"), MB_OK | MB_ICONEXCLAMATION);
WTF? Well, _T is defined in tchar.h so I #include'd that and Voila! My totally useless test worked. I also discovered that if you don't include the tchar.h, remove the _T(), and turn off the UNICODE flag you can compile successfully also with "MessageBox".error C3861: '_T': identifier not found
Go to Project->Properties->Configuration Properties->C/C++->Preprocessor and click on the three dots next to Preprocessor Definitions. Uncheck the box next to "Inherit from parent or project defaults" and click OK. This sets $(NOINHERIT) to drop unicode support.
C++ seems like child's play compared to the wacked out easter eggs in the VS IDE!
Anyone else have helpful hints or tricks for VS?
-capt jack
EDIT:
Forgot to reference my sources!
http://social.msdn.microsoft.com/Forums ... b549f04be8
http://social.msdn.microsoft.com/Forums ... 7fab8dcd21