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

📄 tracker.cpp

📁 主要介绍vc++6.0的编程过程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
HRESULT FAR EXPORT CTracker::XSubDispatch::GetTypeInfoCount(UINT FAR* pctinfo)
{
	METHOD_PROLOGUE(CTracker, SubDispatch)
	return ((IDispatch*)&pThis->m_xDispatch)->GetTypeInfoCount(pctinfo);
}

HRESULT FAR EXPORT CTracker::XSubDispatch::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
{
	METHOD_PROLOGUE(CTracker, SubDispatch)
	return ((IDispatch*)&pThis->m_xDispatch)->GetTypeInfo(itinfo, lcid, pptinfo);
}

HRESULT FAR EXPORT CTracker::XSubDispatch::GetIDsOfNames(REFIID riid,
  OLECHAR FAR* FAR* rgszNames, UINT cNames, LCID lcid, DISPID FAR* rgdispid)
{
	METHOD_PROLOGUE(CTracker, SubDispatch)
	return ((IDispatch*)&pThis->m_xDispatch)->GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
}

HRESULT FAR EXPORT CTracker::XSubDispatch::Invoke(DISPID dispidMember, REFIID riid,
  LCID lcid, WORD wFlags, DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult,
  EXCEPINFO FAR* pexcepinfo, UINT FAR* puArgErr)
{
	METHOD_PROLOGUE(CTracker, SubDispatch)
	return ((IDispatch*)&pThis->m_xDispatch)->Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
}

/////////////////////////////////////////////////////////////////////////////
// CTracker interface handlers

HRESULT CTracker::XSubDispatch::get_Indent(LONG * Indent)
{
	METHOD_PROLOGUE(CTracker, SubDispatch)
	HRESULT hResult = S_OK;
	try
	{
		*Indent = pThis->GetIndent();
	}
	catch(CException * pException)
	{
		hResult = pThis->CreateErrorInfo(pException, IID_ITracker);
	}
	return hResult;
}

HRESULT CTracker::XSubDispatch::put_Indent(LONG Indent)
{
	METHOD_PROLOGUE(CTracker, SubDispatch)
	HRESULT hResult = S_OK;
	try
	{
		pThis->SetIndent(Indent);
	}
	catch(CException * pException)
	{
		hResult = pThis->CreateErrorInfo(pException, IID_ITracker);
	}
	return hResult;
}

HRESULT FAR EXPORT CTracker::XSubDispatch::OutputLines(VARIANT FAR* varOutputArray, VARIANT varIndent, VARIANT_BOOL FAR* RetVal)
{
	METHOD_PROLOGUE(CTracker, SubDispatch)
	HRESULT hResult = S_OK;
	try
	{
		*RetVal = pThis->OutputLines(varOutputArray, varIndent);
	}
	catch(CException * pException)
	{
		hResult = pThis->CreateErrorInfo(pException, IID_ITracker);
	}
	return hResult;
}

/////////////////////////////////////////////////////////////////////////////
// CTracker message handlers

