{"id":29053,"date":"2006-11-10T07:00:00","date_gmt":"2006-11-10T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/11\/10\/converting-an-hresult-to-a-win32-error-code-diagram-and-answer-to-exercise\/"},"modified":"2006-11-10T07:00:00","modified_gmt":"2006-11-10T07:00:00","slug":"converting-an-hresult-to-a-win32-error-code-diagram-and-answer-to-exercise","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20061110-00\/?p=29053","title":{"rendered":"Converting an HRESULT to a Win32 error code: Diagram and answer to exercise"},"content":{"rendered":"<p><!--\nv\\:* { behavior: url(#default#VML); }\n--><\/p>\n<p>\nHere&#8217;s the diagram from\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/11\/03\/942851.aspx\">\nHow do I convert an HRESULT to a Win32 error code?<\/a>.\nIf you are offended by VML, cover your ears and hum for a while.\n<\/p>\n<table BORDER=\"0\">\n<tr>\n<td STYLE=\"padding-top: 10pt\">\n<div>\n<p> Win32\n HRESULT<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>\nThe little sliver at the top is the mapping of zero to zero.\nThe big white box at the bottom is the mapping of all negative\nnumbers to corresponding negative numbers.\nAnd the rainbow represents the mapping of all the positive\nvalues, mod 65536, into the range 0x80070000 through 0x8007FFFF.\n<\/p>\n<p>\nNow let&#8217;s take a look at that puzzle I left behind:\n<\/p>\n<blockquote CLASS=\"q\"><p>\nSometimes, when I import data from a scanner, I get the error\n&#8220;The directory cannot be removed.&#8221;\nWhat does this mean?\n<\/p><\/blockquote>\n<p>\nMy psychic powers told me that the customer was doing something\nlike this (error checking deleted):\n<\/p>\n<pre>\nReportError(HWND hwnd, HRESULT hr)\n{\n DWORD dwError = HRESULT_CODE(hr);\n TCHAR szMessage[256];\n FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,\n               dwError, 0, szMessage, 256, NULL);\n MessageBox(hwnd, szMessage, TEXT(\"Error\"), MB_OK);\n}\n<\/pre>\n<p>\nand that the actual <code>HRESULT<\/code> was\n<code>WIA_ERROR_COVER_OPEN<\/code>, which is defined as\n<\/p>\n<pre>\n#define WIA_ERROR_COVER_OPEN MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIA, 16)\n<\/pre>\n<p>\nPassing this value to <code>HRESULT_CODE<\/code> would yield 16,\nwhich maps to\n<\/p>\n<pre>\n\/\/\n\/\/ MessageId: ERROR_CURRENT_DIRECTORY\n\/\/\n\/\/ MessageText:\n\/\/\n\/\/  The directory cannot be removed.\n\/\/\n#define ERROR_CURRENT_DIRECTORY          16L\n<\/pre>\n<p>\nAnd that would explain why the customer reported this\nstrange error when reading data from a scanner.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s the diagram from How do I convert an HRESULT to a Win32 error code?. If you are offended by VML, cover your ears and hum for a while. Win32 HRESULT The little sliver at the top is the mapping of zero to zero. The big white box at the bottom is the mapping of [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-29053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Here&#8217;s the diagram from How do I convert an HRESULT to a Win32 error code?. If you are offended by VML, cover your ears and hum for a while. Win32 HRESULT The little sliver at the top is the mapping of zero to zero. The big white box at the bottom is the mapping of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=29053"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29053\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=29053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=29053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=29053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}