Context : programming a c/c++ win32-mfc library
How to know whether we are in a console or a windowed app?
You can determine if there is a console currently attached to the process by calling the win32 function GetConsoleWindow. If it returns NULL then there is no console attached to the process. However this will not necessarily tell you if you are running in a windowed app or not. For example I could have a windowed app that uses AllocConsole on start-up to allocate a console for debug output in which case you would have both at the same time. The other problem I can see with what you describe is an application might have no windows and no console attached (A windows service for example).
I'm going to have to agree with litb and Martin on this one as well. If your library needs to know this then it probably isn't decoupled enough. If you are using this to determine where to send debug output for example the best approach would be to use cout or cerr and let the application that is using the library deal with redirecting the stream to where it wants it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With