Quantcast
Channel: DirectShow – Fooling Around
Viewing all articles
Browse latest Browse all 72

Reading HRESULT codes

$
0
0

Although HRESULT codes are so common and structure is simple and well known, and even Visual Studio helps decoding the values nowadays, looking up for code takes some effort: hexadecimal value, searching through SDK headers or online, overlapped regions of codes in FACILITY_ITF etc.

HRESULT Code Structure

MSDN describes the codes in the following sections:

Now is there an answer to the challenge of easy decoding without routinely looking up Windows SDK every time? A helper system tray application makes a nice try. I used to use HR Plus (HR+) application for some time, but at some point even its small bugs started being annoying. Additionally, this one has a priority to decoding DirectShow, Windows Media and Media Foundation error codes.

So having the app started, copy HRESULT or plain system error code such as ERROR_ACCESS_DENIED (5) into clipboard, decimal or hexadecimal, and have it popped up. A click on the balloon googles for code details.

Let us see what is in there. We are using FormatMessage API to look for code message in the following order of preference: DirectShow, Windows Media, Media Foundation, Windows Sockets, WinTHTP, WinInet, System. If the code is found – and this really covers a huge number of codes, there might be additional lookup for the code identifier.

CString sTitle = _T("System"), sMessage, sIdentifier;
if(IsQuartzResult(nResult, &sMessage))
{
    sTitle = _T("DirectShow");
    sIdentifier = LookupQuartzIdentifier(nResult);
} else if(IsWmResult(nResult, &sMessage))
    sTitle = _T("Windows Media");
else if(IsMfResult(nResult, &sMessage))
{
    sTitle = _T("Media Foundation");
    sIdentifier = LookupMfIdentifier(nResult);
} else if(IsWs2Result(nResult, &sMessage))
    sTitle = _T("Sockets");
else if(IsWinHttpResult(nResult, &sMessage))
    sTitle = _T("WinHTTP");
else if(IsWinInetResult(nResult, &sMessage))
    sTitle = _T("WinInet");
else 
{
    sMessage = AtlFormatSystemMessage(nResult);
    sIdentifier = LookupSystemIdentifier(nResult);
    if(sIdentifier.IsEmpty())
        sIdentifier = LookupHresultSystemIdentifier(nResult);
}

If the code is found, it goes up into balloon notification.

The application decodes 6000+ HRESULT codes into human friendly state.

Download links:


Viewing all articles
Browse latest Browse all 72

Trending Articles