home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK10 / MFC / SRC / ASSERT.CP$ / assert
Encoding:
Text File  |  1992-03-07  |  2.0 KB  |  85 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 documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11. #ifdef _WINDOWS
  12. #include "afxwin.h"
  13. #else
  14. #include "afx.h"
  15. #endif
  16. #pragma hdrstop
  17.  
  18. #ifdef AFX_CORE_SEG
  19. #pragma code_seg(AFX_CORE_SEG)
  20. #endif
  21.  
  22.  
  23. /*
  24.  *  NOTE: in separate module so it can replaced if needed
  25.  */
  26.  
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. #ifdef _DEBUG
  33. int afxIgnoreAssertCount = 0;               // for testing diagnostics
  34. #endif
  35.  
  36. #pragma optimize("q", off)
  37.  
  38. extern "C"
  39. void PASCAL AfxAssertFailedLine(const char FAR* lpszFileName, int nLine)
  40. {
  41. #ifdef _DEBUG
  42.     if (afxIgnoreAssertCount > 0)
  43.     {
  44.         afxIgnoreAssertCount--;
  45.         return;
  46.     }
  47.  
  48. #ifdef _WINDOWS
  49.     char sz[255];
  50.     static char BASED_CODE szTitle[] = "Assertion Failed!";
  51.     static char BASED_CODE szMessage[] = "%s: File %s, Line %d";
  52.     static char BASED_CODE szUnknown[] = "<unknown application>";
  53.  
  54.     wsprintf(sz, (LPCSTR)szMessage, 
  55.         AfxGetApp() == NULL ? (LPCSTR)szUnknown : (LPCSTR)AfxGetAppName(), 
  56.         lpszFileName, 
  57.         nLine);
  58.  
  59.     if (afxTraceEnabled)
  60.     {
  61.         // assume the debugger or auxiliary port
  62.         ::OutputDebugString(szTitle);
  63.         ::OutputDebugString("\n\r");
  64.         ::OutputDebugString(sz);
  65.         ::OutputDebugString("\n\r");
  66.         _asm { int 3 };
  67.     }
  68.  
  69.     ::MessageBox(NULL, sz, szTitle, MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
  70. #else
  71.     static char szMessage[] = "Assertion Failed: file %Fs, line %d\r\n";
  72.     fprintf(stderr, szMessage, lpszFileName, nLine);
  73. #endif // _WINDOWS
  74.  
  75. #else
  76.     // parameters not used if non-debug
  77.     (void)lpszFileName;
  78.     (void)nLine;
  79. #endif // _DEBUG
  80.  
  81.     AfxAbort();
  82. }
  83.  
  84. #pragma optimize("", on)
  85.