// Global.cpp: implementation of the CGlobal class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "Global.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

void OutputDebugPrintf(LPCSTR lpszFormat, ...)
{
	char szOutput[256];
	va_list v1;
	DWORD dwSize;

	va_start(v1, lpszFormat);
	dwSize = wvsprintf(szOutput, lpszFormat, v1);

	if (szOutput[dwSize-1] != '\n')
	{
		lstrcat(szOutput, "\r\n");
	}
	OutputDebugString(szOutput);
}

void OutputDebugBinary(BYTE * pData, int iLength)
{
	CString strOutput, strChar;
	int i;

	strOutput.Format("Length = %03d", iLength);
	for (i = 0; i < iLength; i ++)
	{
		if ((i % 16) == 0)
		{
			strOutput += _T("\r\n");
			OutputDebugString(strOutput);
			strOutput = _T("");
		}
		strChar.Format("%02x ", pData[i]);
		strOutput += strChar;
	}
	strOutput += _T("\r\n");
	OutputDebugString(strOutput);
}

void OutputDebugHex(BYTE * pData, int iLength)
{
	CString strOutput, strChar;
	int i;

	strOutput.Format("Length = %03d", iLength);
	for (i = 0; i < iLength; i ++)
	{
		if ((i % 16) == 0)
		{
			strOutput += _T("\r\n");
			OutputDebugString(strOutput);
			strOutput = _T("");
		}
		strChar.Format("0x%02x, ", pData[i]);
		strOutput += strChar;
	}
	strOutput += _T("\r\n");
	OutputDebugString(strOutput);
}

void PumpMessage()
{
	MSG msg;
	while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) 
	{ 
		if (!AfxGetApp()->PumpMessage()) 
		{ 
		}
	}
	// let MFC do its idle processing
	LONG lIdle = 0;
	while (AfxGetApp()->OnIdle(lIdle++ ));  
	// Perform some background processing here using another call to OnIdle
}

