Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dos interrupts

Posted on 1998-01-19
8
Medium Priority
?
381 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 400 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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