【发布时间】:2015-05-06 13:50:57
【问题描述】:
拥有这些功能
void setPixel(SHORT x, SHORT y, WORD color) {
COORD pos = {x, y};
LPDWORD out;
FillConsoleOutputAttribute(console,color,1,pos,out);
}
void setScreenSize(SHORT x, SHORT y) {
COORD size = {x, y};
SetConsoleScreenBufferSize(console,size);
}
当我尝试在screenSize() 之后调用setPixel() 时收到错误消息:
int main() {
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
setScreenSize(120,40); // works well if setPixel is not called after
setPixel(40,12,GREEN); // works well if setScreenSize is not called
}
上面的程序崩溃了。我无法在FillConsoleOutputAttribute() 之后调用GetLastError(),这似乎会导致错误并立即使程序崩溃。我在the reference 中没有找到任何内容。
什么可能导致程序崩溃以及如何解决?
【问题讨论】:
-
开启编译器警告。特别是“使用未初始化的变量”警告。
-
啊,我明白你的意思了!
out是未初始化的:我使用了DWORD out并将其地址作为最后一个参数提供,它工作正常。谢谢。可能是一个答案。
标签: c winapi console-application