Thread: End Program on shutdown/logoff

  1. #1
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001

    End Program on shutdown/logoff

    I have a program in a windows 2k environment that continually listens on a port using winsock, it works fine except that when the user logs off or shutsdown the computer, I get that "End Program Now" window because the program is still listening for connections.

    My question is, How can I avoid this message without having the end-users close my program manually ?

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    in win32 applications, i think that when the OS wants to close a program, it sends a WM_CLOSE or a WM_DESTROY message (not sure exactly which one, if either)

    It sounds like you're constantly listening without jumping back to process win32 messages? assuming that you aren't, I'd suggest that you make sure to jump back to handle any win32 messages every now and then.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    If a console application use SetConsoleCtrlHandler().

    If not handle the WM_QUERYENDSESSION or WM_ENDSESSION messages. If you are blocking on a function call you will need to run a message loop on another thread to catch these(or any other) messages.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-05-2009, 11:32 AM
  2. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Cant figure out how to end my program
    By Summonerur in forum C Programming
    Replies: 9
    Last Post: 10-11-2004, 10:53 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM