error: cannot convert 'const wchar_t [13]' to 'LPCSTR {aka const char*}' in assignment

前端 未结 3 1499
无人共我
无人共我 2020-11-29 09:15
// include the basic windows header file
#include 
#include 

// the WindowProc function prototype LRESULT CALLBACK WindowProc(HWN         


        
3条回答
  •  情歌与酒
    2020-11-29 10:18

    Your project doesn't have the UNICODE preprocessor symbol defined, so Windows API functions that take pointers to strings expect char * and not wchar_t *. Change

    L"WindowClass1"
    

    to

    "WindowClass1"
    

    Do the same for the remaining string literals. Alternatively, change them to _T("WindowClass1"), this will expand to the correct type of string literal based on the UNICODE symbol being defined.


    My recommendation is to go to your project properties and change the Character Set setting to Unicode, and then use the wide char versions of all Windows API functions explicitly. For example, instead of CreateWindow, call CreateWindowW.

    EDIT:
    The project setting I suggested only applies to Visual Studio, not sure how to do that in Code::Blocks.

提交回复
热议问题