How to add ControlHandler to my main program?

Discussion in 'C++' started by Peter, Feb 14, 2004.

  1. Peter

    Peter Guest

    Hi,

    I have the following (simplified for posting) main program:
    -----------------------------------------
    int _tmain( int argc, _TCHAR* argv[] )

    {

    //Create socket listener

    SOCKET s = SetupListener(PORT);

    //Accept connections and create threads

    AcceptConnections(s);

    return 0;

    }

    ---------------------------------------



    This is the main program at server side, it's simple. What we want now is to
    add a control handler function to it, so that when user running server
    program hit ctrl-C, the server console won't show ^C at the end, but call a
    controlhandler function so that it might exit with some meaningful message
    such as "Stopping myservice ...".



    You can see my program is not a service, I wonder if there is anyway to
    attach a controlhandler function to it, if I have to call StartDispatcher
    (like service programs do), how can I do it in THE program?



    The program is implemented with VC++.



    Thanks,

    Peter
     
    Peter, Feb 14, 2004
    #1
    1. Advertising

  2. Peter

    Jack Klein Guest

    On Fri, 13 Feb 2004 18:04:20 -0800, "Peter" <> wrote in
    comp.lang.c++:

    > Hi,
    >
    > I have the following (simplified for posting) main program:
    > -----------------------------------------
    > int _tmain( int argc, _TCHAR* argv[] )
    >
    > {
    >
    > //Create socket listener
    >
    > SOCKET s = SetupListener(PORT);
    >
    > //Accept connections and create threads
    >
    > AcceptConnections(s);
    >
    > return 0;
    >
    > }


    [snip]

    You need to ask this in a Windows programming group, it has nothing at
    all to do with the C++ language and everything to do with the Windows
    API.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Feb 14, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John M
    Replies:
    1
    Views:
    1,304
    Kumar Reddi
    May 29, 2005
  2. Replies:
    1
    Views:
    544
    Andrew Thompson
    Oct 31, 2005
  3. Hal Styli
    Replies:
    14
    Views:
    1,713
    Old Wolf
    Jan 20, 2004
  4. Frederick Ding

    int main() or int main(void)?

    Frederick Ding, Dec 3, 2005, in forum: C Programming
    Replies:
    10
    Views:
    675
  5. Ravi
    Replies:
    17
    Views:
    950
    Kenneth Brody
    Apr 1, 2006
Loading...

Share This Page