Old fashion design for PC-104
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.

107 lines
2.2 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: DebugConsole.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DebugConsole.cpp
  13. //----------------------------------------------------------------------------
  14. // DebugConsole.cpp: implementation of the CDebugConsole class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "..\LgLib\Version.h"
  19. #include "DebugConsole.h"
  20. #ifdef DEBUG_CONSOLE
  21. CDebugConsole DbgConsole(TRUE);
  22. #endif
  23. CDebugConsole::CDebugConsole( BOOL bCreate )
  24. {
  25. m_hOutputHandle = INVALID_HANDLE_VALUE;
  26. if( bCreate )
  27. Create();
  28. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDebugConsole::CDebugConsole" );
  29. }
  30. CDebugConsole::~CDebugConsole()
  31. {
  32. Destroy();
  33. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDebugConsole::~CDebugConsole" );
  34. }
  35. BOOL CDebugConsole::Create()
  36. {
  37. if( !::AllocConsole() )
  38. return FALSE;
  39. m_hOutputHandle = ::GetStdHandle( STD_OUTPUT_HANDLE );
  40. if( m_hOutputHandle == INVALID_HANDLE_VALUE )
  41. return FALSE;
  42. return TRUE;
  43. }
  44. void CDebugConsole::Destroy()
  45. {
  46. ::FreeConsole();
  47. }
  48. INT CDebugConsole::Printf( LPCTSTR pFormat, ... )
  49. {
  50. const INT MAX_PRINT_LENGTH = 1024;
  51. if( !pFormat )
  52. return FALSE;
  53. if( m_hOutputHandle == INVALID_HANDLE_VALUE )
  54. return FALSE;
  55. TCHAR pText[MAX_PRINT_LENGTH];
  56. va_list pMarker;
  57. va_start( pMarker, pFormat );
  58. INT nPrinted = _vsntprintf( pText, MAX_PRINT_LENGTH, pFormat, pMarker );
  59. va_end( pMarker );
  60. ::WriteConsole( m_hOutputHandle, pText, nPrinted, (PDWORD)&nPrinted, NULL );
  61. ::OutputDebugString( pText );
  62. return nPrinted;
  63. }
  64. INT DebugTrace( LPCTSTR pFormat, ... )
  65. {
  66. const INT MAX_PRINT_LENGTH = 1024;
  67. if( !pFormat )
  68. return FALSE;
  69. TCHAR pText[MAX_PRINT_LENGTH];
  70. va_list pMarker;
  71. va_start( pMarker, pFormat );
  72. INT nPrinted = _vsntprintf( pText, MAX_PRINT_LENGTH, pFormat, pMarker );
  73. va_end( pMarker );
  74. ::OutputDebugString( pText );
  75. return nPrinted;
  76. }