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.

108 lines
2.3 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Output capturing support.
  4. //
  5. // Copyright (C) Microsoft Corporation, 2001.
  6. //
  7. //----------------------------------------------------------------------------
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. CaptureOutputCallbacks g_OutCapCb;
  11. CHAR g_CaptureBuffer[65536];
  12. CaptureOutputCallbacks::CaptureOutputCallbacks(void)
  13. {
  14. // For now just use a static buffer.
  15. m_TextBuffer = g_CaptureBuffer;
  16. m_TextBufferSize = sizeof(g_CaptureBuffer);
  17. Reset();
  18. }
  19. STDMETHODIMP
  20. CaptureOutputCallbacks::QueryInterface(
  21. THIS_
  22. IN REFIID InterfaceId,
  23. OUT PVOID* Interface
  24. )
  25. {
  26. *Interface = NULL;
  27. if (IsEqualIID(InterfaceId, IID_IUnknown) ||
  28. IsEqualIID(InterfaceId, IID_IDebugOutputCallbacks))
  29. {
  30. *Interface = (IDebugOutputCallbacks *)this;
  31. AddRef();
  32. return S_OK;
  33. }
  34. else
  35. {
  36. return E_NOINTERFACE;
  37. }
  38. }
  39. STDMETHODIMP_(ULONG)
  40. CaptureOutputCallbacks::AddRef(
  41. THIS
  42. )
  43. {
  44. // This class is designed to be static so
  45. // there's no true refcount.
  46. return 1;
  47. }
  48. STDMETHODIMP_(ULONG)
  49. CaptureOutputCallbacks::Release(
  50. THIS
  51. )
  52. {
  53. // This class is designed to be static so
  54. // there's no true refcount.
  55. return 0;
  56. }
  57. STDMETHODIMP
  58. CaptureOutputCallbacks::Output(
  59. THIS_
  60. IN ULONG Mask,
  61. IN PCSTR Text
  62. )
  63. {
  64. if (Text)
  65. {
  66. ULONG Len = strlen(Text) + 1;
  67. ULONG Space = m_TextBufferSize - (ULONG)(m_Insert - m_TextBuffer);
  68. if (Len > Space)
  69. {
  70. Len = Space;
  71. }
  72. if (Len > 0)
  73. {
  74. Len--;
  75. memcpy(m_Insert, Text, Len);
  76. m_Insert += Len;
  77. *m_Insert = 0;
  78. }
  79. }
  80. return S_OK;
  81. }
  82. HRESULT
  83. CaptureCommandOutput(PSTR Command)
  84. {
  85. HRESULT Status;
  86. PDEBUG_OUTPUT_CALLBACKS PrevCb;
  87. g_OutCapCb.Reset();
  88. g_ExtClient->GetOutputCallbacks(&PrevCb);
  89. g_ExtClient->SetOutputCallbacks(&g_OutCapCb);
  90. Status = g_ExtControl->Execute(DEBUG_OUTCTL_THIS_CLIENT, Command,
  91. DEBUG_EXECUTE_NOT_LOGGED);
  92. g_ExtClient->SetOutputCallbacks(PrevCb);
  93. return Status;
  94. }