Home | History | Annotate | Download | only in win
      1 /*
      2  * Copyright 2011 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkHRESULT_DEFINED
      9 #define SkHRESULT_DEFINED
     10 
     11 #include "SkTypes.h"
     12 
     13 void SkTraceHR(const char* file, unsigned long line,
     14                HRESULT hr, const char* msg);
     15 
     16 #ifdef SK_DEBUG
     17 #define SK_TRACEHR(_hr, _msg) SkTraceHR(__FILE__, __LINE__, _hr, _msg)
     18 #else
     19 #define SK_TRACEHR(_hr, _msg) _hr
     20 #endif
     21 
     22 #define HR_GENERAL(_ex, _msg, _ret) {\
     23     HRESULT _hr = _ex;\
     24     if (FAILED(_hr)) {\
     25         SK_TRACEHR(_hr, _msg);\
     26         return _ret;\
     27     }\
     28 }
     29 
     30 //@{
     31 /**
     32 These macros are for reporting HRESULT errors.
     33 The expression will be evaluated.
     34 If the resulting HRESULT SUCCEEDED then execution will continue normally.
     35 If the HRESULT FAILED then the macro will return from the current function.
     36 In variants ending with 'M' the given message will be traced when FAILED.
     37 The HR variants will return the HRESULT when FAILED.
     38 The HRB variants will return false when FAILED.
     39 The HRV variants will simply return when FAILED.
     40 */
     41 #define HR(ex) HR_GENERAL(ex, NULL, _hr)
     42 #define HRM(ex, msg) HR_GENERAL(ex, msg, _hr)
     43 
     44 #define HRB(ex) HR_GENERAL(ex, NULL, false)
     45 #define HRBM(ex, msg) HR_GENERAL(ex, msg, false)
     46 
     47 #define HRV(ex) HR_GENERAL(ex, NULL, )
     48 #define HRVM(ex, msg) HR_GENERAL(ex, msg, )
     49 //@}
     50 #endif
     51