Convert Win32 Error Code Hresult
Contents |
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine convert hresult to string Forums Blogs Channel 9 Documentation APIs and reference Dev centers hresult_from_win32 Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in hresult values win32 error codes 1 second. Export (0) Print Expand All MSDN Library Open Specifications Protocols Windows Protocols References [MS-ERREF]: Windows Error Codes 2 Structures 2.1 HRESULT 2.1.1 HRESULT Values
Make_hresult
2.1.2 HRESULT From WIN32 Error Code Macro Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. 2.1.2 HRESULT From WIN32 Error Code Macro The HRESULT From WIN32 Error Code Macro converts a Win32 error code to an HRESULT using the pattern 0x8007XXXX, where XXXX ntstatus to hresult is the first two bytes of the Win32 hex value 0x0000XXXX. The macro is as follows: #define FACILITY_WIN32 0x0007 #define __HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000))) Show: Inherited Protected Is this page helpful? Yes No Additional feedback? 1500 characters remaining Submit Skip this Thank you! We appreciate your feedback. Dev centers Windows Office Visual Studio Microsoft Azure More... Learning resources Microsoft Virtual Academy Channel 9 MSDN Magazine Community Forums Blogs Codeplex Support Self support Programs BizSpark (for startups) Microsoft Imagine (for students) United States (English) Newsletter Privacy & cookies Terms of use Trademarks © 2016 Microsoft © 2016 Microsoft
Tags: HRESULT, HRESULT From Win32 error code, WIN32 2 thoughts on “Convert win32 error codes to HRESULT” Reply mithun on October 14, 2009 at 12:12 pm _com_error said: how to convert the hresult code to error description Reply Nibu
Print Hresult
Thomas on October 14, 2009 at 2:08 pm said: Hi Mithun, You can type @err,hr into the debug
Hresult Type
watch window to see a description of last error. Also there is a API called FormatMessage, which helps in translating an error code to it's description. Appreciate your comments... Cancel https://msdn.microsoft.com/en-us/library/gg567305.aspx reply « Saving value of a MACRO( #define ) before redefining! Using GetLogicalDriveStrings! » Subscribe to Blog via Email Enter your email address to subscribe to this blog and receive notifications of new posts by email. Join 1 other subscriber Email Address Calendar June 2007 M T W T F S S « May Jul » 123 45678910 http://ntcoder.com/2007/06/26/convert-win32-error-codes-to-hresult/ 11121314151617 18192021222324 252627282930 Tags.net ActiveX ATL C++ CComboBox CDialog Clipboard COM Console API Console Application cout CreateProcess CString Debug Debugger Debugging dumpbin Feature pack GDI GetProcAddress GetSystemMenu Interview questions MVP MVP Summit MVP Summit 2008 Nibu Nibu babu thomas Nibu Thomas Ray Ozzie Redmond SetBkMode SetWindowPos ShGetFileInfo Steve Ballmer stl Summit VC8 vector Visual studio Visual Studio 2013 VS2005 VS2008 windbg Windows Windows Phone CategoriesCategories Select Category .net(18) C#(15) VB(12) ActiveX(2) Announcements(3) ATL(4) Books(1) C Programming(13) C++, VC++(90) C++/CLI(3) C++11(1) CRT(1) STL(3) CodeProject(1) COM(16) Debugging(24) Development Tools(4) DevTools(1) DOS(2) General(13) MVP Stuff(1) MVP Summit 2008(5) HTML(1) Interop(2) Interview Questions(4) C++(1) MFC(57) Microsoft(7) Windows 8(1) Windows 8 Apps(1) Windows Phone(2) Microsoft Office(1) My Blogs(2) bits and bytes(2) My thoughts(3) Networking(1) Parallel Programming(1) Polls(2) STL(1) STL(1) STL(1) STL(1) STL(1) Strange bugs(5) Uncategorized(1) Undocumented WinAPI(5) Visual C++ Compiler(4) Visual studio(37) Visual Studio 2012(3) Visual Studio 2013(7) Win32Controls(1) WinDbg(6) Windows(18) Batch programming(2) Command Prompt (Cmd.exe)(1) SysInternals(1) Tools(1) Windows API(178) Windows Phone(2) WPF(1) Nibu Thomas I work as a Support Escalation Engineer at Microsoft Support, supporting C#, VB.net, Visual C++,
Win32 1Comment There are three common error code formats used throughout Windows. In the kernel and native part, NTSTATUS is used exclusively. The Win32 API uses its own error codes (they do not really have a name, https://jpassing.com/2007/08/20/error-codes-win32-vs-hresult-vs-ntstatus/ so I will refer to them as Win32 error codes) and COM uses HRESULTs -- though the separation is not always so sharp, e.g. the safe string functions (StringCch* and friends) also return HRESULTs although they do not belong to COM. HRESULT (From winerror.h) // // HRESULTs are 32 bit values layed out as follows: // // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 win32 error 1 1 1 1 1 1 1 1 // 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 // +-+-+-+-+-+---------------------+-------------------------------+ // |S|R|C|N|r| Facility | Code | // +-+-+-+-+-+---------------------+-------------------------------+ // // where // // S - Severity - indicates success/fail // // 0 - Success // 1 - Fail win32 error code (COERROR) // // R - reserved portion of the facility code, corresponds to NT's // second severity bit. // // C - reserved portion of the facility code, corresponds to NT's // C field. // // N - reserved portion of the facility code. Used to indicate a // mapped NT status value. // // r - reserved portion of the facility code. Reserved for internal // use. Used to indicate HRESULT values that are not status // values, but are instead message ids for display strings. // // Facility - is the facility code // // Code - is the facility's status code // NTSTATUS and Win32 error codes (From Winerror.h or ntstatus.h) NTSTATUS* and Win32 error codes share the same definition: // // Values are 32 bit values layed out as follows: // // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 // 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 // +---+-+-+-----------------------+-------------------------------+ // |Sev|C|R| Facility | Code | // +---+-+-+-----------------------+-------------------------------+ // // where // // Sev - is the severity co