Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7932 Discussions

Windows 11, MS VS Community, WriteConsoleOutput

jimdempseyatthecove
Black Belt
398 Views

I am porting some old code (30 years old), which builds and runs properly on Windows 10, using MS VS 2019 Pro (x64), but has errant behavior on Windows 11 using MS VS Community (newest download).

 

The old code uses WriteConsoleOutput to update the (virtual) display.

The output isn't consistent with what it was using the prior system.

1) The code uses NULL characters to fill from the end of text for the line to the end of the display line.  On the old system (and systems going back 30 years) this voids out the remainder of the displayed text (had there been any). On the new system, the NULLs are ignored.

IOW assume window has a width of 80 characters. In the position in the buffer to be written using WriteConsoleOutput, of the beginning of a line, I insert three characters FOO, followed by 77 Nulls (remainder of line), followed by three characters BAR, followed by 77 NULLS, etc. the old system shows

FOO

BAR

whereas the new system shows

FOOBAR

 

IOW the nulls are not passed into the screen buffer. The behavior is as if the (underlaying) code treats/uses each line worth of data in the window buffer of WriteConsolWindow as a WSTRING and truncates at the NULL character. The older Windows and/or MS VS did not do this.

 

2) The console window opens up with a vertical scroll bar. This wouldn't be an issue, except that the cursor positioning (coordinates) pass into WriteConsoleWindow do not place the data into the correct positions of the console window. Data gets into the window, but not at the specified locations.

 

Any guidance on if this can be fixed without much adoo.

 

Note, using Virtual Terminal, when writing the last character on the screen line, the window line is indexed in preparation for additional output for that line. In the application case, it terminates output for that line and I do not want to reserve a line (or reserver the last column of the line).

Jim Dempsey

0 Kudos
1 Solution
jimdempseyatthecove
Black Belt
364 Views

Well, I found the solution. It appears that a flag bit in the console mode is initialized differently between versions of Windows.

By setting ENABLE-VIRTUAL_TERMINAL_PROCESSING this corrects the problem.

	DWORD dwMode = 0;
	if (!GetConsoleMode(hConsoleOutput, &dwMode))
	{
		printf("Unable to get console mode\r\n");
		return GetLastError();;
	}
	dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
	if (!SetConsoleMode(hConsoleOutput, dwMode))
	{
		printf("Unable to get console mode\r\n");
		return GetLastError();;
	}

 Jim Dempsey

View solution in original post

0 Kudos
2 Replies
jimdempseyatthecove
Black Belt
365 Views

Well, I found the solution. It appears that a flag bit in the console mode is initialized differently between versions of Windows.

By setting ENABLE-VIRTUAL_TERMINAL_PROCESSING this corrects the problem.

	DWORD dwMode = 0;
	if (!GetConsoleMode(hConsoleOutput, &dwMode))
	{
		printf("Unable to get console mode\r\n");
		return GetLastError();;
	}
	dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
	if (!SetConsoleMode(hConsoleOutput, dwMode))
	{
		printf("Unable to get console mode\r\n");
		return GetLastError();;
	}

 Jim Dempsey

0 Kudos
SeshaP_Intel
Moderator
311 Views

Hi,


Glad to know that your issue is resolved. As your issue was resolved, i am going ahead and closing this case. 

Please post a new question as this thread will no longer be monitored by Intel.


Thanks and Regards,

Pendyala Sesha Srinivas


0 Kudos
Reply