Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdout_sink raises exception in GUI (non-console) Windows App #1828

Closed
dgehri opened this issue Feb 11, 2021 · 3 comments
Closed

stdout_sink raises exception in GUI (non-console) Windows App #1828

dgehri opened this issue Feb 11, 2021 · 3 comments

Comments

@dgehri
Copy link

dgehri commented Feb 11, 2021

Regression after fix for Issue #1675 : With this fix, creating a stdout_sink in an GUI (non-console) application now throws an exception, because the call ::_get_osfhandle(::fileno(file)); now fails, whereas the previous version would allow the sink to be created.

So where a GUI app previously would log to the debugging console, it now throws an Exception. This is a regression.

@tt4g
Copy link
Contributor

tt4g commented Feb 12, 2021

IMO.

This is the design of the Microsoft Windows operating system.
The STDOUT (STD_OUTPUT_HANDLE) is not attached to GUI applications.
If we need STDOUT in GUI application, you have to attach a console by calling AllocConsole().

Quote: https://docs.microsoft.com/en-us/windows/console/getstdhandle

Console processes must start with the standard handles filled or they will be filled automatically with appropriate handles to a new console. Graphical user interface (GUI) applications can be started without the standard handles and they will not be automatically filled.

Calling AllocConsole() in a GUI application will attach a console, which will be the standard output destination (on most machines, cmd.exe will be launched).
This is undesirable behavior for many programmers, and the library should not call AllocConsole().

@gabime
Copy link
Owner

gabime commented Feb 13, 2021

I tend to fix this since it is not very easy to cope with (e.g when spdlog used through a 3rd party dependency), and indeed it breaks backward compatibility.

@gabime gabime closed this as completed in 5efccfa Feb 13, 2021
@gabime
Copy link
Owner

gabime commented Feb 13, 2021

Fixed in 5efccfa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants