home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / numega / sc501.exe / data1.cab / Examples / DEBUG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  2.5 KB  |  102 lines

  1. /*
  2.  * Debug.c
  3.  * $Header: /bcsample/BUGBNCHX/MAINERR/DEBUG.C 1     5/28/96 1:11p Dave $
  4.  *
  5.  * Description:
  6.  *  Diagnostic support routines
  7.  *
  8.  * Notes:
  9.  *  Much of the implementation was taken from the Win32
  10.  *  sample, MCITEST.
  11.  *
  12.  ***********************************************************************
  13.  *
  14.  * Nu-Mega Technologies, Inc.
  15.  * P.O. Box 7780
  16.  * Nashua, NH 03060
  17.  *
  18.  * (c) Copyright 1994, 1995 Nu-Mega Technologies, Inc.
  19.  * ALL RIGHTS RESERVED.
  20.  *
  21.  ***********************************************************************
  22.  *
  23.  **********************************************************************/
  24.  
  25. #include "stdafx.h"
  26. #include <stdarg.h>
  27. #include "debug.h"
  28.  
  29. #if _DEBUG
  30.  
  31. extern LPCTSTR GetAppName ( ) ;
  32.  
  33.  
  34. // Used by the WinVerify macro when
  35. // evaluating the expression to be
  36. // verified.
  37. DWORD __dwEval;
  38.  
  39. // Sends output to the current debug output device.
  40. void dDbgOut ( LPTSTR lpszFormat, ... )
  41. {
  42.    int i ;
  43.    TCHAR buf[ 256 ] ;
  44.    va_list va ;
  45.  
  46.    i = wsprintf ( buf , _T ( "%s: " ) , GetAppName ( ) ) ;
  47.  
  48.    va_start ( va , lpszFormat ) ;
  49.    i += wvsprintf ( buf + i , lpszFormat , va ) ; 
  50.    va_end ( va ) ;
  51.  
  52.    buf[ i++ ] = _T ( '\n' ) ;
  53.    buf[ i ] = 0 ;
  54.  
  55.    OutputDebugString ( buf ) ;
  56. }
  57.  
  58. // Shows an assert message box.
  59. void dDbgAssert( LPTSTR szExp, LPTSTR szFile, int nLine)
  60. {
  61.    TCHAR bufTmp[ 256 ] ;
  62.    int iResponse ;
  63.    HWND hWnd ;
  64.  
  65.    wsprintf ( bufTmp,
  66.    _T ( "Expression: %s\nFile: %s, Line: %d\n\nAbort:  Exit Process\nRetry:  Enter Debugger\nIgnore: Continue" ) ,
  67.               szExp   , 
  68.               szFile  , 
  69.               nLine   ) ;
  70.  
  71.    // try to use the active window, but NULL is ok if there
  72.    // isn't one.
  73.    hWnd = GetActiveWindow ( ) ;
  74.  
  75.    iResponse = MessageBox ( hWnd                       ,
  76.                             bufTmp                     ,
  77.                             _T ( "Assertion Failure" ) ,
  78.                             MB_TASKMODAL
  79.                               | MB_ICONEXCLAMATION
  80.                               | MB_DEFBUTTON3
  81.                               | MB_ABORTRETRYIGNORE     ) ;
  82.  
  83.    switch ( iResponse ) 
  84.    {
  85.       case 0:
  86.          dprintf  ( ( _T ( "Assert message box failed" ) ) ) ;
  87.          dprintf1 ( ( _T ( "  Expression: %s" ) , szExp ) ) ;
  88.          dprintf2 ( ( _T ( "  File: %s,  Line: %d" ) , szFile , nLine ) ) ;
  89.          break;
  90.       case IDABORT:
  91.          ExitProcess ( 1 ) ;
  92.          break;
  93.       case IDRETRY:
  94.          DebugBreak ( ) ;
  95.          break;
  96.       case IDIGNORE:
  97.          break;
  98.    }
  99. }
  100.  
  101. #endif
  102.