Cannot Convert 'Const Char*' to 'Lpcwstr {Aka Const Wchar_T*}'

cannot convert 'LPCWSTR {aka const wchar_t*}' to 'LPCSTR {aka const char*}

Change CreateWindowEx to CreateWindowExW or define the macro UNICODE before including any headers.

cannot convert 'wchar_t*' to 'LPCSTR' {aka 'const char*'}

Well i see that pBuffer have some issues and thats propably becasue you are using multibyte character set i compiled this code with multibyte character set and i get same errors like you need to change multibyte character set to Use Unicode Character Set and it should solve your problem. Its viusal studio option :)

error C2440: '=': cannot convert from 'const char *' to 'LPCWSTR'

What you need to know about the windows API is that it comes in 2 flavors ,namely UNICODE flavor and non-UNICODE flavor.

When you include windows.h

the flavor selected depends on whether UNICODE is defined.

Many if not most WINAPI structures and function are just macros that basically just add either a W or an A to the macro-name to get the real name of the thing you want.

The UNICODE flavor requires character types of wchar_t and non-UNICODE takes char types (or pointers to them).

So you either must use the non-macro names for structs and/or functions or adjust your usage of types to the required macro-definition (in your case use std::wstring in stead of std::string).

Error C2664: MessageBoxW cannot convert argument 2 from 'const char ' to 'LPCWSTR'

std::runtime_error::what() returns const char*, so you should use MessageBoxA(), not MessageBox() nor MessageBoxW().

MessageBoxA(nullptr,  error.what(), "An error has occured", MB_OK);

Also don't forget to remove the L prefix from the string literal.



Related Topics



Leave a reply



Submit