Leaked source code of windows server 2003
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.

152 lines
2.8 KiB

  1. /* File: D:\WACKER\tdll\assert.c (Created: 30-Nov-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 4 $
  7. * $Date: 4/17/02 5:13p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <stdarg.h>
  12. #include "assert.h"
  13. #include "misc.h"
  14. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  15. * FUNCTION:
  16. * DoAssertDebug
  17. *
  18. * DESCRIPTION:
  19. * Our own home-grown assert function.
  20. *
  21. * ARGUMENTS:
  22. * file - file where it happened
  23. * line - line where is happened
  24. *
  25. * RETURNS:
  26. * void
  27. *
  28. */
  29. void DoAssertDebug(TCHAR *file, int line)
  30. {
  31. #if !defined(NDEBUG)
  32. int retval;
  33. TCHAR buffer[256];
  34. wsprintf(buffer,
  35. TEXT("Assert error in file %s on line %d.\n")
  36. TEXT("Press YES to continue, NO to call CVW, CANCEL to exit.\n"),
  37. file, line);
  38. retval = MessageBox(NULL, buffer, TEXT("Assert"),
  39. MB_ICONEXCLAMATION | MB_YESNOCANCEL | MB_SETFOREGROUND);
  40. switch (retval)
  41. {
  42. case IDYES:
  43. return;
  44. case IDNO:
  45. DebugBreak();
  46. return;
  47. case IDCANCEL:
  48. mscMessageBeep(MB_ICONHAND);
  49. ExitProcess(1);
  50. break;
  51. default:
  52. break;
  53. }
  54. return;
  55. #endif
  56. }
  57. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  58. * FUNCTION:
  59. * DoDbgOutStr
  60. *
  61. * DESCRIPTION:
  62. * Used to output a string to a debug monitor. Use the macros defined
  63. * in ASSERT.H to access this function.
  64. *
  65. * ARGUMENTS:
  66. * LPTSTR achFmt - printf style format string.
  67. * ... - arguments used in formating list.
  68. *
  69. * RETURNS:
  70. * VOID
  71. *
  72. */
  73. VOID __cdecl DoDbgOutStr(TCHAR *achFmt, ...)
  74. {
  75. #if !defined(NDEBUG)
  76. va_list valist;
  77. TCHAR achBuf[256];
  78. va_start(valist, achFmt);
  79. wvsprintf(achBuf, achFmt, valist);
  80. OutputDebugString(achBuf);
  81. va_end(valist);
  82. return;
  83. #endif
  84. }
  85. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  86. * FUNCTION:
  87. * DoShowLastError
  88. *
  89. * DESCRIPTION:
  90. * Does a GetLastError() and displays it. Similar to assert.
  91. *
  92. * ARGUMENTS:
  93. * file - file where it happened
  94. * line - line where it happened
  95. *
  96. * RETURNS:
  97. * void
  98. *
  99. */
  100. void DoShowLastError(const TCHAR *file, const int line)
  101. {
  102. #if !defined(NDEBUG)
  103. int retval;
  104. TCHAR ach[256];
  105. const DWORD dwErr = GetLastError();
  106. if (dwErr == 0)
  107. return;
  108. wsprintf(ach, TEXT("GetLastError=0x%x in file %s, on line %d\n")
  109. TEXT("Press YES to continue, NO to call CVW, CANCEL to exit.\n"),
  110. dwErr, file, line);
  111. retval = MessageBox(NULL, ach, TEXT("GetLastError"),
  112. MB_ICONEXCLAMATION | MB_YESNOCANCEL | MB_SETFOREGROUND);
  113. switch (retval)
  114. {
  115. case IDYES:
  116. return;
  117. case IDNO:
  118. DebugBreak();
  119. return;
  120. case IDCANCEL:
  121. mscMessageBeep(MB_ICONHAND);
  122. ExitProcess(1);
  123. break;
  124. default:
  125. break;
  126. }
  127. return;
  128. #endif
  129. }