Solved

Dos interrupts

Posted on 1998-01-19
8
370 Views
Last Modified: 2013-12-03
I am on an NT 4SP3 computer and I am writing a console app.  I am porting this app from UNIX.  My unix program catches interrupts.  How do I catch interrupts for a comand Prompt app?  What are the interrupts that get sent to the system for a "Ctrl-C", closing the window with the app active, and killing the app through the NT task-manager?

Thanks
0
Comment
Question by:tvandegr
  • 4
  • 4
8 Comments
 
LVL 5

Accepted Solution

by:
inter earned 100 total points
ID: 1410139
Dear tvandegr,
You should use the "SetConsoleCtrlHandler" together with "HandlerRoutine" function to examine and process the following events:

CTRL_C_EVENT      A CTRL+C signal was received, either from keyboard input or from a signal generated by the GenerateConsoleCtrlEvent function.
CTRL_BREAK_EVENT      A CTRL+BREAK signal was received, either from keyboard input or from a signal generated by GenerateConsoleCtrlEvent.
CTRL_CLOSE_EVENT      A signal that the system sends to all processes attached to a console when the user closes the console (either by choosing the Close command from the console window's System menu, or by choosing the End Task command from the Task List).
CTRL_LOGOFF_EVENT      A signal that the system sends to all console processes when a user is logging off. This signal does not indicate which user is logging off, so no assumptions can be made.
CTRL_SHUTDOWN_EVENT      A signal that the system sends to all console processes when the system is shutting down.

So, you can ask user to terminate or continue etc.
If you need more info let me know.

But if you require other kind of hardware interrupts, the work is hard and requires DDK(device driver kit) programming, because NT does not allow us to direcly examine and manupulate ports. However we may have change for some interrupts with direct driver control routines DeviceIOCtls function.

Sincerely,
Igor



0
 

Author Comment

by:tvandegr
ID: 1410140
Thanks,
That is the information that I needed.  I am running into some strange behavior.  If I have a thread started then kill the thread, from within the thread, then call EndProcess from the Handler it brings my system to a crawl and does not free up some sockets, the main reason for the handler.  But if I have not started a thread there is no problem.  Do you have any ideas as to what might be causing it?

Thanks,
Tom  
0
 
LVL 5

Expert Comment

by:inter
ID: 1410141
Which compiler are you using friend? (I have several experieces similiar on Borland C 4.x and Delphi)
Thanks in advance :-)
Igor
0
 

Author Comment

by:tvandegr
ID: 1410142
I am using MS VC++ 5.0 with sp3.

Thanks,
Tom
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:inter
ID: 1410143
Do you use ExitThread, _endthread or TerminateThread inside the thread? also note that ExitProcess does not return until no threads are in their DLL initialization or detach routines (is also true for console apps).
Igor
0
 

Author Comment

by:tvandegr
ID: 1410144
I am using CreateThread and ExitThread.  The threads being in their dll detach routines could be a problem.  But I am waiting 2 seconds after telling my thread to die before calling ExitProcess.  Would that explain why my sockets are not getting freed, c-style sockets created with socket, bound, then freed with closesocket?

Thanks,
Tom
0
 
LVL 5

Expert Comment

by:inter
ID: 1410145
You may try to be sure of closing sockets first, using the close sockets blocking and timed mechanism. In your threads main loop by also checking for succesful close of all sockets (a semaphor may be) may help (or am I just talking silly 'cause mylocaltime 1:40 am). What do you think, is this kind of work complicates your system?
Igor
0
 

Author Comment

by:tvandegr
ID: 1410146
I tried setting the socket so linger, to make sure that the socket was closed when the call to closesocket() returned.  unfortunatly I am not able to use setsockopt() to set linger.  It return with WSAENOPROTOOPT.  I must be doing something wrong.  When I call closesocket() I get a return value of 0, so it is not getting an error.  If you have any ideas I welcome them, but I think that there is probably something I am doing someplace that is messing things up.

Thanks for all of your help.

Tom
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now