{"id":1383,"date":"2012-08-18T10:39:08","date_gmt":"2012-08-18T08:39:08","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1383"},"modified":"2012-08-24T10:05:27","modified_gmt":"2012-08-24T08:05:27","slug":"reading-hresult-codes","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1383","title":{"rendered":"Reading HRESULT codes"},"content":{"rendered":"<p>Although <code>HRESULT<\/code> 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 <code>FACILITY_ITF<\/code> etc.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dynimg\/IC534110.png\" alt=\"HRESULT Code Structure\" \/><\/p>\n<p>MSDN describes the codes in the following sections:<\/p>\n<ul>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms690088%28v=vs.85%29.aspx\">Structure of COM Error Codes<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms679751%28v=vs.85%29.aspx\">Codes in FACILITY_ITF<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms688560%28v=vs.85%29.aspx\">Error Handling Strategies<\/a><\/li>\n<\/ul>\n<p>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.<\/p>\n<p>So having the app started, copy <code>HRESULT<\/code> or plain system error code such as <code>ERROR_ACCESS_DENIED<\/code> (5) into clipboard, decimal or hexadecimal, and have it popped up. A click on the balloon googles for code details.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/08\/Image0012.png\" alt=\"\" title=\"Show HRESULT Balloon Notification\" width=\"672\" height=\"149\" class=\"alignnone size-full wp-image-1384\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/08\/Image0012.png 672w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2012\/08\/Image0012-320x70.png 320w\" sizes=\"auto, (max-width: 672px) 100vw, 672px\" \/><\/p>\n<p>Let us see what is in there. We are using <code>FormatMessage<\/code> 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 &#8211; and this really covers a huge number of codes, there might be additional lookup for the code identifier.<\/p>\n<pre><code>CString sTitle = _T(\"System\"), sMessage, sIdentifier;\nif(IsQuartzResult(nResult, &amp;sMessage))\n{\n    sTitle = _T(\"DirectShow\");\n    sIdentifier = LookupQuartzIdentifier(nResult);\n} else if(IsWmResult(nResult, &amp;sMessage))\n    sTitle = _T(\"Windows Media\");\nelse if(IsMfResult(nResult, &amp;sMessage))\n{\n    sTitle = _T(\"Media Foundation\");\n    sIdentifier = LookupMfIdentifier(nResult);\n} else if(IsWs2Result(nResult, &amp;sMessage))\n    sTitle = _T(\"Sockets\");\nelse if(IsWinHttpResult(nResult, &amp;sMessage))\n    sTitle = _T(\"WinHTTP\");\nelse if(IsWinInetResult(nResult, &amp;sMessage))\n    sTitle = _T(\"WinInet\");\nelse \n{\n    sMessage = AtlFormatSystemMessage(nResult);\n    sIdentifier = LookupSystemIdentifier(nResult);\n    if(sIdentifier.IsEmpty())\n        sIdentifier = LookupHresultSystemIdentifier(nResult);\n}\n<\/code><\/pre>\n<p>If the code is found, it goes up into balloon notification.<\/p>\n<p>The application decodes 6000+ <code>HRESULT<\/code> codes into human friendly state.<\/p>\n<p>Download links:<\/p>\n<ul>\n<li>Partial Visual C++ 2012 source code: <a href=\"https:\/\/www.alax.info\/trac\/public\/browser\/trunk\/Utilities\/ShowHresult\">Trac<\/a>, <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/ShowHresult\">Subversion<\/a><\/li>\n<li>Binaries: Win32 \u00e2\u20ac\u201c <a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Utilities\/ShowHresult\/_Bin\/Release\/ShowHresult.exe\">ShowHresult.exe<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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. MSDN describes the codes in the following sections: Structure of COM&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1383\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13,2],"tags":[433,95,78,434,432,424],"class_list":["post-1383","post","type-post","status-publish","format-standard","hentry","category-atl","category-source","category-utilities","tag-code","tag-com","tag-directshow","tag-error","tag-hresult","tag-media-foundation"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1383"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1383\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}