Solved

Dos interrupts

Posted on 1998-01-19
8
369 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

24 Experts available now in Live!

Get 1:1 Help Now