Click here to Skip to main content
12,349,884 members (25,084 online)
Click here to Skip to main content

Stats

73.9K views
5.6K downloads
73 bookmarked
Posted

Task Manager for Windows Mobile and Windows CE

, 30 Nov 2008 CPOL
Source code for writing your own Task Manager for Windows Mobile or Windows CE based devices
Documents and Settings
Werner
My Documents
The CodeProject
CETaskManager_V2
CETaskManager.CAB
CETaskManager
CAB
TaskManager.vddproj
CEChart
bin
Release
CE
CEchart.dll
CEchart.pdb
CETaskManager
Properties
Res
TaskMgr.ico
TaskMgr.ico
ToolBox
Idl
Res
CpuLoad.rgs
CpuLoadDCOM.rgs
Process.rgs
ProcessDCOM.rgs
ProcessList.rgs
ProcessListDCOM.rgs
System.rgs
SystemDCOM.rgs
ToolBox.def
ToolBox.rgs
ToolBoxdcom.rgs
Src
Threads
Tools
Windows
ToolBox.vcproj.ISAS5.Werner.user
ToolBoxTest
#include "stdafx.h"
#include "Tools\Exception.h"

namespace Tools
{

Exception::Exception(const CLSID& clsId, UINT resourceId, ...)
{
    _ASSERTE ((resourceId > 0x0200) && (resourceId < 0xFFFF));

    m_hr = MAKE_HRESULT (3/*error*/, FACILITY_ITF, resourceId);

    _bstr_t component = GetProgId (clsId);

    va_list argList;
    va_start (argList, resourceId);
    _bstr_t description (LoadString (resourceId, &argList));
    va_end (argList);

    ICreateErrorInfoPtr iCreateErrorInfo;
    if (SUCCEEDED (CreateErrorInfo (&iCreateErrorInfo)))
    {
        iCreateErrorInfo->SetGUID (GUID_NULL);
        iCreateErrorInfo->SetSource (component);
        iCreateErrorInfo->SetDescription (description);

        IErrorInfoPtr iErrorInfo (iCreateErrorInfo);
        SetErrorInfo (0, iErrorInfo);
    }
}

HRESULT Exception::GetException() const
{
    return m_hr;
}

_bstr_t Exception::LoadString (UINT resourceId, va_list *argList)
{
    _bstr_t description;

    WCHAR format[256];
    int length = ::LoadString(::GetModuleInstance(), resourceId, format, ArraySize(format));

    if (length == 0)
    {
        description = L"Unkown message";
    }
    else
    {
        LPWSTR buffer = NULL;
        ::FormatMessage (FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
		                 format, 0, 0, (LPWSTR) &buffer, 0, argList);
        if (buffer != NULL)
        {
    	    description = buffer;
            LocalFree (buffer);
        }
    }

    return description;
}

_bstr_t Exception::GetProgId (const CLSID& clsId)
{
    _bstr_t progId (L"Unknown");
    
    LPOLESTR progIdOle;
    ProgIDFromCLSID (clsId, &progIdOle);

    if (progIdOle != NULL)
    {
        progId = progIdOle;
        CoTaskMemFree (progIdOle);
    }

	return progId;
}

} // namespace Tools

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

Werner Willemsens
Team Leader
Belgium Belgium
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 30 Nov 2008
Article Copyright 2008 by Werner Willemsens
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid