Home > OS >  Unable to update Console Cursor Info (PCONSOLE_CURSOR_INFO) due to security
Unable to update Console Cursor Info (PCONSOLE_CURSOR_INFO) due to security

Time:06-28

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?

CodePudding user response:

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 = ...
  • Related