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.

108 lines
2.1 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. VOID
  37. CDiagContext::Printf (
  38. TRACETAGID ttid,
  39. PCSTR pszFormat,
  40. ...
  41. )
  42. {
  43. va_list argList;
  44. DWORD cch;
  45. CHAR* pszPrintBuffer = NULL;
  46. INT cchPrintBuffer;
  47. Assert (pszFormat);
  48. if (this && (m_dwFlags & DF_SHOW_CONSOLE_OUTPUT) && m_pCtx)
  49. {
  50. pszPrintBuffer = m_pCtx->szPrintBuffer;
  51. cchPrintBuffer = sizeof(m_pCtx->szPrintBuffer);
  52. }
  53. else
  54. {
  55. #ifdef ENABLETRACE
  56. if (!g_TraceTags[ttid].fOutputDebugString)
  57. {
  58. return;
  59. }
  60. static CHAR szPrintfBuffer [2048];
  61. pszPrintBuffer = szPrintfBuffer;
  62. cchPrintBuffer = sizeof(szPrintfBuffer);
  63. #else
  64. return;
  65. #endif
  66. }
  67. Assert (pszPrintBuffer);
  68. // Do the standard variable argument stuff
  69. va_start (argList, pszFormat);
  70. cch = _vsnprintf (pszPrintBuffer, cchPrintBuffer, pszFormat, argList);
  71. va_end(argList);
  72. TraceTag (ttid, pszPrintBuffer);
  73. if (this && (m_dwFlags & DF_SHOW_CONSOLE_OUTPUT))
  74. {
  75. HANDLE hStdOut;
  76. hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  77. if (INVALID_HANDLE_VALUE != hStdOut)
  78. {
  79. DWORD cbWritten;
  80. if (WriteFile(hStdOut, pszPrintBuffer, cch * sizeof(CHAR), &cbWritten, NULL) == FALSE)
  81. {
  82. return;
  83. }
  84. }
  85. }
  86. }