Incompatible with parameter of type "LPCWSTR"

Another way to come by this issue, is to use the Lmacro in front of your string.

MessageBox(NULL, L"Dialog creation failed! Aborting..", L"Error", MB_OK);

See: What does the 'L' in front a string mean in C++?

or

L prefix for strings in C++


To compile your code in Visual C++ you need to use Multi-Byte char WinAPI functions instead of Wide char ones.

Set Project -> Properties -> Advanced (or. General for older versions) -> Character Set option to Use Multi-Byte Character Set

also see the screenshot


I actually found another way to resolve this error since above method did not work for me.

I casted all my constant character strings with (LPCWSTR). The solution looks like this
Earlier

MessageBox(NULL,"Dialog creation failed! Aborting..", "Error", MB_OK);

After casting to LPCWSTR

MessageBox(NULL, (LPCWSTR) "Dialog creation failed! Aborting..", (LPCWSTR) "Error", MB_OK);

So just copying the (LPCWSTR) and pasting wherever this error was generated resolved all my errors.


you can use wchar_t

class Dir
{
public:
    wchar_t* cat;
Dir()
{
    wcout << "(C:/*)\n";
    cat = new wchar_t[50];
    wcin >> cat;
}

    void virtual ShowFiles()
    {
    }

};

In Visual Studio 2013 and later, the MFC libraries for multi-byle character encoding (MBCS) will be provided as an add-on to Visual Studio

Tags:

C++

Visual C++