Masking CTRL-ALT-DEL and ^C Interrupts

This is a discussion on Masking CTRL-ALT-DEL and ^C Interrupts within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Hi, I was just wondering how to mask the interrupts for CTRL-ALT-DEL and ^C for a DOS BOX under windows? ...

  1. #1
    Unregistered
    Guest

    Question Masking CTRL-ALT-DEL and ^C Interrupts

    Hi, I was just wondering how to mask the interrupts for CTRL-ALT-DEL and ^C for a DOS BOX under windows?

    Thanks =)

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    The only one that uses an interrupt is break. The best way to trap for these is to write a keyboard handler. There are several posts on this board related to this topic so I'll not write reams of text here. Check the board as this topic is all over it multiple times in multiple places.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I misled you a bit with my info. For Ctrl^C just write an int23h interrupt handler either in asm or C.


    Code:
    //Use (...) for C++ and (void) for C.
    
    void interrupt (*oldbreakhandler)(...)=NULL;
    
    
    void interrupt breakhandler(...)
    {
       //Do something
       //You can just disable this by putting nothing here
       //This would translate to an IRET in asm
       //Turning off CTRL-C, though, is probably not what you want
       //to do while building your code.
       
       //Example:
       //Uninstall any other int handlers we have installed
       //Free memory
       uninstallbreakhandler();
       oldbreakhandler();   //Pass the int onto the orig int 23h handler
       
       //Will terminate, but cleans up prior to terminating
    }
    
    void installbreakhandler(void)
    {
      disable();  
      //Save old handler
      oldbreakhandler=getvect(0x23);
      //Install our handler
      setvect(0x23,breakhandler);
      enable();
    }
    
    void uninstallbreakhandler(void)
    {
       //Restore the int vector table
       disable();
       setvect(0x23,oldbreakhandler);
       enable();
    }

    DOS does not restore the int vector table if you have patched interrupts and pressed CTRL-C midway in your program. This thrashes the interrupt chain for the vectors you have patched. You would have to reboot to run your code again. The above method will allow you to press CTRL-C for debugging and will properly restore the int vector table so you can run your code again w/o having to reboot.

    In a commercial build you would probably just put an IRET in the int23h handler. You will also want to patch int24h which is DOS's Critical Error Handler - not very friendly at all. Your version should help the user determine what the heck happened and why DOS failed or a DOS call failed.

  4. #4
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    857
    Ctrl + C's ASCI code is 3

    As for the Invincible breakout... You can't in Windows because it will bring up the close prog dialog.
    Yoshi

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    This is for DOS, since this is the DOS programming board.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21