In Windows 8, we have a problem with FreeConsole. It seems to close stdio handles without closing file streams.
This may be a Windows 8 issue, or it may be that I just don’t understand the (completely absurd) way that the Windows / GUI application subsystem does things.
What's happening?
The minimum example is below. Tested with compilers: VS2005, VS2013, VS2017, using a statically coupled CRT.
#include <windows.h> #include <io.h> #include <stdio.h> static void testHandle(FILE* file) { HANDLE h = (HANDLE)_get_osfhandle(fileno(file)); DWORD flags; if (!GetHandleInformation(h, &flags)) { MessageBoxA(0, "Bogus handle!!", "TITLE", MB_OK); } } int main(int argc, char** argv) { freopen("NUL", "wb", stdout); // Demonstrate the issue with NUL // Leave stderr as it is, to demonstrate the issue with handles // to the console device. FreeConsole(); testHandle(stdout); testHandle(stderr); }
windows-8 msvcrt visual-studio-2005
Nicholas Wilson Oct 01 2018-12-12T00: 00Z
source share