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.

185 lines
4.5 KiB

  1. /*
  2. debug.c
  3. debugging menu support
  4. Debug level info is in WIN.INI in the [debug] section:
  5. [debug]
  6. App=0 level for App
  7. */
  8. #include <stdio.h>
  9. #include <windows.h>
  10. #include "PlaySnd.h"
  11. #include <stdarg.h>
  12. #ifdef MEDIA_DEBUG
  13. extern void winmmSetDebugLevel(int level);
  14. void dDbgSetDebugMenuLevel(int i)
  15. {
  16. HMENU hMenu;
  17. UINT m;
  18. if ((i < 0) || (i > 4)) i = 4;
  19. hMenu = GetMenu(ghwndMain);
  20. for (m=IDM_DEBUG0; m<=IDM_DEBUG4; m++) {
  21. CheckMenuItem(hMenu, m, MF_UNCHECKED);
  22. }
  23. CheckMenuItem(hMenu, (i + IDM_DEBUG0), MF_CHECKED);
  24. __iDebugLevel = i;
  25. dprintf3(("Debug level set to %d", i));
  26. //
  27. // set the winmm dll debug level to be the same
  28. //
  29. winmmSetDebugLevel(i);
  30. }
  31. /***************************************************************************
  32. @doc INTERNAL
  33. @api void | dDbgOut | This function sends output to the current
  34. debug output device.
  35. @parm LPSTR | lpszFormat | Pointer to a printf style format string.
  36. @parm ??? | ... | Args.
  37. @rdesc There is no return value.
  38. ****************************************************************************/
  39. void dDbgOut(LPSTR lpszFormat, ...)
  40. {
  41. int i;
  42. char buf[256];
  43. va_list va;
  44. sprintf(buf, "%s: ", szAppName);
  45. OutputDebugString(buf);
  46. va_start(va, lpszFormat);
  47. i = vsprintf(buf, lpszFormat, va);
  48. va_end(va);
  49. OutputDebugString(buf);
  50. OutputDebugString("\n");
  51. }
  52. /***************************************************************************
  53. @doc INTERNAL
  54. @api int | dDbgGetLevel | This function gets the current debug level
  55. for a module.
  56. @parm LPSTR | lpszModule | The name of the module.
  57. @rdesc The return value is the current debug level.
  58. @comm The information is kept in the [debug] section of WIN.INI
  59. ****************************************************************************/
  60. int dDbgGetLevel(LPSTR lpszAppName)
  61. {
  62. #ifdef MEDIA_DEBUG
  63. return GetProfileInt("MMDEBUG", lpszAppName, 4);
  64. #else
  65. return GetProfileInt("MMDEBUG", lpszAppName, 1);
  66. #endif
  67. }
  68. /***************************************************************************
  69. @doc INTERNAL
  70. @api int | dDbgSaveLevel | This function saves the current debug level
  71. for a module.
  72. @parm LPSTR | lpszModule | The name of the module.
  73. @parm int | iLevel | The value to save.
  74. @rdesc There is no return value.
  75. @comm The information is kept in the [debug] section of WIN.INI
  76. ****************************************************************************/
  77. void dDbgSaveLevel(LPSTR lpszAppName, int iLevel)
  78. {
  79. char buf[80];
  80. sprintf(buf, "%d", iLevel);
  81. WriteProfileString("MMDEBUG", lpszAppName, buf);
  82. }
  83. /***************************************************************************
  84. @doc INTERNAL
  85. @api void | dDbgAssert | This function shows an assert message box.
  86. @parm LPSTR | exp | Pointer to the expression string.
  87. @parm LPSTR | file | Pointer to the file name.
  88. @parm int | line | The line number.
  89. @rdesc There is no return value.
  90. @comm We try to use the current active window as the parent. If
  91. this fails we use the desktop window. The box is system
  92. modal to avoid any trouble.
  93. ****************************************************************************/
  94. void dDbgAssert(LPSTR exp, LPSTR file, int line)
  95. {
  96. char bufTmp[256];
  97. int iResponse;
  98. HWND hWnd;
  99. sprintf(bufTmp,
  100. "Expression: %s\nFile: %s, Line: %d\n\nAbort: Exit Process\nRetry: Enter Debugger\nIgnore: Continue",
  101. exp, file, line);
  102. // try to use the active window, but NULL is ok if there
  103. // isn't one.
  104. hWnd = GetActiveWindow();
  105. iResponse = MessageBox(hWnd,
  106. bufTmp,
  107. "Assertion Failure - continue?",
  108. MB_TASKMODAL
  109. | MB_ICONEXCLAMATION
  110. | MB_DEFBUTTON3
  111. | MB_OKCANCEL);
  112. switch (iResponse) {
  113. case 0:
  114. dprintf1(("Assert message box failed"));
  115. dprintf2((" Expression: %s", exp));
  116. dprintf2((" File: %s, Line: %d", file, line));
  117. break;
  118. case IDCANCEL:
  119. ExitProcess(1);
  120. break;
  121. case IDOK:
  122. break;
  123. default:
  124. dprintf1(("Assert message box failed"));
  125. dprintf2((" Expression: %s", exp));
  126. dprintf2((" File: %s, Line: %d", file, line));
  127. break;
  128. }
  129. }
  130. #endif