Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::HResult Class Reference

#include <HResult.h>

Public Types

typedef cPair< FACILITY_TYPE, const GChar_t * > Facility_t
 

Public Member Functions

 HResult (HRESULT hRes) noexcept
 
 HResult (FACILITY_TYPE eFacility, WORD wCode) noexcept
 
 HResult (int eFacility, long wCode) noexcept
 
 operator HRESULT () const noexcept
 
DWORD get_Code () const noexcept
 
FACILITY_TYPE get_Facility () const noexcept
 
bool isFailure () const noexcept
 

Static Public Member Functions

static DWORD GetCode (HRESULT hRes) noexcept
 
static FACILITY_TYPE GetFacility (HRESULT hRes) noexcept
 
static bool IsFailure (HRESULT hRes) noexcept
 
static HRESULT Make (FACILITY_TYPE eFacility, WORD wCode) noexcept
 
static HRESULT Make (BYTE bReserved, FACILITY_TYPE eFacility, WORD wCode) noexcept
 
static HRESULT FromWin32 (DWORD dwWin32Code) noexcept
 
static HRESULT __stdcall GetLast () noexcept
 
static HRESULT GetDef (HRESULT hRes, HRESULT hResDef=E_FAIL) noexcept
 
static HRESULT GetLastDef (HRESULT hResDef=E_FAIL) noexcept
 
static HRESULT __stdcall FromPOSIX (int iErrNo) noexcept
 
static HRESULT __stdcall GetPOSIXLast () noexcept
 
static HRESULT __stdcall GetPOSIXLastDef (HRESULT hResDef=E_FAIL) noexcept
 
static void __stdcall AddCodes (const HResultCode *pCodes)
 
static void __stdcall AddCodesDefault ()
 
static HRESULT __stdcall AddCodesText (const char *pszText)
 
static HRESULT __stdcall AddCodesFile (const FILECHAR_t *pszFilePath)
 
static const char *__stdcall GetTextBase (HRESULT hRes)
 
static StrLen_t __stdcall GetTextSys (HRESULT hRes, GChar_t *lpszError, StrLen_t nLenMaxError, void *pSource=nullptr, va_list vargs=k_va_list_empty)
 
static StrLen_t __stdcall GetTextV (HRESULT hRes, GChar_t *lpszError, StrLen_t nLenMaxError, void *pSource=nullptr, va_list vargs=k_va_list_empty)
 
static HRESULT __stdcall GetHResFromStr (const GChar_t *pszError, StrLen_t nLenError=-1)
 

Public Attributes

HRESULT m_hRes
 

Static Public Attributes

static const Facility_t k_Facility []
 names of all known FACILITY_TYPE. More...
 

Friends

class HResultTests
 

Detailed Description

HRESULT code processing. HRESULT = (high bit=SEVERITY_ERROR, 4bit=reserve, 11bit=facility, 16bits=code) AKA SCODE in old _WIN32 MFC. https://msdn.microsoft.com/en-us/library/cc231198.aspx

Member Typedef Documentation

◆ Facility_t

Constructor & Destructor Documentation

◆ HResult() [1/3]

Gray::HResult::HResult ( HRESULT  hRes)
inlinenoexcept

◆ HResult() [2/3]

Gray::HResult::HResult ( FACILITY_TYPE  eFacility,
WORD  wCode 
)
inlinenoexcept

◆ HResult() [3/3]

Gray::HResult::HResult ( int  eFacility,
long  wCode 
)
inlinenoexcept

Member Function Documentation

◆ AddCodes()

void GRAYCALL Gray::HResult::AddCodes ( const HResultCode pCodes)
static

Add a block of custom HResult codes, usually for a particular FACILITY_TYPE enable HResult::GetTextV()

◆ AddCodesDefault()

void GRAYCALL Gray::HResult::AddCodesDefault ( )
static

configure error text for normal system errors.

Todo:
get rid of these in favor of dynamic loading of s_HResult_CodeSets from file.

< Known codes in FACILITY_WIN32

< Known codes NOT in FACILITY_WIN32

◆ AddCodesFile()

HRESULT GRAYCALL Gray::HResult::AddCodesFile ( const FILECHAR_t pszFilePath)
static

add a block of codes (and text) from a text file. Lines of comma separated text.

◆ AddCodesText()

HRESULT GRAYCALL Gray::HResult::AddCodesText ( const char *  pszText)
static

add a block of codes (and text) from some text blob (that i parse). Lines of comma separated text.

◆ FromPOSIX()

HRESULT GRAYCALL Gray::HResult::FromPOSIX ( int  iErrNo)
staticnoexcept

Translate/Convert a DOS/POSIX error code errno_t to HRESULT type. AKA errno POSIX calls like system() return these codes. http://www.koders.com/c/fid8425F6A15760BC96CEEEC6FD90C93E689C2C1AF5.aspx

◆ FromWin32()

static HRESULT Gray::HResult::FromWin32 ( DWORD  dwWin32Code)
inlinestaticnoexcept
  • dwWin32Code = maybe LSTATUS/error_status_t or already HRESULT (see GetLastError() docs) like HRESULT_FROM_WIN32(dwWin32Code) NOT HRESULT_WIN32_C(WORD)

◆ get_Code()

DWORD Gray::HResult::get_Code ( ) const
inlinenoexcept

◆ get_Facility()

FACILITY_TYPE Gray::HResult::get_Facility ( ) const
inlinenoexcept

◆ GetCode()

static DWORD Gray::HResult::GetCode ( HRESULT  hRes)
inlinestaticnoexcept

Get just the facility sub code portion of the HRESULT. may be LSTATUS/error_status_t HRESULT_CODE(hRes) = WORD or LSTATUS

