Click to See Complete Forum and Search --> : catch message from closing console application


bobfromb
July 16th, 2004, 11:38 AM
Hello,

I have a console application that I start from my GUI application as follows:


WinExec(page->m_PlatingMasterConsoleExe.c_str(), SW_SHOW);

The idea is to catch a message when I close the console window before it finishes (e.g. forced finish of application by user who do not wants to wait until the console reaches its end).

Is there a way to catch messages from a console application.
Any code samples are higly appreciated.

Bob

MrViggy
July 16th, 2004, 12:02 PM
Don't use 'WinExec', use 'CreateProcess' instead. Then, you can use the handle to the created process to monitor it. I believe if you do a "WaitForSingleObject" on the created proc's handle, when the wait is triggered, the process has ended (but I could be wrong; it's been a while since I played with that).

Viggy

Andreas Masur
July 16th, 2004, 05:36 PM
'WinExec()' is only provided for compatibility with 16-bit Windows and should not be used any longer...take a look at the following two FAQs which answer your questions...

How can I start a process? (http://www.codeguru.com/forum/showthread.php?t=302501)
How can I wait until a process ends ? (http://www.codeguru.com/forum/showthread.php?s=&threadid=231238)