home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- // RIPTRAP.C
- //
- // This module contains a TESTDRVR trap. It installs a notification
- // callback function using the TOOLHELP.DLL 'NotifyRegister' function.
- // and invokes the TESTDRVR Trap Dispatcher if a RIP occurs.
- //
- //---------------------------------------------------------------------------
-
- #include <string.h>
- #include <windows.h>
- #include <toolhelp.h>
-
- void FAR PASCAL log(LPSTR Message, int flag);
-
-
- HANDLE hInst; // Module-instance handle (dll)
- int RIPTrapID; // Trap ID
- void (far pascal *TrapDispatcher)(int) = NULL; // The WTD Trap Dispathcher
- BOOL fRegResult ; // Results of Register/UnRegister.
- HANDLE hTask;
- LPFNNOTIFYCALLBACK lpfnCallback; // Pointer to the callback function.
- NFYRIP RIPInfo; // Record of RIP information.
- int hFile, result;
- int RIPFlag = 0;
- int NumCalls = 0;
- int StrWaiting = FALSE;
- char OutStrBuffer[215];
-
-
-
- //---------------------------------------------------------------------------
- // RIPCallBackProc
- //
- // This is the callback function installed by the trap code. If this routine is
- // called, it is assumed that TrapDispatcher has been initialized, and calls it
- // if appropriate.
- //
- // RETURNS: Per Windows Convention (nothing)
- //---------------------------------------------------------------------------
- BOOL FAR PASCAL RIPCallBackProc (WORD wParam, DWORD lParam)
- {
-
- RIPFlag = wParam;
- NumCalls++;
-
- if (wParam == NFY_RIP){
- RIPInfo.dwSize = ((NFYRIP far *)lParam)->dwSize;
- RIPInfo.wIP = ((NFYRIP far *)lParam)->wIP;
- RIPInfo.wCS = ((NFYRIP far *)lParam)->wCS;
- RIPInfo.wSS = ((NFYRIP far *)lParam)->wSS;
- RIPInfo.wBP = ((NFYRIP far *)lParam)->wBP;
- RIPInfo.wExitCode = ((NFYRIP far *)lParam)->wExitCode;
- TrapDispatcher (RIPTrapID); // Cause the trap to occur.
- return(TRUE); // return(TRUE) means WE handle the problem.
- // The assumption is the TRAP handles.
- // The problem.
- }
-
- if (wParam == NFY_OUTSTR) {
- _fstrncpy(OutStrBuffer, (char far *)lParam, sizeof (OutStrBuffer) - 1);
- StrWaiting = TRUE;
- }
-
- return(0);
-
- }
-
-
- //---------------------------------------------------------------------------
- // RIPTrap
- //
- // This is a TESTDRVR trap installation routine.
- // It is called by TESTDRVR during the bind stage of compiling a script.
- // It installs the RIPCallBackProc which informs TESTDRVR of any RIPs
- // that occur in any application while the trap is installed.
- //
- // RETURNS: Nothing
- //---------------------------------------------------------------------------
- VOID FAR PASCAL RIPTrap (int TrapID, int Action, FARPROC TrapProc)
- {
-
- if (Action)
- if (TrapDispatcher)
- {
- return; // We've already been called and have
- // the address of the dispatcher.
- }
- else // Install the given dispatcher and Trap ID.
- {
- TrapDispatcher = TrapProc; // Save the address of the TESTDRVR
- // Trap Dispatcher.
- RIPTrapID = TrapID; // Save the ID of our TESTDRVR TRAP
- // routine.
-
- lpfnCallback = MakeProcInstance(RIPCallBackProc, hInst);
- fRegResult = NotifyRegister (0, lpfnCallback, NF_NORMAL | NF_RIP); // 0 means the current task
- }
- else
- {
- // Action=FALSE means deactivate the trap.
- //-------------------------------------------------------------------
- fRegResult = NotifyUnRegister (hTask); // NULL implies handle to current task.
- TrapDispatcher = NULL;
- RIPTrapID = NULL;
- hTask = NULL;
- }
- } // END RIPTrap()
-
-
- //---------------------------------------------------------------------------
- // LibMain
- //
- // This is the entry point to the dll.
- //
- // RETURNS: 1
- //---------------------------------------------------------------------------
- int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg,
- WORD wHeapSize, LPSTR lpCmdLine)
- {
- hInst = hInstance;
- TrapDispatcher = NULL;
- return(1);
- }
-
-
- //---------------------------------------------------------------------------
- //
- // WINDOWS EXIT PROCEDURE
- // This routine is required for all DLL's. It provides a means for cleaning
- // up prior to closing the DLL.
- //
- // CALLED ROUTINES
- // -none-
- //
- // PARAMETERS
- // WORD wParam = TRUE is system shutdown
- //
- // GLOBAL VARIABLES
- // -none-
- //
- // RETURNS
- // -none-
- //---------------------------------------------------------------------------
- void FAR PASCAL WEP(WORD wParam)
- {
- // If TESTDRVR hangs or is not able to terminate normally,
- // we have to unregister our RIP callback function here.
- if (wParam && TrapDispatcher)
- {
- fRegResult = NotifyUnRegister (hTask); // NULL implies handle to current task.
- TrapDispatcher = NULL;
- hTask = NULL;
- }
- return;
- }
-
-
-
- int FAR PASCAL GetDebugStr (LPSTR DebugStr)
- {
- if (StrWaiting == TRUE)
- {
- _fstrncpy(DebugStr, OutStrBuffer, sizeof (OutStrBuffer) - 1);
- StrWaiting = FALSE;
- return(-1);
- }
-
- else return(0);
-
- }
-
-
- // GetRIPInfo can be used by a TRAP routine to get the
- // information about the RIP retrieved in RIPCallBackProc.
- //
- int FAR PASCAL GetRIPInfo (NFYRIP far * RInfo)
- {
- RInfo->dwSize = RIPInfo.dwSize;
- RInfo->wIP = RIPInfo.wIP;
- RInfo->wCS = RIPInfo.wCS;
- RInfo->wSS = RIPInfo.wSS;
- RInfo->wBP = RIPInfo.wBP;
- RInfo->wExitCode = RIPInfo.wExitCode;
-
- return(0);
-
- }
-
-