![](/img/trans.png)
[英]Argument of type “LPCWSTR” is incompatible of the parameter of type “LPCSTR”
[英]argument of type WORD* is incompatible with parameter of type LPCWSTR
问题是&cursorTile.Attributes.
我得到的错误是(argument of type "WORD*" is incompatible with parameter of type "LPCWSTR")
我试图找到一些解决方案,我正在使用多字节字符集。
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);
}
这是非常详尽的错误。 WriteConsoleOutputCharacter
需要一些字符串作为第二个参数。 如果您的程序被定义为unicode,则它期望LPCWSTR
,这基本上是对以null结尾的wchar_t*
字符串的(难看)类型定义。
在您的调用中,您传递了&cursorTile.Attributes
,其类型为DWORD*
(这也是对unsigned long*
丑陋类型定义)。 您需要传递一些宽字符字符串而不是无符号长指针,即您要打印的字符串。
DWORD:32位无符号整数。 范围是0到4294967295十进制。
typedef unsigned long DWORD;
LPCWSTR:指向以16位Unicode字符为常数的,以空字符结尾的常量的指针。
typedef CONST WCHAR *LPCWSTR;
两者都是完全不同的数据类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.