{"id":3083,"date":"2005-07-21T12:04:00","date_gmt":"2005-07-21T12:04:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/heaths\/2005\/07\/21\/deciphering-an-hresult\/"},"modified":"2005-07-21T12:04:00","modified_gmt":"2005-07-21T12:04:00","slug":"deciphering-an-hresult","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/setup\/deciphering-an-hresult\/","title":{"rendered":"Deciphering an HRESULT"},"content":{"rendered":"<p><a href=\"\/astebner\/\">Aaron Stebner<\/a> recently <a href=\"\/astebner\/archive\/2005\/07\/18\/440194.aspx\">blogged<\/a> about ways to find out the cause of 1935 <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/msi\/setup\/windows_installer_error_messages.asp\">Windows Installer errors<\/a> and I wanted to provide a little more background on what an <code>HRESULT<\/code> defines.<\/p>\n<p>An <code>HRESULT<\/code> in the 32-bit world and beyond is defined as a <code>long<\/code>, or a signed 32-bit integer. It is defined in, among other places, <em>winerror.h<\/em> in the <a href=\"http:\/\/msdn.microsoft.com\/platformsdk\/\">Platform SDK<\/a>. It defines the severity of an error, whether the error is from user code, a facility that defines where the error came from, and the actual error code. As defined in <em>winerror.h<\/em>:<\/p>\n<pre>\/\/  Values are 32 bit values layed out as follows:\n\/\/\n\/\/   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1\n\/\/   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0\n\/\/  +---+-+-+-----------------------+-------------------------------+\n\/\/  |Sev|C|R|     Facility          |               Code            |\n\/\/  +---+-+-+-----------------------+-------------------------------+\n\/\/\n\/\/  where\n\/\/\n\/\/      Sev - is the severity code\n\/\/\n\/\/          00 - Success\n\/\/          01 - Informational\n\/\/          10 - Warning\n\/\/          11 - Error\n\/\/\n\/\/      C - is the Customer code flag\n\/\/\n\/\/      R - is a reserved bit\n\/\/\n\/\/      Facility - is the facility code\n\/\/\n\/\/      Code - is the facility's status code<\/pre>\n<p>Return codes like <code>S_OK<\/code> and <code>S_FALSE<\/code> have the values 0 and 1, respectively. <code>S_FALSE<\/code> is not treated as an error because the severity bits are 0. Return codes like E_FAIL have the error bit set to 1 (the high-order bit). The macro <code>HRESULT_SEVERITY<\/code> can help determine if the return code represents an error or not by performing a bitwise AND on the high-order bit.<\/p>\n<p>A facility helps identify from where the error came. Was it a security error or an error from the <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/cpguide\/html\/cpconthecommonlanguageruntime.asp\">Common Language Runtime<\/a> (CLR)? The macro <code>HRESULT_FACILTY<\/code> can help you determine that as well. <em>winerror.h<\/em> defines the following facilities (sorted by value):<\/p>\n<pre>#define FACILITY_NULL                    0\n#define FACILITY_RPC                     1\n#define FACILITY_DISPATCH                2\n#define FACILITY_STORAGE                 3\n#define FACILITY_ITF                     4\n#define FACILITY_WIN32                   7\n#define FACILITY_WINDOWS                 8\n#define FACILITY_SSPI                    9\n#define FACILITY_SECURITY                9\n#define FACILITY_CONTROL                 10\n#define FACILITY_CERT                    11\n#define FACILITY_INTERNET                12\n#define FACILITY_MEDIASERVER             13\n#define FACILITY_MSMQ                    14\n#define FACILITY_SETUPAPI                15\n#define FACILITY_SCARD                   16\n#define FACILITY_COMPLUS                 17\n#define FACILITY_AAF                     18\n#define FACILITY_URT                     19\n#define FACILITY_ACS                     20\n#define FACILITY_DPLAY                   21\n#define FACILITY_UMI                     22\n#define FACILITY_SXS                     23\n#define FACILITY_WINDOWS_CE              24\n#define FACILITY_HTTP                    25\n#define FACILITY_BACKGROUNDCOPY          32\n#define FACILITY_CONFIGURATION           33<\/pre>\n<p>All facilities except for <code>FACILITY_ITF<\/code> are defined by Microsoft. <code>FACILITY_ITF<\/code> is designated for user-defined error codes returned from interface methods. Microsoft <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/com\/html\/1f9f7b2c-a4e4-41c0-9ba5-b8bbf722e077.asp\">recommends<\/a> that when using <code>FACILITY_ITF<\/code> you use errors in the range of 0x0200 to 0xffff.<\/p>\n<p>One might be asking if the 2 high-order bits define the severity and having both set is an error, why &#8211; in hexadecimal &#8211; does the error code number start with 8 instead of C? In the days of 16-bit computing, an <code>HRESULT<\/code> was only a 16-bit signed integer while an <code>SCODE<\/code> was a 32-bit signed integer. Only the highest-order bit designated the severity. The facility was also only 4 bits instead of 11. Error codes such as <code>E_FAIL<\/code> defined as 0x80004005 are legacy <code>SCODE<\/code>s and the values have not changed. Newer error codes may set both severity bits like <code>ERROR_AUDITING_DISABLED<\/code> defined as 0xC0090001.<\/p>\n<p>Hopefully this helps you to decipher error codes and at least get some idea from where the error came.<\/p>\n<p><strong>Edit<\/strong>: Thanks to bgrainger for <a HREF=\"\/heaths\/archive\/2005\/07\/21\/441391.aspx#452791\">pointing out<\/a> the correct recommended range.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Aaron Stebner recently blogged about ways to find out the cause of 1935 Windows Installer errors and I wanted to provide a little more background on what an HRESULT defines. An HRESULT in the 32-bit world and beyond is defined as a long, or a signed 32-bit integer. It is defined in, among other places, [&hellip;]<\/p>\n","protected":false},"author":389,"featured_media":3843,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[14],"class_list":["post-3083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-development"],"acf":[],"blog_post_summary":"<p>Aaron Stebner recently blogged about ways to find out the cause of 1935 Windows Installer errors and I wanted to provide a little more background on what an HRESULT defines. An HRESULT in the 32-bit world and beyond is defined as a long, or a signed 32-bit integer. It is defined in, among other places, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/3083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/users\/389"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/comments?post=3083"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/3083\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media\/3843"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media?parent=3083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/categories?post=3083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/tags?post=3083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}