http://bugs.winehq.org/show_bug.cgi?id=22216
Summary: Problem with freopen("CONOUT$", "w", stdout); Product: Wine Version: unspecified Platform: x86 OS/Version: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: msvcrt AssignedTo: wine-bugs@winehq.org ReportedBy: terra@gnome.org
I am having trouble with code that reads...
has_console = FALSE; { typedef BOOL (CALLBACK* LPFNATTACHCONSOLE)(DWORD); LPFNATTACHCONSOLE MyAttachConsole; HMODULE hmod;
if ((hmod = GetModuleHandle("kernel32.dll"))) { MyAttachConsole = (LPFNATTACHCONSOLE) GetProcAddress(hmod, "AttachConsole"); if (MyAttachConsole && MyAttachConsole(ATTACH_PARENT_PROCESS)) { freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); dup2(fileno(stdout), 1); dup2(fileno(stderr), 2); has_console = TRUE; } } }
The freopen calls should cause stderr and stdout to be redirected to the console. Under wine they are not.
The failure occurs in dlls/kernel32/console.c function OpenConsoleW when it checks creation != OPEN_EXISTING. creation at that point is CREATE_ALWAYS.
Changing the check to allow CREATE_ALWAYS fixes my problem, but may not be right.
(The code is from Gnumeric, btw.)