GetConsoleWindow() returns nonsense instead of NULL in 1809 when there is no console. #1556

Open
opened 2026-01-30 22:30:35 +00:00 by claunia · 0 comments
Owner

Originally created by @EricYoungdale on GitHub (Jun 8, 2019).

Up to and including 1803, a call to GetConsoleWindow() will return NULL if the process has no console. In 1809, it seems to just return some uninitialized variable instead.

The enclosed testcase demonstrates this. It launches a child using the CREATE_NO_WINDOW flag, and passing pipe handles as the std handles. The child reports back (via the pipe) to the launcher what it sees.

Expected behavior (both Win7 and 1803) give something like this:

Parent console handle is 00330654
child says: stdin handle is 000000FC
stdout handle is 00000108
stderr handle is 00000110
hConsole is 0000000F
Console hWnd handle is 00000000
Cannot get window class

The last two lines are the ones that are of the most interest. In 1809, we instead get:

Parent console handle is 00420AEE
child says: stdin handle is 0000029C
stdout handle is 000002A8
stderr handle is 000002B0
hConsole is 00000298
Console handle is 004035E8
Cannot get window class

The console handle that is obtained is non-zero, and it is not even a valid HWND.

testcase.zip

Originally created by @EricYoungdale on GitHub (Jun 8, 2019). Up to and including 1803, a call to GetConsoleWindow() will return NULL if the process has no console. In 1809, it seems to just return some uninitialized variable instead. The enclosed testcase demonstrates this. It launches a child using the CREATE_NO_WINDOW flag, and passing pipe handles as the std handles. The child reports back (via the pipe) to the launcher what it sees. Expected behavior (both Win7 and 1803) give something like this: Parent console handle is 00330654 child says: stdin handle is 000000FC stdout handle is 00000108 stderr handle is 00000110 hConsole is 0000000F Console hWnd handle is 00000000 Cannot get window class The last two lines are the ones that are of the most interest. In 1809, we instead get: Parent console handle is 00420AEE child says: stdin handle is 0000029C stdout handle is 000002A8 stderr handle is 000002B0 hConsole is 00000298 Console handle is 004035E8 Cannot get window class The console handle that is obtained is non-zero, and it is not even a valid HWND. [testcase.zip](https://github.com/microsoft/terminal/files/3268549/testcase.zip)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1556