Click here to Skip to main content
15,897,518 members
Articles / Mobile Apps / Windows Mobile

Task Manager for Windows Mobile and Windows CE

Rate me:
Please Sign up or sign in to vote.
4.51/5 (23 votes)
30 Nov 2008CPOL10 min read 112.9K   7.3K   79  
Source code for writing your own Task Manager for Windows Mobile or Windows CE based devices
// Process.cpp : Implementation of CProcess

#include "stdafx.h"
#include "Processes.h"
#include "Tools\Exception.h"
#include <stdexcept>

CProcess::CProcess() :
    m_name(L""),
    m_pid(0),
    m_threadCount(0),
    m_baseAddress(0),
    m_heapSize(0),
    m_virtualMemory(0),
    m_virtualMemoryCommitted(0),
    m_virtualMemoryReserved(0),
    m_dll(0)
{
}

// CProcess
HRESULT CProcess::FinalConstruct()
{
	return S_OK;
}

void CProcess::FinalRelease()
{
}

STDMETHODIMP CProcess::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&IID_IProcess
	};

	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}

void CProcess::Init(_bstr_t name, long pid, 
                                  long threadCount, 
                                  long baseAddress, 
                                  long heapSize, 
                                  long virtualMemory,
                                  long virtualMemoryCommitted,
                                  long virtualMemoryReserved,
                                  long dll)
{
    m_name = name;
    m_pid = pid;
    m_threadCount = threadCount;
    m_baseAddress = baseAddress;
    m_heapSize = heapSize;
    m_virtualMemory = virtualMemory;
    m_virtualMemoryCommitted = virtualMemoryCommitted;
    m_virtualMemoryReserved = virtualMemoryReserved;
    m_dll = dll;
}

STDMETHODIMP CProcess::get_Name(/*[out, retval]*/ BSTR *value)
{
    try
    {
        Windows::AutoCriticalSection lock(m_lock);

        *value = m_name.copy ();
    } catch (std::exception& err)
    {
        const char* msg = err.what();
        Tools::Exception exception(CLSID_Process, IDS_FAILED);
        return exception.GetException();
    } catch (_com_error& err)
    {
        err = err;
        Tools::Exception exception(CLSID_Process, IDS_FAILED);
        return exception.GetException();
    }

    return S_OK;
}

STDMETHODIMP CProcess::get_Pid(/*[out, retval]*/ LONG *value)
{
    *value = m_pid;
    return S_OK;
}

STDMETHODIMP CProcess::get_ThreadCount(/*[out, retval]*/ LONG *value)
{
    *value = m_threadCount;
    return S_OK;
}

STDMETHODIMP CProcess::get_BaseAddress(/*[out, retval]*/ LONG *value)
{
    *value = m_baseAddress;
    return S_OK;
}

STDMETHODIMP CProcess::get_HeapSize(/*[out, retval]*/ LONG *value)
{
    *value = m_heapSize;
    return S_OK;
}

STDMETHODIMP CProcess::get_VirtualMemory(/*[out, retval]*/ LONG *value)
{
    *value = m_virtualMemory;
    return S_OK;
}

STDMETHODIMP CProcess::get_VirtualMemoryCommitted(/*[out, retval]*/ LONG *value)
{
    *value = m_virtualMemoryCommitted;
    return S_OK;
}

STDMETHODIMP CProcess::get_VirtualMemoryReserved(/*[out, retval]*/ LONG *value)
{
    *value = m_virtualMemoryReserved;
    return S_OK;
}

STDMETHODIMP CProcess::get_DllCount(/*[out, retval]*/ LONG *value)
{
    *value = m_dll;
    return S_OK;
}

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)


Written By
Team Leader
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions