Click here to Skip to main content
12,502,104 members (52,327 online)
Click here to Skip to main content

Stats

74.3K views
1.8K downloads
170 bookmarked
Posted

ProSysLib: Dissecting the Process

, 22 Nov 2010 CPOL
Access detailed information about the current process the easiest way.
ProcessInfo.exe
ProSysLib.dll
Interop.ProSysLib.dll
Interop.ProSysLib.dll
ProcessInfo.exe
ProSysLib.dll
PSL64v0.9.dll
Interop.ProSysLib.dll
ProcessInfo.exe
PSL32v0.9.dll
ProSysLib_v0.9
Bin
PSL32v0.9.dll
PSL64v0.9.dll
Help
Samples
C#2008
ProcessInfo
Properties
ProcessViewer
Properties
VB6
CPUInfo.exe
CPUInfo.frm
CPUInfo.frx
CPUInfo.vbp
CPUInfo.vbw
VC2008
Deployment
Src
mssccprj.scc
ProSysLib.def
ProSysLib.rgs
ProSysLib.vcproj.vspscc
ProSysLib.vssscc
PSLSystem.rgs
PSLv0.5Setup.exe
PSLv0.7Setup.exe
// PSLTable.cpp : Implementation of CPSLTable

#include "stdafx.h"
#include "PSLTable.h"

CPSLTable::CPSLTable()
{
	m_nCols = 0;
	m_nRows = 0;
}

HRESULT CPSLTable::FinalConstruct()
{
	return S_OK;
}

void CPSLTable::FinalRelease()
{
}

bool CPSLTable::Initialize(IWbemClassObject * pClassObject, long & lErrorCode, vector<tstring> * pColFilter, bool bSpecial)
{
	m_nCols = 0;
	SAFEARRAY * pArray = NULL;
	long lFlags = WBEM_FLAG_ALWAYS|WBEM_FLAG_NONSYSTEM_ONLY;
	if(bSpecial)
		lFlags = WBEM_FLAG_ALWAYS;
	lErrorCode = pClassObject->GetNames(NULL, lFlags, NULL, &pArray);
	bool bResult = false;
	vector<tstring> names;
	if(lErrorCode == WBEM_S_NO_ERROR)
	{
		long nElements;	// Number of elements in the array;
		lErrorCode = ::SafeArrayGetUBound(pArray, 1, &nElements);
		if(lErrorCode == S_OK)
		{
			bResult = true;
			long nCols = nElements + 1;
			BSTR sName = NULL;
			long Idx = 0;
			for(long i = 0;i < nCols;i ++)
			{
				lErrorCode = ::SafeArrayGetElement(pArray, &i, &sName);
				if(lErrorCode == S_OK)
				{
					if(pColFilter)
						names.push_back(sName);
					else
					{
						m_ColumnNames.insert(pair<long, _bstr_t>(Idx ++, sName));
						m_nCols ++;
					}

					::SysFreeString(sName);
					bResult = true;
				}
				else
				{
					bResult = false;
					break;
				}
			}
		}
		::SafeArrayDestroy(pArray);
	}

	if(bResult && pColFilter)
	{
		long Idx = 0;
		for(vector<tstring>::iterator i = pColFilter->begin();i != pColFilter->end(); i++)
			for(vector<tstring>::iterator k = names.begin();k != names.end(); k++)
				if(!_tcsicmp(i->c_str(), k->c_str()))
				{
					m_ColumnNames.insert(pair<long, _bstr_t>(Idx ++, k->c_str()));
					m_nCols ++;
					break;
				}
	}

	return bResult;
}

bool CPSLTable::AddRow(IWbemClassObject * pClassObject, long & lErrorCode)
{
	long Idx = 0;
	for(CColumnNames::const_iterator i = m_ColumnNames.begin();i != m_ColumnNames.end();i ++)
	{
		_variant_t v;
		lErrorCode = pClassObject->Get(i->second, 0, &v, 0, 0);
		if(lErrorCode != S_OK)
			return false;

		m_ColumnValues.insert(pair<long, _variant_t>(m_nRows * m_nCols + Idx, v));
		Idx ++;
	}
	m_nRows ++;
	return true;
}

////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////

STDMETHODIMP CPSLTable::get_nCols(long * pValue)
{
	PSL_BEGIN

	*pValue = m_nCols;

	PSL_END
}

STDMETHODIMP CPSLTable::get_nRows(long * pValue)
{
	PSL_BEGIN

	*pValue = m_nRows;

	PSL_END
}

STDMETHODIMP CPSLTable::GetValue(long RowIdx, long ColIdx, VARIANT * pValue)
{
	PSL_BEGIN

	if(RowIdx > m_nRows || ColIdx > m_nCols)
		SetException(exIndexOutOfRange);
	else
	{
		CColumnValues::const_iterator i = m_ColumnValues.find(RowIdx * m_nCols + ColIdx);
		if(i == m_ColumnValues.end())
			SetException(exGeneric);
		else
			::VariantCopy(pValue, &i->second);
	}

	PSL_END
}

STDMETHODIMP CPSLTable::GetColName(long ColIdx, BSTR * pValue)
{
	PSL_BEGIN

	if(ColIdx > m_nCols)
		SetException(exIndexOutOfRange);
	else
	{
		CColumnNames::const_iterator i = m_ColumnNames.find(ColIdx);
		if(i == m_ColumnNames.end())
			SetException(exGeneric);
		else
			*pValue = i->second.copy();
	}

	PSL_END
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Vitaly Tomilov
Software Developer (Senior) Sibedge IT
Ireland Ireland
My online CV: cv.vitalytomilov.com

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160919.1 | Last Updated 22 Nov 2010
Article Copyright 2008 by Vitaly Tomilov
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid