Click here to Skip to main content
15,896,201 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.8K   7.3K   79  
Source code for writing your own Task Manager for Windows Mobile or Windows CE based devices
// System.cpp : Implementation of CSystem

#include "stdafx.h"
#include "System.h"
#include <stdexcept>
#include "Tools\Exception.h"
#include "Windows\Handle.h"

CSystem::CSystem()
{
    Update();
}

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

void CSystem::FinalRelease()
{
}

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

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

STDMETHODIMP CSystem::Update(void)
{
    {
        // Make sure this happens thread-safe
        Windows::AutoCriticalSection lock(m_lock);

        m_memoryStatus.dwLength = sizeof(MEMORYSTATUS);
        GlobalMemoryStatus(&m_memoryStatus);
    }

    return S_OK;
}

STDMETHODIMP CSystem::get_PhysicalMemoryTotal(/*[out, retval]*/ LONG *value)
{
    *value = m_memoryStatus.dwTotalPhys;
    return S_OK;
}

STDMETHODIMP CSystem::get_PhysicalAvailable(/*[out, retval]*/ LONG *value)
{
    *value = m_memoryStatus.dwAvailPhys;
    return S_OK;
}

STDMETHODIMP CSystem::get_PageFileTotal(/*[out, retval]*/ LONG *value)
{
    *value = m_memoryStatus.dwTotalPageFile;
    return S_OK;
}

STDMETHODIMP CSystem::get_PageFileAvailable(/*[out, retval]*/ LONG *value)
{
    *value = m_memoryStatus.dwAvailPageFile;
    return S_OK;
}

STDMETHODIMP CSystem::get_VirtualMemoryTotal(/*[out, retval]*/ LONG *value)
{
    *value = m_memoryStatus.dwTotalVirtual;
    return S_OK;
}

STDMETHODIMP CSystem::get_VirtualMemoryAvailable(/*[out, retval]*/ LONG *value)
{
    *value = m_memoryStatus.dwAvailVirtual;
    return S_OK;
}

STDMETHODIMP CSystem::EndProcess(/*[in]*/ LONG Pid, /*[out, retval]*/ VARIANT_BOOL *result)
{
    BOOL success = FALSE;
    try
    {
        Windows::Handle processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
        success = TerminateProcess(processHandle, 0);
    } catch (...)
    {
    }

    *result = (success != FALSE) ? VARIANT_TRUE : VARIANT_FALSE;

    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