Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

ProSysLib: Dissecting the Process

, 22 Nov 2010 CPOL
Access detailed information about the current process the easiest way.
ProcessInfo32_bin.zip
ProcessInfo.exe
ProSysLib.dll
Interop.ProSysLib.dll
ProcessInfo64_bin.zip
Interop.ProSysLib.dll
ProcessInfo.exe
ProSysLib.dll
ProcessInfo_bin.zip
PSL64v0.9.dll
Interop.ProSysLib.dll
ProcessInfo.exe
PSL32v0.9.dll
ProSysLib_v0.9.zip
ProSysLib_v0.9
Bin
PSL32v0.9.dll
PSL64v0.9.dll
Help
Samples
C#2008
ProcessInfo
Properties
Settings.settings
ProcessViewer
Properties
Settings.settings
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.zip
PSLv0.5Setup.exe
PSLv0.7Setup.zip
PSLv0.7Setup.exe
// PSLWindowsFilter.cpp : Implementation of CPSLWindowsFilter

#include "stdafx.h"
#include "PSLWindowsFilter.h"

CPSLWindowsFilter::CWindowsFilter::CWindowsFilter()
{
	TopLevel = ffAny;
	HasText = ffAny;
	Visible = ffAny;
	Enabled = ffAny;
	ThreadID = 0;
	ParentWnd = NULL;
}

bool CPSLWindowsFilter::CWindowsFilter::Reset()
{
	if(TopLevel != ffAny || HasText != ffAny || Visible != ffAny || Enabled != ffAny || ThreadID || ParentWnd)
	{
		TopLevel = ffAny;
		HasText = ffAny;
		Visible = ffAny;
		Enabled = ffAny;
		ThreadID = 0;
		ParentWnd = NULL;
		return true;
	}
	return false;
}


/////////////////////////////////////////////////////////
// Implementation of class CPSLWindowsFilter
/////////////////////////////////////////////////////////


CPSLWindowsFilter::CPSLWindowsFilter()
{
	::InitializeCriticalSection(&m_cs);
	m_bLocalProcess = true; // Using filter for the current process by default;
	Reset();
	m_bDirty = true;
}

CPSLWindowsFilter::~CPSLWindowsFilter()
{
	::DeleteCriticalSection(&m_cs);
}

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

void CPSLWindowsFilter::FinalRelease()
{
}

bool CPSLWindowsFilter::CheckDirtyAndReset(CWindowsFilter * pFilter)
{
	CCritSecLock lock(m_cs);
	bool bDirty = m_bDirty;
	m_bDirty = false;
	*pFilter = m_Filter;
	return bDirty;
}

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

STDMETHODIMP CPSLWindowsFilter::get_TopLevel(PSLFilterFlag * pValue)
{
	PSL_BEGIN

	CCritSecLock lock(m_cs);
	*pValue = m_Filter.TopLevel;
	
	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::put_TopLevel(PSLFilterFlag newValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	if(m_Filter.TopLevel != newValue)
	{
		m_Filter.TopLevel = newValue;
		m_bDirty = true;
	}

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::get_HasText(PSLFilterFlag * pValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	*pValue = m_Filter.HasText;

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::put_HasText(PSLFilterFlag newValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	if(m_Filter.HasText != newValue)
	{
		m_Filter.HasText = newValue;
		m_bDirty = true;
	}

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::get_Visible(PSLFilterFlag * pValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	*pValue = m_Filter.Visible;

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::put_Visible(PSLFilterFlag newValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	if(m_Filter.Visible != newValue)
	{
		m_Filter.Visible = newValue;
		m_bDirty = true;
	}

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::get_Enabled(PSLFilterFlag * pValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	*pValue = m_Filter.Enabled;

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::put_Enabled(PSLFilterFlag newValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	if(m_Filter.Enabled != newValue)
	{
		m_Filter.Enabled = newValue;
		m_bDirty = true;
	}

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::get_ThreadID(long * pValue)
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	*pValue = m_Filter.ThreadID;

	PSL_END
}


STDMETHODIMP CPSLWindowsFilter::put_ThreadID(long newValue)
{
	PSL_BEGIN
	
	if(newValue)
	{
		HANDLE hThread = ::OpenThread(THREAD_ALL_ACCESS, FALSE, newValue);
		if(hThread)
			::CloseHandle(hThread);
		else
		{
			// Either invalid thread ID, or the thread
			// doesn't belong to the current process;
			return MakeException(exInvalidParameter);
		}
	}
	CCritSecLock lock(m_cs);
	if(m_Filter.ThreadID != newValue)
	{
		m_Filter.ThreadID = newValue;
		m_bDirty = true;
	}

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::get_ParentHandle(VARIANT * pValue)
{
	PSL_BEGIN

	CCritSecLock lock(m_cs);
	CPSLUtilities::SetVariantBig(pValue, (ABIG)m_Filter.ParentWnd);

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::put_ParentHandle(VARIANT newValue)
{
	PSL_BEGIN

	bool bError = false;
	HWND hWnd = (HWND)CPSLUtilities::GetVariantBig(&newValue, &bError);
	if(bError)
		return MakeException(exInvalidParameter);

	if(hWnd)
	{
		if(::IsWindow(hWnd))
		{
			if(m_bLocalProcess)
			{
				// This means we can only set window handle
				// that belongs to the current process here!

				DWORD dwProcessID = 0;
				::GetWindowThreadProcessId(hWnd, &dwProcessID);
				if(::GetCurrentProcessId() != dwProcessID)
					return MakeException(exInvalidParameter);
			}
		}
		else
			return MakeException(exInvalidParameter);
	}

	CCritSecLock lock(m_cs);
	if(m_Filter.ParentWnd != hWnd)
	{
		m_Filter.ParentWnd = hWnd;
		m_bDirty = true;
	}

	PSL_END
}

STDMETHODIMP CPSLWindowsFilter::Reset()
{
	PSL_BEGIN
	
	CCritSecLock lock(m_cs);
	m_bDirty = m_Filter.Reset();

	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

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 22 Nov 2010
Article Copyright 2008 by Vitaly Tomilov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid