FillConsoleOutputCharacterW()C ++错误(FillConsoleOutputCharacterW() C++ error)

编程入门 行业动态 更新时间:2024-10-23 05:39:39
FillConsoleOutputCharacterW()C ++错误(FillConsoleOutputCharacterW() C++ error)

当这部分代码运行时,我收到运行时错误:

void PrintChar(int x, int y, char ch, Colors color) { COORD c = {y,x}; FillConsoleOutputCharacterW(GameData::handle, ch, 1, c, NULL); FillConsoleOutputAttribute(GameData::handle, color, 1, c, NULL); }

错误是它覆盖了位置0x00000000

有人可以解释为什么这个错误会出现一个例子吗?

GameData类 -

class GameData { public: static CRITICAL_SECTION cs; static void * handle; static GameStates gameState; static int speed; static int level; static int points; static int nextShape; static int nextTurnShape; };

颜色 -

enum Colors { Black, DarkBlue, Green, Blue, Red, Purple, Yellow, While, Gray, LightDarkBlue, LightGreen, LightBlue, LightRed, LightPurple, LightYellow, BrightWhile };

PS

如果我需要提供更多代码来澄清正在发生的事情,请告诉我。

I'm getting a runtime error whenver this section of code runs:

void PrintChar(int x, int y, char ch, Colors color) { COORD c = {y,x}; FillConsoleOutputCharacterW(GameData::handle, ch, 1, c, NULL); FillConsoleOutputAttribute(GameData::handle, color, 1, c, NULL); }

The error is that it is overwriting location 0x00000000

Could someone explain why this error comes up with an example please?

GameData class -

class GameData { public: static CRITICAL_SECTION cs; static void * handle; static GameStates gameState; static int speed; static int level; static int points; static int nextShape; static int nextTurnShape; };

Colours -

enum Colors { Black, DarkBlue, Green, Blue, Red, Purple, Yellow, While, Gray, LightDarkBlue, LightGreen, LightBlue, LightRed, LightPurple, LightYellow, BrightWhile };

P.S.

Please let me know if I need to provide any more code to clarify what is going on.

最满意答案

如果您查看该API的文档: https : //msdn.microsoft.com/en-us/library/windows/desktop/ms682663(v = vs。85).aspx

您应该传递一个DWORD变量的地址,该变量接收实际写入控制台屏幕缓冲区的字符数

void PrintChar(int x, int y, char ch, Colors color) { DWORD dwNumOfCharsWritten; COORD c = {static_cast<short>(y), static_cast<short>(x)}; FillConsoleOutputCharacterW(GameData::handle, ch, 1, c, &dwNumOfCharsWritten); FillConsoleOutputAttribute(GameData::handle, color, 1, c, &dwNumOfCharsWritten); }

If you look at the documentation of that API: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682663(v=vs.85).aspx

You should pass the address of a DWORD variable that receives the number of characters actually written to the console screen buffer

void PrintChar(int x, int y, char ch, Colors color) { DWORD dwNumOfCharsWritten; COORD c = {static_cast<short>(y), static_cast<short>(x)}; FillConsoleOutputCharacterW(GameData::handle, ch, 1, c, &dwNumOfCharsWritten); FillConsoleOutputAttribute(GameData::handle, color, 1, c, &dwNumOfCharsWritten); }

更多推荐

本文发布于:2023-08-03 16:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   FillConsoleOutputCharacterW   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!