Topic: interrupts - help required


Author: csf029@cch.coventry.ac.uk (R.P. Bonnett)
Date: 13 Mar 92 17:59:17 GMT
Raw View
Problem - I am writing a MS-Windows V3.0 application in Borland C++ (V3.0).
I require my application to monitor and react to ALL disk file activity
from all other applications running in the windows environment (including
and DOS command box's running). To do this I am trying to trap the DOS
21hex interrupt handler (where all file activity passes through) although
I am having some problems. I am unable to setup an interrupt under a dos box
(still under windows) that dosn't crash the whole system, however when the
same routine is run as windows application the program runs fine without
any problems, but does not react to the desired file activity and therefore
I assume has not installed the interrupt handler.

Can anyone help. Can I set up interrupt under windows in this way and would
they give me the desired results or does anyone know of an easier way of
obtaining the same result - to trap all file activite for all applications.
If an interrupt is the only way of performing this then can anyone advise
me on how to program this (using Borland C++ V3.0). Can I setup windows
interrupts when windows is running or do I have to do this before windows
starts to run, or does windows reset/set up its own interrupts when it start
up.

Below is the code I am trying to run.
Any help would be appreciated.

Thank you

          -------------------------------------------------------

#include <dos.h>
#include <iostream.h>

#define INTR 0x21
#define LEN_STRING 80

int flag;

void interrupt _FAR (*oldhandler) ( ... );

void interrupt _FAR newHandler( unsigned bp, unsigned di, unsigned si,
    unsigned ds, unsigned es, unsigned dx,
    unsigned cx, unsigned bx, unsigned ax,
    unsigned ip, unsigned cs, unsigned flags, ...)
{
 _enable();


 flag = 1;  // to tell main program that handler
    // has been executed.

    // then call original handler
 oldhandler(bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, flags);
}

void main(void)
{
 int count = 0;
 char temp[LEN_STRING];
 cin.width(LEN_STRING);
 flag = 0;

 oldhandler = getvect(INTR);
 cout << "new version - saved old handler" << endl;
 cin >> temp;                // dummy read to control program execution

 setvect(INTR,(void interrupt _FAR (*)( ... )) newHandler);
 cout << "set up new handler" << endl;
 cin >> temp;                // dummy read to control program execution

 cout << "looping - forever" << endl;

 while(1) { // loop forever

  cout << count << " - accepting dummy data....";
  count++;
  cin >> temp;   // dummy read to allow windows to task switch.

  if (flag == 1)
  {
   cout << "flag has been set" << endl;
   flag = 0;
  }

 }

}




--

  From Richard B.
   (csf029)