◆ GetDef()

static HRESULT Gray::HResult::GetDef ( HRESULT  hRes,
HRESULT  hResDef = E_FAIL 
)
inlinestaticnoexcept

We know there was an error! If the hRes isn't an error supply a default error as hResDef.

◆ GetFacility()

static FACILITY_TYPE Gray::HResult::GetFacility ( HRESULT  hRes)
inlinestaticnoexcept

HRESULT_FACILITY(hRes)

◆ GetHResFromStr()

HRESULT GRAYCALL Gray::HResult::GetHResFromStr ( const GChar_t pszError,
StrLen_t  nLenError = -1 
)
static

Reverse lookup of error string. given a string from GetTextV() get the original HRESULT code.

Returns
HRESULT Error code from a string.

◆ GetLast()

HRESULT GRAYCALL Gray::HResult::GetLast ( )
staticnoexcept

Get the last system error recorded for this thread. match against HRESULT_WIN32_C(x)

◆ GetLastDef()

static HRESULT Gray::HResult::GetLastDef ( HRESULT  hResDef = E_FAIL)
inlinestaticnoexcept

Get the last system error recorded for this thread. A known failure. If there isn't one then just use the supplied default. E_FAIL

◆ GetPOSIXLast()

HRESULT GRAYCALL Gray::HResult::GetPOSIXLast ( )
staticnoexcept

Get last POSIX error code. 'errno' converted to HRESULT

◆ GetPOSIXLastDef()

static HRESULT __stdcall Gray::HResult::GetPOSIXLastDef ( HRESULT  hResDef = E_FAIL)
inlinestaticnoexcept

◆ GetTextBase()

const char *GRAYCALL Gray::HResult::GetTextBase ( HRESULT  hRes)
static

Get raw unformatted text for HRESULT codes from s_HResult_CodeSets first

◆ GetTextSys()

StrLen_t GRAYCALL Gray::HResult::GetTextSys ( HRESULT  hRes,
GChar_t lpszError,
StrLen_t  nLenMaxError,
void *  pSource = nullptr,
va_list  vargs = k_va_list_empty 
)
static

Ask the system what text there is for hRes. don't call strerror() here since it has just a pointer. use GetTextBase().

◆ GetTextV()

StrLen_t GRAYCALL Gray::HResult::GetTextV ( HRESULT  hRes,
GChar_t lpszError,
StrLen_t  nLenMaxError,
void *  pSource = nullptr,
va_list  vargs = k_va_list_empty 
)
static

Get a string for the error code hRes. copies error message text to a string pszError. Append numeric code to the end. similar to the linux strerror() In windows there is a COM API for resolving these ?

  • pszError = destination buffer
  • nLenMaxError = buffer size for pszError in chars including room for null.
  • pSource = module handle for "pdh.dll" ?
  • vargs = additional arguments.
    Returns
    destination buffer length in chars.

◆ isFailure()

bool Gray::HResult::isFailure ( ) const
inlinenoexcept

FAILED(hRes) like HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1)

◆ IsFailure()

static bool Gray::HResult::IsFailure ( HRESULT  hRes)
inlinestaticnoexcept

FAILED(hRes) like HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1)

◆ Make() [1/2]

static HRESULT Gray::HResult::Make ( BYTE  bReserved,
FACILITY_TYPE  eFacility,
WORD  wCode 
)
inlinestaticnoexcept

Make a special HRESULT error code from FACILITY_TYPE + WORD code + bReserved. bReserved = 4 for a PerfMon Code. 8=app specific error. leave 0 for normal system error code.

◆ Make() [2/2]

static HRESULT Gray::HResult::Make ( FACILITY_TYPE  eFacility,
WORD  wCode 
)
inlinestaticnoexcept

Make a HRESULT error code from FACILITY_TYPE + WORD code.

◆ operator HRESULT()

Gray::HResult::operator HRESULT ( ) const
inlinenoexcept

Friends And Related Function Documentation

◆ HResultTests

friend class HResultTests
friend

Member Data Documentation

◆ k_Facility

const HResult::Facility_t Gray::HResult::k_Facility
static
Initial value:
=
{
Facility_t((FACILITY_TYPE)FACILITY_WIN32, _GT("Win32")),
Facility_t((FACILITY_TYPE)FACILITY_INTERNET, _GT("Internet")),
Facility_t((FACILITY_TYPE)FACILITY_HTTP, _GT("Http")),
Facility_t((FACILITY_TYPE)FACILITY_DISPATCH, _GT("Dispatch")),
Facility_t((FACILITY_TYPE)FACILITY_ITF, _GT("ITF")),
Facility_t((FACILITY_TYPE)FACILITY_SECURITY, _GT("Security")),
Facility_t((FACILITY_TYPE)FACILITY_COMPLUS, _GT("ComPlus")),
Facility_t((FACILITY_TYPE)FACILITY_NULL, nullptr),
}
#define _GT(x)
like _T(x) macro for static text.
Definition: StrConst.h:27
cPair< FACILITY_TYPE, const GChar_t * > Facility_t
Definition: HResult.h:124
FACILITY_TYPE
Definition: HResult.h:36
@ FACILITY_MMSYS
Facility for _WIN32 MMSYSTEM MMRESULT error codes. MMSYSERR_BASE.
Definition: HResult.h:57
@ FACILITY_D3D
max = 2048 = 0x800 = 11 bits ?
Definition: HResult.h:59
@ FACILITY_POSIX
Facility for POSIX _errno in a _WIN32 style code.
Definition: HResult.h:49

names of all known FACILITY_TYPE.

◆ m_hRes

HRESULT Gray::HResult::m_hRes

The documentation for this class was generated from the following files: