Hresult From Win32 Error Code
Contents |
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine hresult values win32 error codes Forums Blogs Channel 9 Documentation APIs and reference Dev centers
Convert Hresult To String
Samples Retired content We’re sorry. The content you requested has been removed. You’ll be auto redirected in hresult_from_win32 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 hresult formatmessage 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
Hresult C#
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
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community hresult c++ Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev hresult msdn centers Samples Retired content We’re sorry. The content you requested has been removed. You’ll be auto
Hresult Error
redirected in 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 https://msdn.microsoft.com/en-us/library/gg567305.aspx HRESULT Values 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 HRESULT The HRESULT numbering space is vendor-extensible. Vendors can supply their own values for this field, as long as the C bit (0x20000000) is https://msdn.microsoft.com/en-us/library/cc231198.aspx set, indicating it is a customer code. The HRESULT numbering space has the following internal structure. Any protocol that uses NTSTATUS values on the wire is responsible for stating the order in which the bytes are placed on the wire. 01234567891012345678920123456789301 S R C N X Facility Code S (1 bit): Severity. If set, indicates a failure result. If clear, indicates a success result. R (1 bit): Reserved. If the N bit is clear, this bit MUST be set to 0. If the N bit is set, this bit is defined by the NTSTATUS numbering space (as specified in section 2.3). C (1 bit): Customer. This bit specifies if the value is customer-defined or Microsoft-defined. The bit is set for customer-defined values and clear for Microsoft-defined values.<1> N (1 bit): If set, indicates that the error code is an NTSTATUS value (as specified in section 2.3), except that this bit is set. X (1 bit): Reserved. SHOUL
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn http://stackoverflow.com/questions/25566234/how-to-convert-specific-ntstatus-value-to-the-hresult more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community http://www.java2s.com/Code/CSharp/Windows/ReturnstheHRESULTassociatedwiththegivenerrorcode.htm Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to convert specific NTSTATUS value to the Hresult? up win32 error vote 2 down vote favorite 2 I am know NTSTATUS that i will get in case of specific error, but i got hresult, not ntstatus from pinvoke. So how to convert specific NTSTATUS value to the Hresult. I tried with no success: class Program { private const int FacilityNtBit = 0x10000000; //#define STATUS_DUPLICATE_OBJECTID ((NTSTATUS)0xC000022AL) private const int STATUS_DUPLICATE_OBJECTID = unchecked((int) (0xC000022A)); // HResult that is returned for the STATUS_DUPLICATE_OBJECTID win32 error code private const int CorrectHrStatusDuplicateObjectid = -2147019886; static void Main(string[] args) { int res = HRESULT_FROM_NT(STATUS_DUPLICATE_OBJECTID); Debug.Assert(res == CorrectHrStatusDuplicateObjectid, "Must be the same"); } private static int HRESULT_FROM_NT(int ntStatus) { //#define HRESULT_FROM_NT(x) ((HRESULT) ((x) | FACILITY_NT_BIT)) return ntStatus | FacilityNtBit; } } c# winapi share|improve this question edited Aug 29 '14 at 10:35 asked Aug 29 '14 at 10:17 Brans Ds 1,436623 add a comment| 5 Answers 5 active oldest votes up vote 3 down vote The mapping of native OS error codes to the winapi layer error codes is non-trivial. There's just no correspondence whatsoever between 5010 and 0xc000022a. The mental image to use is a giant switch statement hidden inside ntdll.dll that translates from one to the other. Reluctantly exposed by Microsoft, you'd normally have to jump through hoops to use it. Actually easier from pinvoke code since it already uses GetProcAddress() to find exported functions. But as long as you are making a winapi call, you should only expect to get a winapi error code and make no attempt to translate it yourself. It can be wrapped in an HRESULT, simply 0x80070000 + error. The native OS error code does bleed through sometimes, particularly for SEH exception codes, but is
EventThreadWeb ServicesWindowsWindows Presentation FoundationXMLXML LINQReturns the HRESULT associated with the given error code. : Windows API«Windows«C# / C SharpC# / C SharpWindowsWindows APIReturns the HRESULT associated with the given error code. /* * Public, Non-Commecial use. * * Copyright ? 2008 Mordechai Botrushvili (GASS Ltd.) * moti@gass-ltd.co.il * Bosmat 2a, Shoham 60850, Israel. * All rights reserved. Israel. * * Use is permitted with restrictions of the attached license. */ using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace GASS.Utilities { /// NativeUtilities
wraps several necessary native functions /// from Win32 API and useful macros that exist when programming in C/C++ /// languages. /// CloseHandle
function. ///