Incompatible with Parameter of Type "Lpcwstr"

Incompatible with parameter of type LPCWSTR

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

Argument of type const char * is incompatible with parameter of type LPCWSTR Visual Studio 2019

There are two ways to fix this.

First is to use a string made of wide characters:

OutputDebugString(L"Lets test this out \n");
// ^

Second is to call the version of the function that takes a narrow character string:

OutputDebugStringA("Lets test this out \n");
// ^

Since the Windows API prefers to work with wide character strings, I'd prefer the first solution.

P.S. LPCWSTR stands for "Long Pointer to Constant Wide STRing". The L is obsolete, you can ignore that.

Argument of type LPCWSTR is incompatible of the parameter of type LPCSTR

LPCWSTR is an alias for const wchar_t*.

You are using the TCHAR version of the GetDriveType() and MessageBox() functions. TCHAR maps to wchar_t if UNICODE is defined at compile-time, otherwise it maps to char.

Your drive2 variable is an array of wchar_t pointers, so in order to pass drive2[i] as-is to GetDriveType() and MessageBox(), you have to compile your project for Unicode (ie, make the UNICODE conditional be defined at compile-time), which will make GetDriveType() map to GetDriveTypeW() and MessageBox() map to MessageBoxW() so that they accept only wide (wchar_t) strings. Otherwise, GetDriveType() will map to GetDriveTypeA() and MessageBox() will map to MessageBoxA() so they accept only narrow (char) strings.

You are passing narrow string literals to MessageBox(), which will not work when compiling for Unicode. And you can't pass wide strings to TCHAR functions if you are NOT compiling for Unicode - which sounds like the case in your situation, as the error message is complaining about passing a const wchar_t* pointer to a const char* parameter.

You need to use the TEXT() macro to make string literals be wide when UNICODE is defined, instead of being narrow.

I would also suggest using TEXT() for the string literals in your drive2 array as well, to match the TCHAR functions that you are passing the array elements to.

Also, your loop is going out of bounds of the drive2 array.

With that said, try this:

LPCTSTR drive2[4] = { TEXT("C:\\"), TEXT("D:\\"), TEXT("E:\\"), TEXT("F:\\") };
int i;
UINT test;

for (i = 0; i < 4; i++)
{
test = GetDriveType(drive2[i]);

switch (test)
{
case 0:
::MessageBox(Handle, drive2[i], TEXT("0 cannot be determined"), MB_OK);
break;
case 1:
::MessageBox(Handle, drive2[i], TEXT("1 invalid"), MB_OK);
break;
case 2:
::MessageBox(Handle, drive2[i], TEXT("2 removable"), MB_OK);
break;
case 3:
::MessageBox(Handle, drive2[i], TEXT("3 fixed"), MB_OK);
break;
default:
::MessageBox(Handle, drive2[i], TEXT("Unknown value!"), MB_OK);
break;
}
}

Otherwise, if you want to deal exclusively with wchar_t (which you should be), then use the Unicode-based function definitions directly, and use wide string literals only, don't deal with TCHAR at all:

LPCWSTR drive2[4] = { L"C:\\", L"D:\\", L"E:\\", L"F:\\" };
int i;
UINT test;

for (i = 0; i < 4; i++)
{
test = GetDriveTypeW(drive2[i]);

switch (test)
{
case 0:
::MessageBoxW(Handle, drive2[i], L"0 cannot be determined", MB_OK);
break;
case 1:
::MessageBoxW(Handle, drive2[i], L"1 invalid", MB_OK);
break;
case 2:
::MessageBoxW(Handle, drive2[i], L"2 removable", MB_OK);
break;
case 3:
::MessageBoxW(Handle, drive2[i], L"3 fixed", MB_OK);
break;
default:
::MessageBoxW(Handle, drive2[i], L"Unknown value!", MB_OK);
break;
}
}

argument of type const char * is incompatible with parameter of type LPCWSTR

Obviously not a good tutorial. Do it like like this

MessageBox(NULL, L"Ciao!", L"La prima GUI", MB_OK);

Using L changes the string literal so that it uses wide characters. A wide character string literal can be converted to the type LPCWSTR, a normal string literal cannot.

Argument of type const wchar_t* is incompatible with parameter of type LPTSTR

TEXT("RegisterWindowClass") is supposed to be used.

Avoid using L"RegisterWindowClass" or "RegisterWindowClass" with parameters of type LPTSTR.

Also change the parameter type to LPCTSTR in static void ErrorExit(LPCTSTR lpszFunction).

argument of type char * is incompatible with parameter of type LPCWSTR

You're building with the UNICODE macro defined, which means that all functions default to their wide-character equivalent. So when you call SetConsoleTitle that's really a macro that expands to SetConsoleTitleW.

A wide character has the type wchar_t and is incompatible with char.

You either have to explicitly call SetConsoleTitleA, remove the definition of UNICODE, or start using TCHAR and related types and macros.



Related Topics



Leave a reply



Submit