BOOL CTracker::OutputLines(VARIANT FAR* varOutputArray, const VARIANT FAR& varIndent) 
{
	BOOL bResult = VARIANT_TRUE;

	// if we have a file a if the variant contains a string array
	if(m_fileLog && varOutputArray->vt == (VT_ARRAY | VT_BSTR))
	{
		// lock the array so we can use it
		if(::SafeArrayLock(varOutputArray->parray) == S_OK)
		{
			LONG lLBound;

			// get the lower bound of the array
			if(::SafeArrayGetLBound(varOutputArray->parray, 1, &lLBound) == S_OK)
			{
				LONG lUBound;

				// get the number of elements in the array
				if(::SafeArrayGetUBound(varOutputArray->parray, 1, &lUBound) == S_OK)
				{
					CString cstrIndent;
					CTime oTimeStamp;
					BSTR bstrTemp;

					// if we have an indent parameter
					if(varIndent.vt != VT_I4)
					{
						// get a variant that we can use for conversion purposes
						VARIANT varConvertedValue;

						// initialize the variant
						::VariantInit(&varConvertedValue);

						// see if we can convert the data type to something useful - VariantChangeTypeEx() could also be used
						if(S_OK == ::VariantChangeType(&varConvertedValue, (VARIANT *) &varIndent, 0, VT_I4))
							// assign the value to our member variable	
							m_lIndent = varConvertedValue.lVal;
					}
					else
						// assign the value to our member variable	
						m_lIndent = varIndent.lVal;

					// if we have to indent the text
					for(long lIndentCount = 0; lIndentCount < m_lIndent; lIndentCount++)
						// add a tab to the string
						cstrIndent += _T("\t");

					// for each of the elements in the array
					for(long lArrayCount = lLBound; lArrayCount < (lUBound + lLBound); lArrayCount++)
					{
						// update the time
						oTimeStamp = CTime::GetCurrentTime();
						m_lHiResTime = timeGetTime();

						// get the data from the array
						if(::SafeArrayGetElement(varOutputArray->parray, &lArrayCount, &bstrTemp) == S_OK)
						{
							// output the data
							fprintf(m_fileLog, _T("%s(%10ld)-%s%ls\n"), (LPCTSTR) oTimeStamp.Format("%H:%M:%S"), m_lHiResTime - m_lLastHiResTime, (LPCTSTR) cstrIndent, bstrTemp);

							// store the last timer value
							m_lLastHiResTime = m_lHiResTime;

							// free the bstr
							::SysFreeString(bstrTemp);
						}
					}
				}
				else
				{
					bResult = VARIANT_FALSE;

					// unable to get a record based on the sql statement - throw an exception
					COleDispatchException * pOleDispExcep = new COleDispatchException(_T(""), NULL, 0);

					// format the error code
					pOleDispExcep->m_scError = MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, MFCSERVER_E_NO_UBOUND);
					// set the source file
					pOleDispExcep->m_strSource = __FILE__;
					// format the error description
					pOleDispExcep->m_strDescription = _T("Unable to retrieve the upper bound dimension of the array.");

					// the function call failed cause an ole exception
					throw(pOleDispExcep);
				}
			}
			else
			{
				bResult = VARIANT_FALSE;

				// unable to get a record based on the sql statement - throw an exception
				COleDispatchException * pOleDispExcep = new COleDispatchException(_T(""), NULL, 0);

				// format the error code
				pOleDispExcep->m_scError = MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, MFCSERVER_E_NO_LBOUND);
				// set the source file
				pOleDispExcep->m_strSource = __FILE__;
				// format the error description
				pOleDispExcep->m_strDescription = _T("Unable to retrieve the lower bound dimension of the array.");

				// the function call failed cause an ole exception
				throw(pOleDispExcep);
			}

			// unlock the array we don't need it anymore
			::SafeArrayUnlock(varOutputArray->parray);
		}
		else
		{
			bResult = VARIANT_FALSE;

			// unable to get a record based on the sql statement - throw an exception
			COleDispatchException * pOleDispExcep = new COleDispatchException(_T(""), NULL, 0);

			// format the error code
			pOleDispExcep->m_scError = MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, MFCSERVER_E_NO_ARRAYLOCK);
			// set the source file
			pOleDispExcep->m_strSource = __FILE__;
			// format the error description
			pOleDispExcep->m_strDescription = _T("Unable to lock the array memory.");

			// the function call failed cause an ole exception
			throw(pOleDispExcep);
		}
	}
	else
	{
		bResult = VARIANT_FALSE;

		// unable to get a record based on the sql statement - throw an exception
		COleDispatchException * pOleDispExcep = new COleDispatchException(_T(""), NULL, 0);

		// if we didn't have a file handle
		if(!m_fileLog)
			// format the error code
			pOleDispExcep->m_scError = MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, MFCSERVER_E_NO_FILE);
		else
			// format the error code
			pOleDispExcep->m_scError = MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, MFCSERVER_E_BAD_ARRAY_PARAMETER);
		// set the source file
		pOleDispExcep->m_strSource = __FILE__;
		// if we didn't have a file handle
		if(!m_fileLog)
			// format the error description
			pOleDispExcep->m_strDescription = _T("Invalid File Handle. File could not be opened for output.");
		else
			// format the error description
			pOleDispExcep->m_strDescription = _T("The first parameter must be a string array passed by reference.");

		// the function call failed cause an ole exception
		throw(pOleDispExcep);
	}

	// return the result
	return bResult;
}

long CTracker::GetIndent() 
{
	// return the member variable
	return m_lIndent;
}

void CTracker::SetIndent(long nNewValue) 
{
	// if the new value is a least 0
	if(nNewValue >= 0)
		// assign the value to our member variable
		m_lIndent = nNewValue;
	else
	{
		// unable to get a record based on the sql statement - throw an exception
		COleDispatchException * pOleDispExcep = new COleDispatchException(_T(""), NULL, 0);

		// format the error code
		pOleDispExcep->m_scError = MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, MFCSERVER_E_INVALID_VALUE);
		// set the source file
		pOleDispExcep->m_strSource = __FILE__;
		// format the error description
		pOleDispExcep->m_strDescription = _T("Invalid value. Value must be 0 or greater.");

		// the function call failed cause an ole exception
		throw(pOleDispExcep);
	}
}

⌨️ 快捷键说明

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