PRODUCT : C++ NUMBER : 652 VERSION : All OS : PC DOS DATE : October 22, 1993 PAGE : 1/1 TITLE : Interrupt Handlers as Member Functions A static member function of a class can be used as an interrupt handler. It is not possible to use a 'regular or normal' member function as an Interrupt Handler because such functions expect a hidden parameter when called ( i.e. the 'this' pointer ) and the Intel interrupt mechanism cannot push the 'this' pointer prior to calling a handler. ( See your C++ documentation for more information about the 'this' parameter passed to member functions ). The following provides an example where a static member function is used as an interrupt handler. The class also contains a pointer to an instance of the class, therefore providing more flexibility to the handler. The only requirement is that the static pointer must be initialized to a valid instance of the class: #include #include #include _CLASSDEF( ISR ) class ISR { int intNumber; void interrupt (*oldHandler)(...); public: static PISR curISR; ISR( int ); ~ISR(); static void interrupt __handler(...); virtual void handler(); virtual void justBeep(); }; PISR ISR::curISR = NULL; PRODUCT : C++ NUMBER : 652 VERSION : All OS : PC DOS DATE : October 22, 1993 PAGE : 2/1 TITLE : Interrupt Handlers as Member Functions ISR::ISR( int iNum ) { intNumber = iNum; oldHandler = getvect( intNumber ); setvect( intNumber, (void interrupt(*)(...))__handler ); } ISR::~ISR() { setvect( intNumber, (void interrupt (*)(...))oldHandler ); curISR = NULL; } void interrupt ISR::__handler(...) { if ( curISR ) curISR->handler(); } void ISR::handler() { justBeep(); } void ISR::justBeep() { _AX = 0x0E07; geninterrupt( 0x10 ); } int main( void ) { int key = 0; ISR myPrintISR( 5 ); ISR::curISR = &myPrintISR; printf("Hit ESC to terminate or PrintScreen to trigger\n" ); PRODUCT : C++ NUMBER : 652 VERSION : All OS : PC DOS DATE : October 22, 1993 PAGE : 3/1 TITLE : Interrupt Handlers as Member Functions printf("the Interrupt 5 and listen to my Beep !\n" ); while( key != 27 ) { if ( !(key = getch()) ) key = getch(); putch( key ); } return( 0 ); } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.