Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.2 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. // AssertBreak.cpp
  6. //
  7. // Purpose: AssertBreak macro definition
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #if defined(_DEBUG) || defined(DEBUG)
  12. #include <polarity.h>
  13. #include <assertbreak.h>
  14. #ifdef UTILLIB
  15. #include <cregcls.h>
  16. #endif
  17. #include <chstring.h>
  18. #include <malloc.h>
  19. #include <cnvmacros.h>
  20. ////////////////////////////////////////////////////////////////////////
  21. //
  22. // Function: assert_break
  23. //
  24. // Debug Helper function for displaying a message box
  25. //
  26. // Inputs: const char* pszReason - Reason for the failure.
  27. // const char* pszFilename - Filename
  28. // int nLine - Line Number
  29. //
  30. // Outputs: None.
  31. //
  32. // Return: None.
  33. //
  34. // Comments: None.
  35. //
  36. ////////////////////////////////////////////////////////////////////////
  37. void WINAPI assert_break( LPCWSTR pszReason, LPCWSTR pszFileName, int nLine )
  38. {
  39. DWORD t_dwFlag = 0; //
  40. #ifdef UTILLIB
  41. CRegistry t_Reg;
  42. if(t_Reg.Open(HKEY_LOCAL_MACHINE,
  43. L"SOFTWARE\\Microsoft\\WBEM\\CIMOM",
  44. KEY_READ) == ERROR_SUCCESS)
  45. {
  46. // see if we can find the flag
  47. if((t_Reg.GetCurrentKeyValue(L"IgnoreAssert", t_dwFlag) != ERROR_SUCCESS))
  48. {
  49. t_dwFlag = 0;
  50. }
  51. }
  52. #endif
  53. if (t_dwFlag == 0)
  54. {
  55. CHString strAssert;
  56. strAssert.Format( L"Assert Failed\n\n[%s:%d]\n\n%s\n\nBreak into Debugger?", pszFileName, nLine, pszReason );
  57. // Set the MB flags correctly depending on which OS we are running on, since in NT we may
  58. // be running as a System Service, in which case we need to ensure we have the
  59. // MB_SERVICE_NOTIFICATION flag on, or the message box may not actually display.
  60. DWORD dwFlags = MB_YESNO | MB_ICONSTOP;
  61. OSVERSIONINFOA OsVersionInfoA;
  62. OsVersionInfoA.dwOSVersionInfoSize = sizeof (OSVERSIONINFOA) ;
  63. GetVersionExA(&OsVersionInfoA);
  64. if ( OsVersionInfoA.dwPlatformId == VER_PLATFORM_WIN32_NT )
  65. {
  66. // Flag changed between OS's (sigh)
  67. if ( 4 <= OsVersionInfoA.dwMajorVersion )
  68. {
  69. dwFlags |= MB_SERVICE_NOTIFICATION;
  70. }
  71. else
  72. {
  73. dwFlags |= MB_SERVICE_NOTIFICATION_NT3X;
  74. }
  75. }
  76. // Now display the message box.
  77. int iRet;
  78. if (OsVersionInfoA.dwPlatformId == VER_PLATFORM_WIN32_NT)
  79. {
  80. iRet = MessageBoxW( NULL, strAssert, L"Assertion Failed!", dwFlags);
  81. }
  82. else
  83. {
  84. bool t_ConversionFailure = false ;
  85. char *szAssert = NULL ;
  86. WCSTOANSISTRING(strAssert, szAssert, t_ConversionFailure );
  87. if ( ! t_ConversionFailure )
  88. {
  89. if ( szAssert )
  90. {
  91. iRet = MessageBoxA( NULL, szAssert, "Assertion Failed!", dwFlags);
  92. }
  93. }
  94. }
  95. if (iRet == IDYES)
  96. {
  97. DebugBreak();
  98. }
  99. }
  100. }
  101. #endif