首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows7 SP1上的GetConsoleCursorInfo崩溃

Windows7 SP1上的GetConsoleCursorInfo崩溃
EN

Stack Overflow用户
提问于 2020-10-21 22:13:55
回答 1查看 26关注 0票数 0

我正在尝试在我的win7 sp1上打印ConsoleCursorInfo。

代码语言:javascript
复制
#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构建工具成功地构建了这段代码,尽管运行它总是会崩溃。我该如何修复它?

EN

回答 1

Stack Overflow用户

发布于 2020-10-21 22:25:13

您的代码中有几个问题。

这是您更正后的代码和注释:

代码语言:javascript
复制
#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());
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64465491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档