//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: DebugConsole.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of DebugConsole.cpp //---------------------------------------------------------------------------- // DebugConsole.cpp: implementation of the CDebugConsole class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "..\LgLib\Version.h" #include "DebugConsole.h" #ifdef DEBUG_CONSOLE CDebugConsole DbgConsole(TRUE); #endif CDebugConsole::CDebugConsole( BOOL bCreate ) { m_hOutputHandle = INVALID_HANDLE_VALUE; if( bCreate ) Create(); LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDebugConsole::CDebugConsole" ); } CDebugConsole::~CDebugConsole() { Destroy(); LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDebugConsole::~CDebugConsole" ); } BOOL CDebugConsole::Create() { if( !::AllocConsole() ) return FALSE; m_hOutputHandle = ::GetStdHandle( STD_OUTPUT_HANDLE ); if( m_hOutputHandle == INVALID_HANDLE_VALUE ) return FALSE; return TRUE; } void CDebugConsole::Destroy() { ::FreeConsole(); } INT CDebugConsole::Printf( LPCTSTR pFormat, ... ) { const INT MAX_PRINT_LENGTH = 1024; if( !pFormat ) return FALSE; if( m_hOutputHandle == INVALID_HANDLE_VALUE ) return FALSE; TCHAR pText[MAX_PRINT_LENGTH]; va_list pMarker; va_start( pMarker, pFormat ); INT nPrinted = _vsntprintf( pText, MAX_PRINT_LENGTH, pFormat, pMarker ); va_end( pMarker ); ::WriteConsole( m_hOutputHandle, pText, nPrinted, (PDWORD)&nPrinted, NULL ); ::OutputDebugString( pText ); return nPrinted; } INT DebugTrace( LPCTSTR pFormat, ... ) { const INT MAX_PRINT_LENGTH = 1024; if( !pFormat ) return FALSE; TCHAR pText[MAX_PRINT_LENGTH]; va_list pMarker; va_start( pMarker, pFormat ); INT nPrinted = _vsntprintf( pText, MAX_PRINT_LENGTH, pFormat, pMarker ); va_end( pMarker ); ::OutputDebugString( pText ); return nPrinted; }