Determining If Your TSR Has Already Been InstalledLast reviewed: July 17, 1997Article ID: Q59884 |
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS | WINDOWSkbprg
The information in this article applies to:
SUMMARYIn Microsoft C, when writing a TSR (terminate-and-stay-resident) program, it is possible to utilize the multiplex interrupt (2fh) to determine whether your TSR has already been loaded into memory. Set up an interrupt service routine (ISR) for this interrupt that will compare the AH register with a predefined TSR number (ID#) and change the AL register to a nonzero value if the two are equal.
MORE INFORMATIONWhen using the interrupt keyword in Microsoft C, registers are pushed onto the stack before each function call. To access these register values from within an ISR, define the ISR function as accepting these registers as parameters. Once this is set up, the installation part of the TSR can make a call to the multiplex interrupt with the AH register set to the ID# of the TSR, and the AL register set to 00h. If the handler is currently installed, it will pick up these values in the AX register and then change the AL register to 01h and return this "installed" signal to the calling program. If the ID# in the AL register is not that of the TSR, the TSR can simply chain the interrupt back to its original vector. In summary, to have your TSR check to see if it is already installed, do the following:
Sample Code
#include <dos.h> void (interrupt far *original_int2fh)(); /*set to original*/ /* int2fh handler*/ #define HIBYTE(x) (((unsigned) (x) >> 8) & 0xff) #define REGPAK unsigned es, unsigned ds, unsigned di, \ unsigned si, unsigned bp, unsigned sp, \ unsigned bx, unsigned dx, unsigned cx, \ unsigned ax, unsigned ip, unsigned cs, \ unsigned flags void interrupt far new_int2fh(REGPAK){ if (HIBYTE(ax)==0xc9) /* check TSR ID# */ ax=0xc901; /* set AL to 01 */ else _chain_intr(original_int2fh); }NOTE: The keyword 'interrupt' is '__interupt' in versions 7.0 and 8.0 of the Microsoft C/C++ compiler.
|
Additional reference words: kbinf 5.10 6.00 6.00a 6.00ax 7.00 1.00 1.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |