#ifndef __THREAD_MONITOR_REGISTRAR_H__
#define __THREAD_MONITOR_REGISTRAR_H__
/*********************************************************************
Copyright (C) 2003,2004 Eric Fredericksen.
These coded instructions, statements, and computer programs
are protected by Federal copyright law.
The software is free for non-commercial purposes. You may use and
distribute it for free without any restrictions except that
this notice must remain intact and be distributed with the software
in a human readable format.
This software may not be sold in any manner or in any form without
written permission from Eric Fredericksen.
THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
WARRANTY. THE AUTHOR MAKES NO REPRESENTATION OR WARRANTY OF
ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS
FITNESS FOR ANY PARTICULAR PURPOSE.
File Name: ThreadMonitorRegistrar.h
Description: tools for registering keys for use with CThreadMonitor.
Author: Eric Fredericksen
Comments:
**********************************************************************/
#include
#define _PRODUCT_ TEXT("PTTP Systems\\ThreadMonitor")
#define _VERSION_NUMBER_ TEXT("1.1")
class CThreadMonitorRegistrar : public CRegKey
{
protected:
CString m_oRegPath;
CString m_oKeyName;
enum { DELETE_NO_KEY, DELETE_KEY_RECURSIVE, DELETE_KEY_IF_EMPTY };
DWORD m_dwDeleteStrategy;
public:
LPCTSTR GetRegPath(void) { return(m_oRegPath); }
LPCTSTR GetKeyname(void) { return(m_oKeyName); }
CRegKey m_oParent;
void CreateKey( LPCTSTR _lpParentPath, LPCTSTR _pKeyName,
DWORD _dwDeleteStrategy=DELETE_KEY_RECURSIVE )
{
// open the parent key in preparation for deleting this key and its offspring
m_oRegPath.Format( _T("%s"), _lpParentPath);
m_oParent.Create(HKEY_LOCAL_MACHINE, m_oRegPath);
m_dwDeleteStrategy = _dwDeleteStrategy;
// save the key name
m_oKeyName.Format( _T("%s"), _pKeyName);
// create the key
m_oRegPath.Format( _T("%s\\%s"), _lpParentPath, _pKeyName);
Create(HKEY_LOCAL_MACHINE, m_oRegPath);
}
CThreadMonitorRegistrar(void)
{
m_dwDeleteStrategy = DELETE_NO_KEY;
m_oRegPath = "";
m_oKeyName = "";
}
virtual ~CThreadMonitorRegistrar()
{
Close();
long lResult;
switch(m_dwDeleteStrategy)
{
case DELETE_KEY_RECURSIVE:
lResult = m_oParent.RecurseDeleteKey(m_oKeyName);
break;
case DELETE_KEY_IF_EMPTY:
lResult = m_oParent.DeleteSubKey(m_oKeyName);
break;
}
}
};
class CRegisterProcess : public CThreadMonitorRegistrar
{
public:
CRegisterProcess( LPCTSTR _ptcProcessName=0)
{ Register(_ptcProcessName); }
void Register( LPCTSTR _ptcProcessName )
{
if( NULL == _ptcProcessName ) return;
CString oBaseName;
oBaseName.Format(TEXT("Software\\%s\\%s"), _PRODUCT_, _VERSION_NUMBER_);
CreateKey( oBaseName, _ptcProcessName );
}
};
class CRegisterThread : public CThreadMonitorRegistrar
{
public:
void Register(CRegisterProcess & _roProcess,
LPCTSTR _ptcThreadTagName, DWORD _dwThreadID=-1)
{
if( _dwThreadID == (DWORD)-1 ) _dwThreadID = GetCurrentThreadId();
CString oThreadID;
oThreadID.Format( TEXT("0x%X"), _dwThreadID);
CString oKeyPath;
oKeyPath.Format( TEXT("%s\\Threads"), _roProcess.GetRegPath() );
CreateKey(oKeyPath, oThreadID);
long lResult = SetStringValue(NULL, _ptcThreadTagName);
}
void SetKeyValue(CRegisterProcess & _roProcess,
DWORD _dwValue,
LPCTSTR _ptcName,
DWORD _dwThreadID=-1
)
{
if( _dwThreadID == (DWORD)-1 ) _dwThreadID = GetCurrentThreadId();
CString oThreadID;
oThreadID.Format( TEXT("0x%X"), _dwThreadID);
CString oKeyPath;
oKeyPath.Format( TEXT("%s\\Threads"), _roProcess.GetRegPath() );
CreateKey(oKeyPath, oThreadID);
long lResult = SetDWORDValue(_ptcName, _dwValue );
}
void SetKeyValue(CRegisterProcess & _roProcess,
LPCTSTR _ptcValue,
LPCTSTR _ptcName,
DWORD _dwThreadID=-1
)
{
if( _dwThreadID == (DWORD)-1 ) _dwThreadID = GetCurrentThreadId();
CString oThreadID;
oThreadID.Format( TEXT("0x%X"), _dwThreadID);
CString oKeyPath;
oKeyPath.Format( TEXT("%s\\Threads"), _roProcess.GetRegPath() );
CreateKey(oKeyPath, oThreadID);
long lResult = SetStringValue(_ptcName, _ptcValue );
}
};
#endif // __THREAD_MONITOR_REGISTRAR_H__