Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tracing to console in GUI application 2

Status
Not open for further replies.

titanandrews

Programmer
Feb 27, 2003
130
US
Hi,
In Java, even in a GUI application you can log messages to stdout, but can this be done in C++? I know I can use cout << &quot;Blah&quot;; But if you link with the /SUBSYSTEM:WINDOWS option then where does it go? I already know that I cannot use /SUBSYSTEM:CONSOLE with a GUI application. The program will crash right away. Of course, I can log to a file, but it would be nice to see my messages in the console. Does anyone know if this is possible?
 
uh, the reason you can write to a console in a Java GUI application is because the console is the actual Win32 process that is hosting the JVM that creates the Window Frame for the GUI to run in.

A normal Win32 GUI application does not use a command prompt process to host a JVM. It is a native Win32 application with a GUI thread and a Message Loop so there is no console to write to. If you want to create a Console to output to from your Win32 process you can use the Console API. I would caution you that this is highly abnormal. You can find the Console API documentation in the Platform SDK at msdn.microsoft.com

-pete
 
Very cool! I will try this OutputDebugString(). Is this something I can leave in the release version? Is there any overhead to having it there? From Platform SDK: &quot;If the application has no debugger and the system debugger is not active, OutputDebugString does nothing.&quot;


thanks,

Barry
 
In my opinion it's clever to have this in a release version of your program.
I have seen it used in BizTalk and some Trend Micro antivirus software - so I am not alone ... ;-)

There must be an overhead - but I wouldn't worry unless you log/trace extremely much.

/JOlesen
 
Well I couldn't help it. I had to make a test to see if there really was any overhead, and it looks like there is none at all! [2thumbsup] I made 10000 calls to OutputDebugString() and ran with DebugView (BTW, Very Cool Tool!) and it took an average of 8.5 seconds on my computer. Without running DebugView, it only took .30 seconds which means those function calls literally do nothing if there is nothing to intercept the traces. Or at least if they are doing something it is very insignificant. I can email my test to anyone who is interested.

regards,

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top