最終更新:2015-06-02 (火) 15:40:20 (3248d)  

HRESULT
Top / HRESULT

主にWindowsDirectXプログラミングでエラー処理に頻繁に使われる型。32 ビット整数

戻り値の例

  • S_OK(中身は0)
  • E_FAIL(中身は0以外)

メモ

基本的に、HRESULT は 2 つの主要な情報が含まれる構造体です。

  • メソッドが成功したか失敗したかには関係ありません。
  • メソッドによってサポートされる処理の結果に関するより詳細な情報です。

規則により、成功コードの名前の先頭には S_ が、失敗コードの名前の先頭には E_ が付けられます。たとえば、最もよく使用される 2 つのコードは S_OK と E_FAIL であり、それぞれ単純に成功と失敗を示します。

マクロ

  • SUCCEEDED? マクロは、成功コードには TRUE を、失敗コードには FALSE を返します。
  • FAILED マクロは、失敗コードには TRUE を、成功コードには FALSE を返します。
if ( SUCCEEDED( Func(0) )  ) //Func関数でS_OKが返された場合
if ( FAILED( Func(1) ) ) //Func関数でE_FAILが返された場合

構造

  • winerror.h?
    // Note: There is a slightly modified layout for HRESULT values below,
    //        after the heading "COM Error Codes".
    //
    // Search for "**** Available SYSTEM error codes ****" to find where to
    // insert new error codes
    //
    //  Values are 32 bit values laid 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
    //  +-+-+-+-+-+---------------------+-------------------------------+
    //  |S|R|C|N|r|    Facility         |               Code            |
    //  +-+-+-+-+-+---------------------+-------------------------------+
    //
    //  where
    //
    //      S - Severity - indicates success/fail
    //
    //          0 - Success
    //          1 - Fail (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
    //