由于安全性无法更新控制台光标信息(PCONSOLE_CURSOR_INFO)

发布于 2025-02-11 02:28:35 字数 718 浏览 1 评论 0原文

在控制台应用程序中,我想在特定位置编写输出,并且控制台(Windows CMD)不应有光标。为此,我得到了以下方式:

HANDLE hdl = GetStdHandle(STD_OUTPUT_HANDLE); 
if (hdl == INVALID_HANDLE_VALUE)
{
    printf("Error : Unable to get console handle.\n");
    return 0;
}
PCONSOLE_CURSOR_INFO lpConsoleCursorInfo = { NULL };
if (!GetConsoleCursorInfo(hdl, &lpConsoleCursorInfo))
{
    printf("Error : Unable to get console cursor information.\n");
    return 0;
}
lpConsoleCursorInfo->dwSize = 1; //App exit at this point with error code 0xC0000005h

我有运行时错误0xc0000005h。通过搜索,我得出的结论是,这是一个安全级别的问题,并使用设置访问级别的security_descriptor。

我无法找到如何将访问级别设置为已创建并通过Visual Studio Console应用程序与我的控制台应用程序关联的std_output_handle。

有人可以将我指向正确的方向吗?

In console application, I want to write the output at a specific location and there should be no cursor at the console (Windows CMD). To do so, I got following way:

HANDLE hdl = GetStdHandle(STD_OUTPUT_HANDLE); 
if (hdl == INVALID_HANDLE_VALUE)
{
    printf("Error : Unable to get console handle.\n");
    return 0;
}
PCONSOLE_CURSOR_INFO lpConsoleCursorInfo = { NULL };
if (!GetConsoleCursorInfo(hdl, &lpConsoleCursorInfo))
{
    printf("Error : Unable to get console cursor information.\n");
    return 0;
}
lpConsoleCursorInfo->dwSize = 1; //App exit at this point with error code 0xC0000005h

I got runtime error 0xC0000005h. By searching, I have reach at the conclusion that it is a security level issue, and to setup access level SECURITY_DESCRIPTOR is used.

I am unable to find the way how to set the access level to STD_OUTPUT_HANDLE that already created and associated with my console application by visual studio console application.

Can someone point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2025-02-18 02:28:35

没有安全问题,您根本不了解Windows指针类型的工作方式。 pconsole_cursor_info只是指针,删除P。

CONSOLE_CURSOR_INFO ConsoleCursorInfo = { NULL };
if (!GetConsoleCursorInfo(hdl, &ConsoleCursorInfo)) ...
else ConsoleCursorInfo.dwSize = ...

There is no security issue, you simply don't understand how Windows pointer types work. PCONSOLE_CURSOR_INFO is just a pointer, remove the P.

CONSOLE_CURSOR_INFO ConsoleCursorInfo = { NULL };
if (!GetConsoleCursorInfo(hdl, &ConsoleCursorInfo)) ...
else ConsoleCursorInfo.dwSize = ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文