Solved

Dos interrupts

Posted on 1998-01-19
8
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 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