How handle exit event in a console application.

  • Thread starter Jean-Francois Hamelin
  • Start date
J

Jean-Francois Hamelin

Hi,

I have an console application, in the main when all my initializations are
done I wait for a user input to terminate the application. Since the
application is a console the user and click on the X to close the console,
when this occurs I have not able to gracefully shutdown my applications,
this part is important for my application.

Is there some event I can trap to handle this situation?

JF
 
T

Tian Min Huang

Hello,

Thanks for your post. You can handle exit event with a function registered
in SetConsoleCtrlHandler(). Please refer to the following MSDN article for
detailed information:

SetConsoleCtrlHandler
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/setconsolectrlhandler.asp

Console Event Handling
http://www.codeproject.com/win32/console_event_handling.asp

If it's a VB .NET or C# console application, you should call this native
API via P/Invoke.

Consuming Unmanaged DLL Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconConsumingUnmanagedDLLFunctions.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top