Cannot convert parameter from 'const char[20]' to 'LPCWSTR'

后端 未结 3 1983
独厮守ぢ
独厮守ぢ 2020-11-27 23:16

When compiling this code:

#include 

int WINAPI WinMain(HINSTANCE hInsance,HINSTANCE hPrevInstance,PSTR cmdLine,int showCmd){
    MessageBox         


        
相关标签:
3条回答
  • 2020-11-27 23:37

    By default UNICODE is defined in Visual Studio 2010. Either call MessageBoxA instead of using the MessageBox define or pass a wide string literal (L"First Win32 Program" and L"Window Title") or, if you really care about being able to build without UNICODE defined, use the _T macro around your string literals: _T("First Win32 Program") (this is the same as L"First Win32 Program" when UNICODE is defined, but it will be "First Win32 Program" when UNICODE is not defined).

    For more information about UNICODE and how it affects what APIs are called, see this link: http://msdn.microsoft.com/en-us/goglobal/bb688113.aspx. Specifically, the sections below "Creating Win32 Unicode Applications".

    On a side note: All Windows operating systems supported by Microsoft today are Unicode native. I would recommend to always favor the "wide" API. In this case, MessageBoxW, which is what MessageBox is defined to be when UNICODE is set. The days of using the _T macro and compiling without UNICODE defined should be behind us.

    0 讨论(0)
  • 2020-11-27 23:38

    You have UNICODE defined, so MessageBox is expecting a wide string.

    0 讨论(0)
  • 2020-11-27 23:50

    MessageboxW expects wide char... you can make little bit changes in your code and than your code will be perfectly running like. Solution One :- MessageBox(0,L"First Win32 Program",L"Window Tittle",MB_OK); Solution two. Use MessageboxA instead of Messagebox. MessageboxA will take char in ANCI character set.

    0 讨论(0)
提交回复
热议问题