Solved

Dos interrupts

Posted on 1998-01-19
8
373 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

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

Thanks,
Tom
0
 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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