⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qhtm_trace.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
字号:
/*----------------------------------------------------------------------
Copyright (c) 1998,1999 Gipsysoft. All Rights Reserved.
Please see the file "licence.txt" for licencing details.
File:	QHTM_Trace.cpp
Owner:	russf@gipsysoft.com
Purpose:	The bulk of this code has been taken from DebugHLP.
----------------------------------------------------------------------*/
#include "stdafx.h"

#ifdef QHTM_TRACE_ENABLED	

#include <DebugHlp.h>
#include "QHTM_Trace.h"
#include <stdio.h> 



static HANDLE g_hHeap = GetProcessHeap();

static int Startup()
{
	AllocConsole();
	return 0;
}

static int g_nDummy = Startup();

inline LPVOID GetBuffer()
{
	return HeapAlloc( g_hHeap, HEAP_ZERO_MEMORY, 512 );
}


LPVOID ReallocBuffer( LPVOID pszBuffer, int nAllocated )
{
	LPVOID pVoid = HeapReAlloc( g_hHeap, HEAP_ZERO_MEMORY, pszBuffer, nAllocated );
	if( !pVoid )
	{
		HeapFree( g_hHeap, 0, pszBuffer );
		pszBuffer = NULL;
	}
	else
	{
		pszBuffer = pVoid;
	}
	return pszBuffer;
}



LPTSTR vmalprintf( LPCTSTR pcszFormat, va_list list )
{
  bool  bSuccess = FALSE;

	LPSTR pszBuffer = reinterpret_cast<LPTSTR>( GetBuffer() );

	int nAllocated = 512;
	do
  {
		if( _vsnprintf( pszBuffer, nAllocated - 1, pcszFormat, list ) < 0 )
	  {
			nAllocated *= 2;
			pszBuffer = reinterpret_cast<LPTSTR>( ReallocBuffer( pszBuffer, nAllocated ) );
			if( !pszBuffer )
			{
				return NULL;
			}
	  }
    else
		{
      bSuccess = TRUE;
		}
  } while( !bSuccess );

	return pszBuffer;
}


void _cdecl QHTMTrace( LPCSTR pcszFormat, ... )
{
 	va_list marker;
	va_start( marker, pcszFormat );

	LPTSTR pszBuffer = vmalprintf( pcszFormat, marker );
	OutputDebugStringA( pszBuffer );
	DWORD dw;
	WriteFile( GetStdHandle( STD_OUTPUT_HANDLE ), pszBuffer, _tcslen( pszBuffer ) * sizeof( TCHAR ), &dw, NULL );
	VERIFY( HeapFree( GetProcessHeap(), 0, pszBuffer ) );

	va_end( marker );
}

#endif	//	QHTM_TRACE_ENABLED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -