error:cannot convert parameter 1 from 'const char[12]' to 'LPCTSTR'

Question
        I'm trying to compile a piece of code such as:
MessageBox("Hello world!");
... when I compile the project, the compiler yields:
error C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'const char[12]' to 'LPCTSTR'
What am I doing wrong?
Problem
        This error message means that you are trying topass a multi-byte string (const char [12]) to a function which expects aunicode string (LPCTSTR). The LPCTSTR type extends to const TCHAR*, where TCHARis char when you compile for multi-byte and wchar_t for unicode. Since thecompiler doesn't accept the char array, we can safely assume that the actualtype of TCHAR, in this compilation, is wchar_t.
Resolution
     You will have to do one of two things:
               <1> Change yourproject configuration to use multibyte strings. Press ALT+F7 to open theproperties, and navigate to          ConfigurationProperties > General. Switch Character Set to "Use Multi-Byte CharacterSet".
              <2> Indicate that thestring literal, in this case "Hello world!" is of a specificencoding. This can be done through either prefixing it with L, such asL"Hello world!", or surrounding it with the generic _T("Helloworld!") macro. The latter will expand to the L prefix if you arecompiling for unicode (see #1), and nothing (indicating multi-byte) otherwise.
Variations
       Another error message, indicating the same problem,would be:
cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR'
Where LPCWSTR maps to a wchar_t pointer, regardless of your buildconfiguration. This problem can be resolved primarily by using solution #2, butin some cases also #1. A lot of the Microsoft provided libraries, such as thePlatform SDK, have got two variations of each function which takes strings asparameters. In case of a unicode build, the actual functions are postfixed W,such as the MessageBoxW seen above. In case of multi-byte, the function wouldbe MessageBoxA (ASCII). Which of these functions is actually used when youcompile your application, depends on the setting described in resolution #1above.

你可能感兴趣的:(error:cannot convert parameter 1 from 'const char[12]' to 'LPCTSTR')