home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / AFXASERT.CP_ / AFXASERT.CP
Encoding:
Text File  |  1993-02-08  |  2.4 KB  |  98 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 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 Microsoft 
  7. // QuickHelp and/or WinHelp 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 AFX_DBG1_SEG
  14. #pragma code_seg(AFX_DBG1_SEG)
  15. #endif
  16.  
  17. // NOTE: in separate module so it can replaced if needed
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. #ifdef _DEBUG
  25. int NEAR afxIgnoreAssertCount = 0;               // for testing diagnostics
  26. #endif
  27.  
  28. #pragma optimize("qgel", off) // assembler cannot be globally optimized
  29.  
  30. extern "C"
  31. void AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine)
  32. {
  33. #ifdef _DEBUG
  34.     if (afxIgnoreAssertCount > 0)
  35.     {
  36.         afxIgnoreAssertCount--;
  37.         return;
  38.     }
  39.  
  40. #ifdef _WINDOWS
  41.     char sz[255];
  42.     static char BASED_CODE szTitle[] = "Assertion Failed!";
  43.     static char BASED_CODE szMessage[] = "%s: File %s, Line %d";
  44.     static char BASED_CODE szUnknown[] = "<unknown application>";
  45.  
  46.     // get app name or NULL if unknown (don't call assert)
  47. #ifndef _AFXDLL
  48.     const char* pszAppName = afxCurrentAppName;
  49. #else
  50.     const char* pszAppName = _AfxGetAppData()->appCurrentAppName;
  51. #endif
  52.     wsprintf(sz, (LPCSTR)szMessage, 
  53.         (pszAppName == NULL) ? (LPCSTR)szUnknown : (LPCSTR)pszAppName,
  54.         lpszFileName, 
  55.         nLine);
  56.  
  57.     if (afxTraceEnabled)
  58.     {
  59.         // assume the debugger or auxiliary port
  60.         ::OutputDebugString(sz);
  61.         ::OutputDebugString(", ");
  62.         ::OutputDebugString(szTitle);
  63.         ::OutputDebugString("\n\r");
  64.     }
  65.  
  66. retry:
  67.     int nCode = ::MessageBox(NULL, sz, szTitle,
  68.             MB_SYSTEMMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE);
  69.     if (nCode == IDIGNORE)
  70.     {
  71.         return;     // ignore
  72.     }
  73.     else if (nCode == IDRETRY)
  74.     {
  75.         // break into the debugger (or Dr Watson log)
  76. #ifndef _PORTABLE
  77.         _asm { int 3 };
  78. #endif
  79.         goto retry;
  80.     }
  81.     // else fall through and call AfxAbort
  82.  
  83. #else
  84.     static char szMessage[] = "Assertion Failed: file %Fs, line %d\r\n";
  85.     fprintf(stderr, szMessage, lpszFileName, nLine);
  86. #endif // _WINDOWS
  87.  
  88. #else
  89.     // parameters not used if non-debug
  90.     (void)lpszFileName;
  91.     (void)nLine;
  92. #endif // _DEBUG
  93.  
  94.     AfxAbort();
  95. }
  96.  
  97. #pragma optimize("", on)
  98.