Click here to Skip to main content
15,886,362 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.3K   7.3K   79  
Source code for writing your own Task Manager for Windows Mobile or Windows CE based devices
#pragma once

#include <comutil.h>

template <class T>
class CProxy_ICpuLoadEvents : public IConnectionPointImpl<T, &__uuidof(_ICpuLoadEvents), CComDynamicUnkArray>
{
	//Warning this class will  be regenerated by the wizard.
public:
    HRESULT Measurement(LONG CpuLoad)
    {
		T* pT = static_cast<T*>(this);
		int nConnectionIndex;
		int nConnections;
        int nValidConnections = 0;
		CComVariant vars[1];

   		nConnections = m_vec.GetSize();
        for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
        {
			if (m_vec.GetAt(nConnectionIndex)) nValidConnections++;
        }
		for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
		{
			HRESULT hr=S_OK;
			pT->Lock();
			CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);  // Will AddRef() on client
			pT->Unlock();
			IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
			if (pDispatch != NULL)
			{
				vars[0] = _variant_t(CpuLoad);
				DISPPARAMS disp = { vars, NULL, 1, 0 };
        		CComVariant varResult;
		        EXCEPINFO stExcepInfo;
		        unsigned int uiArgErr = 0;
				hr = pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, &stExcepInfo, &uiArgErr);
				if (FAILED(hr))
				{
                    return hr;
				}
			}
		}
        return S_OK;
    }

#ifdef DEBUG
    // This way we can see who subscribes
    STDMETHODIMP Advise(IUnknown *pUnkSink, DWORD *pdwCookie)
	{
		HRESULT hr=S_OK;

		hr = IConnectionPointImpl<T, &__uuidof(_ICpuLoadEvents), CComDynamicUnkArray>::Advise(pUnkSink, pdwCookie);

		return hr;
	}

    // This way we can see who un-subscribes
	STDMETHODIMP Unadvise(DWORD dwCookie)
	{
		HRESULT hr=S_OK;

    	hr = IConnectionPointImpl<T, &__uuidof(_ICpuLoadEvents), CComDynamicUnkArray>::Unadvise(dwCookie);

		return hr;
	}
#endif
};

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