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

2k Views Asked by At

The problem is &cursorTile.Attributes.
The error I am getting is (argument of type "WORD*" is incompatible with parameter of type "LPCWSTR")
I have tried to find some solutions, I am using multi-byte character set.

void CMap::Draw(){
SMALL_RECT drawRect = { 0, 0, MAP_WIDTH - 1, MAP_HEIGHT - 1 };
COORD buffersize = { MAP_WIDTH, MAP_HEIGHT };
COORD zeroZero = { 0, 0 };
DWORD dwResult = 0;
char szCursor[2] = "";

HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);

for (int i = 0; i < (int)m_vTiles.size(); i++){
    m_screenBuffer[i] = m_vTiles[i].GetChar();
}

WriteConsoleOutput(hOutput, m_screenBuffer, buffersize, zeroZero, &drawRect);

if (g_pCursorTile != NULL){
    CHAR_INFO cursorTile = g_pCursorTile->GetChar();
    sprintf(szCursor, "%c", cursorTile.Char);
    WriteConsoleOutputCharacter(hOutput, szCursor, 1, g_cursorPos, &dwResult);
    WriteConsoleOutputCharacter(hOutput, &cursorTile.Attributes, 1, g_cursorPos, &dwResult);
}
2

There are 2 best solutions below

7
On

this is very explenetory error. WriteConsoleOutputCharacter expects some string as the second argument. if your program is defined as unicode, it expects LPCWSTR, which is basically an (ugly) type-definition to a null terminated wchar_t* string.

in your invocation, you pass &cursorTile.Attributes which has the type of DWORD* (which is again, ugly type-definition to unsigned long*). you need to pass some wide-char string instead of unsigned long pointer, which is , the string you are trying to print.

0
On

DWORD: A 32-bit unsigned integer. The range is 0 through 4294967295 decimal.

typedef unsigned long DWORD;

LPCWSTR: A pointer to a constant null-terminated string of 16-bit Unicode characters.

typedef CONST WCHAR *LPCWSTR;

Both are different datatypes altogether.