473,411 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

How to add ControlHandler to my main program?

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
Jul 22 '05 #1
1 1417
On Fri, 13 Feb 2004 18:04:20 -0800, "Peter" <yb***@yahoo.com> 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/~a...FAQ-acllc.html
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
15
by: Fred Zwarts | last post by:
In C++ execution of a program starts already before execution of main(). The initialization of static variables defined outside the scope of main is performed first. I could imagine a program where...
9
by: Neelesh | last post by:
Hi all, it is strange that the following code compiles and runs (tested with g++ 3.4.2) #include <iostream> using namespace std; int main(int a, int b, int c, int d, int e) { cout <<...
12
by: Bill Cunningham | last post by:
> #include <stdlib.h> > #include <stdio.h> > > int main(int argc, char *argv) { > FILE *in, *out; > > if(argc==1) > { > in = stdin; > out = stdout;
75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
16
by: junky_fellow | last post by:
I was reading the various posts in this newsgroup, and found that main function should be declared as int main(void) // if no arguments are passed to main i wanted to know whats the purpose of...
17
by: Fred Nelson | last post by:
Hi: I'm trying to implement an overall error handler in my VB.NET windows application. I need to place an "On Error Goto" in "Sub Main". I have tried to create a Sub Main and have had no...
39
by: Ravi | last post by:
Can you all please suggest a program which tell us the range of memry addresses occupied by the given c program?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.