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.

109 lines
2.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: D I A G C T X . C P P
  7. //
  8. // Contents: Implements the optional diagnostic context used by
  9. // CNetConfig.
  10. //
  11. // Notes:
  12. //
  13. // Author: shaunco 10 Feb 1999
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <pch.h>
  17. #pragma hdrstop
  18. #include "diagctx.h"
  19. CDiagContext* g_pDiagCtx;
  20. DWORD
  21. CDiagContext::Flags () const
  22. {
  23. return (this) ? m_dwFlags : 0;
  24. }
  25. VOID
  26. CDiagContext::SetFlags (
  27. DWORD dwFlags /* DIAG_FLAGS */)
  28. {
  29. Assert (this);
  30. m_dwFlags = dwFlags;
  31. if ((dwFlags & DF_SHOW_CONSOLE_OUTPUT) && !m_pCtx)
  32. {
  33. m_pCtx = (DIAG_CONTEXT*) MemAlloc (sizeof(DIAG_CONTEXT));
  34. }
  35. }
  36. #ifndef COMPILE_WITH_TYPESAFE_PRINTF
  37. VOID
  38. CDiagContext::Printf (
  39. TRACETAGID ttid,
  40. PCSTR pszFormat,
  41. ...
  42. )
  43. {
  44. va_list argList;
  45. DWORD cch;
  46. CHAR* pszPrintBuffer = NULL;
  47. INT cchPrintBuffer;
  48. Assert (pszFormat);
  49. if (this && (m_dwFlags & DF_SHOW_CONSOLE_OUTPUT) && m_pCtx)
  50. {
  51. pszPrintBuffer = m_pCtx->szPrintBuffer;
  52. cchPrintBuffer = sizeof(m_pCtx->szPrintBuffer);
  53. }
  54. else
  55. {
  56. #ifdef ENABLETRACE
  57. if (!g_TraceTags[ttid].fOutputDebugString)
  58. {
  59. return;
  60. }
  61. static CHAR szPrintfBuffer [2048];
  62. pszPrintBuffer = szPrintfBuffer;
  63. cchPrintBuffer = sizeof(szPrintfBuffer);
  64. #else
  65. return;
  66. #endif
  67. }
  68. Assert (pszPrintBuffer);
  69. // Do the standard variable argument stuff
  70. va_start (argList, pszFormat);
  71. cch = _vsnprintf (pszPrintBuffer, cchPrintBuffer, pszFormat, argList);
  72. va_end(argList);
  73. TraceTag (ttid, pszPrintBuffer);
  74. if (this && (m_dwFlags & DF_SHOW_CONSOLE_OUTPUT))
  75. {
  76. HANDLE hStdOut;
  77. hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  78. if (INVALID_HANDLE_VALUE != hStdOut)
  79. {
  80. DWORD cbWritten;
  81. if (WriteFile(hStdOut, pszPrintBuffer, cch * sizeof(CHAR), &cbWritten, NULL) == FALSE)
  82. {
  83. return;
  84. }
  85. }
  86. }
  87. }
  88. #endif