HRESULT_FROM_WIN32 macro
Applies to: desktop apps only
Maps a system error code to an HRESULT value.
Syntax
HRESULT HRESULT_FROM_WIN32( DWORD x );
Parameters
- x
-
The system error code.
Return value
The HRESULT value.
Remarks
This macro is defined as follows:
//
// HRESULT_FROM_WIN32(x) used to be a macro, however we now run it as an inline function
// to prevent double evaluation of 'x'. If you still need the macro, you can use __HRESULT_FROM_WIN32(x)
//
#define __HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)))
#ifndef __midl
FORCEINLINE HRESULT HRESULT_FROM_WIN32(unsigned long x) {
return (HRESULT)(x) <= 0 ? (HRESULT)(x) : (HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000);
}
#else
#define HRESULT_FROM_WIN32(x) __HRESULT_FROM_WIN32(x)
#endif
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
See also
Send comments about this topic to Microsoft
Build date: 3/7/2012
Better C# alternative
Even better is to simply use this method: int hResult = Marshal.GetHRForLastWin32Error()
- 5/22/2012
- Jim Harrison
- 5/22/2012
- Jim Harrison
A C# conversion
static Int32 HRESULT_FROM_WIN32(Int32 win32Error)
{
const Int32 FACILITY_WIN32 = 7;
UInt32 hr = win32Error <= 0
? (UInt32)(win32Error)
: (((UInt32)(win32Error & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000));
return (Int32)hr;
}
- 11/5/2008
- codekaizen
- 6/29/2010
- Stanley Roark