How to add ControlHandler to my main program?

P

Peter

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
 
J

Jack Klein

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.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top