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.

126 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbgcon.cxx
  6. Abstract:
  7. Debug Device Text Console
  8. Author:
  9. Steve Kiraly (SteveKi) 10-Dec-1995
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "dbgcon.hxx"
  15. //
  16. // Construct the console device.
  17. //
  18. TDebugDeviceConsole::
  19. TDebugDeviceConsole(
  20. IN LPCTSTR pszConfiguration,
  21. IN EDebugType eDebugType
  22. ) : TDebugDevice( pszConfiguration, eDebugType ),
  23. _bValid( FALSE ),
  24. _hOutputHandle( INVALID_HANDLE_VALUE ),
  25. _eCharType( kAnsi )
  26. {
  27. //
  28. // Get the current character type.
  29. //
  30. _eCharType = eGetCharType();
  31. //
  32. // If console allocated.
  33. //
  34. _bValid = AllocConsole();
  35. //
  36. // If valid console created.
  37. //
  38. _hOutputHandle = GetStdHandle( STD_OUTPUT_HANDLE );
  39. }
  40. //
  41. // Release the constructed console.
  42. //
  43. TDebugDeviceConsole::
  44. ~TDebugDeviceConsole(
  45. )
  46. {
  47. //
  48. // If console was alocated.
  49. //
  50. if( _hOutputHandle )
  51. {
  52. FreeConsole();
  53. }
  54. }
  55. //
  56. // Indicates object validity.
  57. //
  58. BOOL
  59. TDebugDeviceConsole::
  60. bValid(
  61. VOID
  62. )
  63. {
  64. return _hOutputHandle != NULL;
  65. }
  66. //
  67. // Output to the specified device.
  68. //
  69. BOOL
  70. TDebugDeviceConsole::
  71. bOutput (
  72. IN UINT uSize,
  73. IN LPBYTE pBuffer
  74. )
  75. {
  76. BOOL bStatus = FALSE;
  77. //
  78. // Only if console was created.
  79. //
  80. if( bValid() )
  81. {
  82. //
  83. // Adjust passed in byte cound to a character count.
  84. //
  85. if( _eCharType == kUnicode )
  86. {
  87. uSize = uSize / sizeof( WCHAR );
  88. }
  89. //
  90. // Write the specified bytes to the console.
  91. //
  92. DWORD cbWritten;
  93. bStatus = WriteConsole( _hOutputHandle,
  94. pBuffer,
  95. uSize,
  96. &cbWritten,
  97. NULL );
  98. //
  99. // Success only of the specified bytes were written.
  100. //
  101. if( !bStatus || cbWritten != uSize )
  102. {
  103. bStatus = FALSE;
  104. }
  105. }
  106. return bStatus;
  107. }