Argument of Type "Char *" Is Incompatible with Parameter of Type "Lpwstr"

Argument of type char * is incompatible with parameter of type LPWSTR

You need to use the ansi version:

std::string GetPath()
{
char buffer[MAX_PATH] = {};
::GetSystemDirectoryA(buffer,_countof(buffer)); // notice the A
strcat(buffer,"\\version.dll");

return std::string(buffer);
}

Or use unicode:

std::wstring GetPath()
{
wchar_t buffer[MAX_PATH] = {};
::GetSystemDirectoryW(buffer,_countof(buffer)); // notice the W, or drop the W to get it "by default"
wcscat(buffer,L"\\version.dll");

return std::wstring(buffer);
}

Rather than call the A/W versions explicitly you can drop the A/W and configure the whole project to use ansi/unicode instead. All this will do is change some #defines to replace foo with fooA/W.

Notice that you should use _countof() to avoid incorrect sizes depending on the buffers type too.

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 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.

char* incompatible with parameter of LPWSTR for C++

Yes, that's true.

If you insist on having a char* parameter, call CreateProcessA instead of CreateProcess. Otherwise, make path an LPWSTR too and bring your program into this millenium.

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.

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



Related Topics



Leave a reply



Submit