Hello Christopher.
06 Nov 97 16:41, Christopher Butler wrote to All:
CB> How do I get the address of a member function?
Looking for this?
=== Start cpp_isr.txt ===
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;
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()
{
int key = 0;
ISR myPrintISR( 5 );
ISR::curISR = &myPrintISR;
printf( "Hit ESC to terminate or PrintScreen to trigger\n" );
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
ot the terms of the No-Nonsense License Statement that you received with
the Borland product to which this information pertains.
=== End cpp_isr.txt ===
Don
... IBM: I Blame Microsoft
---
---------------
* Origin: Extreme Impossibility/2 [Kingston, Ontario, Canada] (1:249/176)
|