Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 25, 2022 [Issue 23312] Cannot use writeln with WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich@gmail.com --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- My workaround for this is to use `main()` instead of `WinMain()`. It's still possible to write GUI apps this way, and there will be a console spawned with the app so the stdout/stderr handles are valid this way. Maybe there's a way to spawn a console when using WinMain if one is not detected. Or alternatively it would be nice to be able to set stdout/stderr to a file handle when using WinMain. Not sure if this is already possible. -- |
September 25, 2022 [Issue 23312] Cannot use writeln with WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Mike Parker <aldacron@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |aldacron@gmail.com Resolution|--- |INVALID --- Comment #2 from Mike Parker <aldacron@gmail.com> --- This is not specific to D. It's a Windows thing, and it happens in C and C++ programs as well. The presence of WinMain in your source automatically tells most (all?) linkers on Windows that you're building a "windows subsystem" executable. This means standard I/O will be unavailable at startup since there's no console to write to or read from. Andrej's suggestion of using main instead, which is automatically interpreted as a "console subsystem" works, and is probably the best solution if you need stdout/stderr/stdin. Windows linkers also support a flag that allows you to specify either the windows or console subsystem (among others) no matter which entry point you have (WinMain or main). The MS linker also has a flag, and requires its use, to specify the entry point if it doesn't match the subsystem. You can find the documentation for both at the following links (and remember, these are specifically for the Microsoft linker; the LDC linker may support both or may not require the entry specification, I don't know): https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170 https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=msvc-170 But there's no reason to use WinMain if you want a console, so I just use main. Anyway, this isn't a D-specific issue, so I'm going to close this as invalid. If there's not a way in the standard library to redirect standard I/O (to file, or a console created via AttachConsole), there should be, but that should be a separate issue from this one. -- |
September 26, 2022 [Issue 23312] Cannot use writeln with WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 --- Comment #3 from Perry <alex@perry.express> --- Thanks I'll use main as a workaround. I'd argue this is still a bug, pretty sure in C/C++ the output would silently fail rather than outright crash. -- |
September 26, 2022 [Issue 23312] Cannot use writeln with WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Mike Parker <aldacron@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|INVALID |--- --- Comment #4 from Mike Parker <aldacron@gmail.com> --- Okay. I glossed over the bit about the crash. I'll change the title and reopen. -- |
September 26, 2022 [Issue 23312] Crash when calling writeln in WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Mike Parker <aldacron@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Cannot use writeln with |Crash when calling writeln |WinMain |in WinMain -- |
December 17, 2022 [Issue 23312] Crash when calling writeln in WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P1 |P3 -- |
April 12, 2023 [Issue 23312] Crash when calling writeln in WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Richard Cattermole <alphaglosined@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |alphaglosined@gmail.com --- Comment #5 from Richard Cattermole <alphaglosined@gmail.com> --- It appears on Microsoft's end that _setmode is expected to assert out if anything isn't right. For example: > Unicode mode is for wide print functions (for example, wprintf) and is not supported for narrow print functions. Use of a narrow print function on a Unicode mode stream triggers an assert. https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=msvc-170 Realistically though std.stdio shouldn't be used for console output and therefore that particular bit of code shouldn't exist to assert out. -- |
June 20 [Issue 23312] Crash when calling writeln in WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://issues.dlang.org/sh | |ow_bug.cgi?id=24001 -- |
June 21 [Issue 23312] Crash when calling writeln in WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla@digitalmars.com --- Comment #6 from Walter Bright <bugzilla@digitalmars.com> --- The code that is crashing is calling _setmode() but not checking the error return from it. https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=msvc-170 -- |
June 21 [Issue 23312] Crash when calling writeln in WinMain | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23312 Dlang Bot <dlang-bot@dlang.rocks> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> --- @WalterBright created dlang/phobos pull request #8770 "fix Issue 23312 - Crash when calling writeln in WinMain" fixing this issue: - fix Issue 23312 - Crash when calling writeln in WinMain https://github.com/dlang/phobos/pull/8770 -- |
Copyright © 1999-2021 by the D Language Foundation