You can determine if there is currently a console that calls the win32 function GetConsoleWindow . If it returns NULL, then the console is not connected to the process. However, this does not necessarily tell you whether you are working in a windowed application or not. For example, I could have a windowed application that uses AllocConsole at startup to select the console for debugging output, in which case you would have both at the same time. Another problem that I see with what you described is that the application may not have windows and the console is not connected (for example, the Windows service).
I, too, will have to agree with him and Martin on this. If your library needs to know this, then it is probably not sufficiently untied. If you use this to determine where to send debug output, for example, the best approach would be to use cout or cerr, and let the application using the library deal with redirecting the stream to where it wants it.
Kevin loney
source share