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.

175 lines
3.1 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1999 - 1999
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. Common code for debugging.
  7. Author:
  8. Keisuke Tsuchida (KeisukeT)
  9. Environment:
  10. uesr mode only
  11. Notes:
  12. Revision History:
  13. --*/
  14. //
  15. // Precompiled header
  16. //
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. //
  20. // Includes
  21. //
  22. #include "stddef.h"
  23. #include "debug.h"
  24. #include <stiregi.h>
  25. //
  26. // Globals
  27. //
  28. ULONG DebugTraceLevel = MIN_TRACE | DEBUG_FLAG_DISABLE;
  29. //ULONG DebugTraceLevel = MAX_TRACE | DEBUG_FLAG_DISABLE | TRACE_PROC_ENTER | TRACE_PROC_LEAVE;
  30. TCHAR acErrorBuffer[MAX_TEMPBUF];
  31. //
  32. // Function
  33. //
  34. VOID
  35. MyDebugInit()
  36. /*++
  37. Routine Description:
  38. Read DebugTraceLevel key from registry if exists.
  39. Arguments:
  40. none.
  41. Return Value:
  42. none.
  43. --*/
  44. {
  45. HKEY hkRegistry;
  46. LONG Err;
  47. DWORD dwType;
  48. DWORD dwSize;
  49. ULONG ulBuffer;
  50. DebugTrace(TRACE_PROC_ENTER,("MyDebugInit: Enter... \r\n"));
  51. //
  52. // Initialize local variables.
  53. //
  54. hkRegistry = NULL;
  55. Err = 0;
  56. dwSize = sizeof(ulBuffer);
  57. //
  58. // Open registry key.
  59. //
  60. Err = RegOpenKey(HKEY_LOCAL_MACHINE,
  61. REGSTR_PATH_STICONTROL_W,
  62. &hkRegistry);
  63. if(ERROR_SUCCESS != Err){
  64. DebugTrace(TRACE_STATUS,("MyDebugInit: Can't open %ws. Err=0x%x.\r\n", REGSTR_PATH_STICONTROL_W, Err));
  65. goto MyDebugInit_return;
  66. }
  67. Err = RegQueryValueEx(hkRegistry,
  68. REGVAL_DEBUGLEVEL,
  69. NULL,
  70. &dwType,
  71. (LPBYTE)&ulBuffer,
  72. &dwSize);
  73. if(ERROR_SUCCESS != Err){
  74. DebugTrace(TRACE_STATUS,("MyDebugInit: Can't get %ws\\%ws value. Err=0x%x.\r\n", REGSTR_PATH_STICONTROL_W, REGVAL_DEBUGLEVEL, Err));
  75. goto MyDebugInit_return;
  76. }
  77. DebugTraceLevel = ulBuffer;
  78. DebugTrace(TRACE_CRITICAL, ("MyDebugInit: Reg-key found. DebugTraceLevel=0x%x.\r\n", DebugTraceLevel));
  79. MyDebugInit_return:
  80. //
  81. // Clean up.
  82. //
  83. if(NULL != hkRegistry){
  84. RegCloseKey(hkRegistry);
  85. }
  86. DebugTrace(TRACE_PROC_LEAVE,("MyDebugInit: Leaving... Ret=VOID.\r\n"));
  87. return;
  88. }
  89. void __cdecl
  90. DbgPrint(
  91. LPSTR lpstrMessage,
  92. ...
  93. )
  94. {
  95. va_list list;
  96. va_start(list,lpstrMessage);
  97. wvsprintfA((LPSTR)acErrorBuffer, lpstrMessage, list);
  98. if(DebugTraceLevel & TRACE_MESSAGEBOX){
  99. MessageBoxA(NULL, (LPSTR)acErrorBuffer, "", MB_OK);
  100. }
  101. #if DBG
  102. OutputDebugStringA((LPCSTR)acErrorBuffer);
  103. #endif // DBG
  104. va_end(list);
  105. }
  106. void __cdecl
  107. DbgPrint(
  108. LPWSTR lpstrMessage,
  109. ...
  110. )
  111. {
  112. va_list list;
  113. va_start(list,lpstrMessage);
  114. wvsprintfW(acErrorBuffer, lpstrMessage, list);
  115. if(DebugTraceLevel & TRACE_MESSAGEBOX){
  116. MessageBoxW(NULL, acErrorBuffer, L"", MB_OK);
  117. }
  118. #if DBG
  119. OutputDebugStringW(acErrorBuffer);
  120. #endif // DBG
  121. va_end(list);
  122. }