我正在尝试在我的win7 sp1上打印ConsoleCursorInfo。
#include <windows.h>
#include <stdio.h>
int main(){
printf("xp SetConsoleCursorInfo\n");
CONSOLE_CURSOR_INFO *CURSOR;
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleCursorInfo(hStdout, CURSOR);
printf("%u",CURSOR->dwSize);
}我使用vs2019构建工具成功地构建了这段代码,尽管运行它总是会崩溃。我该如何修复它?
发布于 2020-10-21 22:25:13
您的代码中有几个问题。
这是您更正后的代码和注释:
#include <windows.h>
#include <stdio.h>
int main(){
printf("xp SetConsoleCursorInfo\n");
CONSOLE_CURSOR_INFO cursor; // we need a CONSOLE_CURSOR_INFO and not
// a pointer to CONSOLE_CURSOR_INFO
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (GetConsoleCursorInfo(hStdout, &cursor)) // check if GetConsoleCursorInfo fails
// ^ and mind the & operator here
printf("%u",cursor.dwSize);
else
printf("GetConsoleCursorInfo failed with error %d\n", GetLastError());
}https://stackoverflow.com/questions/64465491
复制相似问题