home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / appwiz / logowiz / debug.cpp < prev    next >
C/C++ Source or Header  |  1998-03-05  |  2KB  |  91 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1995 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef _PSEUDO_DEBUG   // entire file
  14.  
  15. #ifdef _PSEUDO_DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. LONG AssertBusy = -1;
  21. LONG AssertReallyBusy = -1;
  22.  
  23. BOOL AssertFailedLine(LPCSTR lpszFileName, int nLine)
  24. {
  25.     TCHAR szMessage[_MAX_PATH*2];
  26.  
  27.     InterlockedDecrement(&AssertReallyBusy);
  28.  
  29.     // format message into buffer
  30.     wsprintf(szMessage, _T("File %hs, Line %d"),
  31.         lpszFileName, nLine);
  32.  
  33.     TCHAR szT[_MAX_PATH*2 + 20];
  34.     wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage);
  35.     OutputDebugString(szT);
  36.  
  37.     if (InterlockedIncrement(&AssertBusy) > 0)
  38.     {
  39.         InterlockedDecrement(&AssertBusy);
  40.  
  41.         // assert within assert (examine call stack to determine first one)
  42.         DebugBreak();
  43.         return FALSE;
  44.     }
  45.  
  46.     // active popup window for the current thread
  47.     HWND hWndParent = GetActiveWindow();
  48.     if (hWndParent != NULL)
  49.         hWndParent = GetLastActivePopup(hWndParent);
  50.  
  51.     // display the assert
  52.     int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"),
  53.         MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
  54.  
  55.     // cleanup
  56.     InterlockedDecrement(&AssertBusy);
  57.  
  58.     if (nCode == IDIGNORE)
  59.         return FALSE;   // ignore
  60.  
  61.     if (nCode == IDRETRY)
  62.         return TRUE;    // will cause DebugBreak
  63.  
  64.     AfxAbort();     // should not return (but otherwise DebugBreak)
  65.     return TRUE;
  66. }
  67.  
  68. void Trace(LPCTSTR lpszFormat, ...)
  69. {
  70.     va_list args;
  71.     va_start(args, lpszFormat);
  72.  
  73.     int nBuf;
  74.     TCHAR szBuffer[512];
  75.  
  76.     nBuf = _vstprintf(szBuffer, lpszFormat, args);
  77.     ASSERT(nBuf < (sizeof(szBuffer)/sizeof(szBuffer[0])));
  78.  
  79.     CString strMessage;
  80.  
  81.     if (AfxGetApp() != NULL)
  82.         strMessage = ((CString) (AfxGetApp()->m_pszExeName)) + _T(": ");
  83.     strMessage += szBuffer;
  84.     OutputDebugString(strMessage);
  85.  
  86.     va_end(args);
  87. }
  88.  
  89.  
  90. #endif // _PSEUDO_DEBUG
  91.