c++winapicharintellisenselpcwstr

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


I get this error:

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

Here's a part of my code

void score(void)
{
    char s[128];
    sprintf_s(s, "Thread War! Hits:%d  Misses:%d", hit, miss);
    SetConsoleTitle(s);
    ...
}

How to fix this?


Solution

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