err.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 8k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //
  2. // err.h: Declares data, defines and struct types for error handling
  3. //          module.
  4. //
  5. //
  6. #ifndef __ERR_H__
  7. #define __ERR_H__
  8. // Requires utils.h to be included prior to this
  9. //
  10. /////////////////////////////////////////////////////  INCLUDES
  11. /////////////////////////////////////////////////////  DEFINES
  12. // Messagebox type flags, used by MsgBox_* macros
  13. //
  14. #define MSG_ERROR       1
  15. #define MSG_INFO        2
  16. #define MSG_QUESTION    3
  17. #ifdef DEBUG
  18. // Dump flags used in g_uDumpFlags
  19. //
  20. #define DF_SPACE        0x0001
  21. #define DF_SUBOBJ       0x0002
  22. // Break flags used in g_uBreakFlags
  23. //
  24. #define BF_ONOPEN       0x0001
  25. #define BF_ONCLOSE      0x0002
  26. #define BF_ONRUNONCE    0x0004
  27. #define BF_ONVALIDATE   0x0010
  28. #define BF_ONTHREADATT  0x0100
  29. #define BF_ONTHREADDET  0x0200
  30. #define BF_ONPROCESSATT 0x0400
  31. #define BF_ONPROCESSDET 0x0800
  32. #endif
  33. // Trace flags used in g_uTraceFlags (defined in retail on purpose)
  34. //
  35. #define TF_ALWAYS       0x0000
  36. #define TF_WARNING      0x0001
  37. #define TF_ERROR        0x0002
  38. #define TF_GENERAL      0x0004      // Standard trace messages
  39. #define TF_FUNC         0x0008      // Function entry/exit trace
  40. #define TF_SUBOBJ       0x0010      // Trace subobj actions
  41. /////////////////////////////////////////////////////  MACROS
  42. // Message box macros
  43. //
  44. //      int MsgBox_Err(HWND hwndParent, UINT ids, UINT idsCaption);
  45. //          Invoke error message (with ! icon)
  46. //
  47. #define MsgBox_Err(hwnd, ids, idsCap)       MsgBoxIds(hwnd, ids, idsCap, MSG_ERROR)
  48. //      int MsgBox_Info(HWND hwndParent, UINT ids, UINT idsCaption);
  49. //          Invoke info message (with i icon)
  50. //
  51. #define MsgBox_Info(hwnd, ids, idsCap)      MsgBoxIds(hwnd, ids, idsCap, MSG_INFO)
  52. //      int MsgBox_Question(HWND hwndParent, UINT ids, UINT idsCaption);
  53. //          Invoke question message (with ? icon and Yes/No buttons)
  54. //
  55. #define MsgBox_Question(hwnd, ids, idsCap)  MsgBoxIds(hwnd, ids, idsCap, MSG_QUESTION)
  56. //      int MsgBox_ErrSz(HWND hwndParent, LPCSTR psz, UINT idsCaption);
  57. //          Invoke error message (with ! icon)
  58. //
  59. #define MsgBox_ErrSz(hwnd, lpsz, idsCap)        MsgBoxSz(hwnd, lpsz, idsCap, MSG_ERROR, NULL)
  60. //      int MsgBox_InfoSz(HWND hwndParent, LPCSTR psz, UINT idsCaption);
  61. //          Invoke info message (with i icon)
  62. //
  63. #define MsgBox_InfoSz(hwnd, lpsz, idsCap)       MsgBoxSz(hwnd, lpsz, idsCap, MSG_INFO, NULL)
  64. //      int MsgBox_QuestionSz(HWND hwndParent, LPCSTR psz, UINT idsCaption);
  65. //          Invoke question message (with ? icon and Yes/No buttons)
  66. //
  67. #define MsgBox_QuestionSz(hwnd, lpsz, idsCap)   MsgBoxSz(hwnd, lpsz, idsCap, MSG_QUESTION, NULL)
  68. // Error table for lookup strings.  Usually an array of these
  69. // structures is created and placed in the readonly data segment.
  70. //
  71. typedef struct _ERRTBL
  72.     {
  73.     DWORD   dwValue;     // Some return value
  74.     UINT    ids;         // String ID of message
  75.     } ErrTbl, * PERRTBL;
  76. typedef ErrTbl const *  PCERRTBL;
  77. int PUBLIC ETMsgBox(HWND hwnd, UINT idsCaption, DWORD dwValue, PCERRTBL petTable, UINT cArraySize);
  78. // Debugging macros
  79. //
  80. #ifdef DEBUG
  81. #define ASSERTSEG
  82. // Use this macro to declare message text that will be placed
  83. // in the CODE segment (useful if DS is getting full)
  84. //
  85. // Ex: DEBUGTEXT(szMsg, "Invalid whatever: %d");
  86. //
  87. #define DEBUGTEXT(sz, msg) /* ;Internal */ 
  88.     static const char ASSERTSEG sz[] = msg;
  89. void PUBLIC RnaAssertFailed(LPCSTR szFile, int line);
  90. void CPUBLIC RnaAssertMsg(BOOL f, LPCSTR pszMsg, ...);
  91. void CPUBLIC RnaDebugMsg(UINT mask, LPCSTR pszMsg, ...);
  92. // ASSERT(f)  -- Generate "assertion failed in line x of file.c"
  93. //               message if f is NOT true.
  94. //
  95. #define ASSERT(f)                                                       
  96.     {                                                                   
  97.         DEBUGTEXT(szFile, __FILE__);                                    
  98.         if (!(f))                                                       
  99.             RnaAssertFailed(szFile, __LINE__);                          
  100.     }
  101. #define ASSERT_E(f)  ASSERT(f)
  102. // ASSERT_MSG(f, msg, args...)  -- Generate wsprintf-formatted msg w/params
  103. //                          if f is NOT true.
  104. //
  105. #define ASSERT_MSG   RnaAssertMsg
  106. // DEBUG_MSG(mask, msg, args...) - Generate wsprintf-formatted msg using
  107. //                          specified debug mask.  System debug mask
  108. //                          governs whether message is output.
  109. //
  110. #define DEBUG_MSG    RnaDebugMsg
  111. #define TRACE_MSG    DEBUG_MSG
  112. // VERIFYSZ(f, msg, arg)  -- Generate wsprintf-formatted msg w/ 1 param
  113. //                          if f is NOT true 
  114. //
  115. #define VERIFYSZ(f, szFmt, x)   ASSERT_MSG(f, szFmt, x)
  116. // DBG_ENTER_RIID(szFn, riid)  -- Generates a function entry debug spew for
  117. //                          a function 
  118. //
  119. #define DBG_ENTER(szFn)                  
  120.     TRACE_MSG(TF_FUNC, " > " szFn "()")
  121. // DBG_ENTER_SZ(szFn, sz)  -- Generates a function entry debug spew for
  122. //                          a function that accepts a string as one of its
  123. //                          parameters.
  124. //
  125. #define DBG_ENTER_SZ(szFn, sz)                  
  126.     TRACE_MSG(TF_FUNC, " > " szFn "(..., %s,...)", Dbg_SafeStr(sz))
  127. // DBG_ENTER_RIID(szFn, riid)  -- Generates a function entry debug spew for
  128. //                          a function that accepts an riid as one of its
  129. //                          parameters.
  130. //
  131. #define DBG_ENTER_RIID(szFn, riid)                  
  132.     TRACE_MSG(TF_FUNC, " > " szFn "(..., %s,...)", Dbg_GetRiidName(riid))
  133. // DBG_EXIT(szFn)  -- Generates a function exit debug spew 
  134. //
  135. #define DBG_EXIT(szFn)                              
  136.         TRACE_MSG(TF_FUNC, " < " szFn "()")
  137. // DBG_EXIT_US(szFn, us)  -- Generates a function exit debug spew for
  138. //                          functions that return a USHORT.
  139. //
  140. #define DBG_EXIT_US(szFn, us)                       
  141.         TRACE_MSG(TF_FUNC, " < " szFn "() with %#x", (USHORT)us)
  142. // DBG_EXIT_UL(szFn, ul)  -- Generates a function exit debug spew for
  143. //                          functions that return a ULONG.
  144. //
  145. #define DBG_EXIT_UL(szFn, ul)                   
  146.         TRACE_MSG(TF_FUNC, " < " szFn "() with %#lx", (ULONG)ul)
  147. // DBG_EXIT_PTR(szFn, pv)  -- Generates a function exit debug spew for
  148. //                          functions that return a pointer.
  149. //
  150. #define DBG_EXIT_PTR(szFn, pv)                   
  151.         TRACE_MSG(TF_FUNC, " < " szFn "() with %#lx", (LPVOID)pv)
  152. // DBG_EXIT_HRES(szFn, hres)  -- Generates a function exit debug spew for
  153. //                          functions that return an HRESULT.
  154. //
  155. #define DBG_EXIT_HRES(szFn, hres)                   
  156.         TRACE_MSG(TF_FUNC, " < " szFn "() with %s", Dbg_GetScode(hres))
  157. #else
  158. #define ASSERT(f)
  159. #define ASSERT_E(f)      (f)
  160. #define ASSERT_MSG   1 ? (void)0 : (void)
  161. #define DEBUG_MSG    1 ? (void)0 : (void)
  162. #define TRACE_MSG    1 ? (void)0 : (void)
  163. #define VERIFYSZ(f, szFmt, x)     (f)
  164. #define DBG_ENTER(szFn)
  165. #define DBG_ENTER_SZ(szFn, sz)
  166. #define DBG_ENTER_RIID(szFn, riid)   
  167. #define DBG_EXIT(szFn)                            
  168. #define DBG_EXIT_US(szFn, us)
  169. #define DBG_EXIT_UL(szFn, ul)
  170. #define DBG_EXIT_PTR(szFn, ptr)                            
  171. #define DBG_EXIT_HRES(szFn, hres)   
  172. #endif
  173. /////////////////////////////////////////////////////  TYPEDEFS
  174. /////////////////////////////////////////////////////  EXPORTED DATA
  175. /////////////////////////////////////////////////////  PUBLIC PROTOTYPES
  176. #ifdef DEBUG
  177. void PUBLIC DEBUG_BREAK(UINT flag);
  178. LPCSTR PUBLIC Dbg_GetRiidName(REFIID riid);
  179. LPCSTR PUBLIC Dbg_GetScode(HRESULT hres);
  180. LPCSTR PUBLIC Dbg_SafeStr(LPCSTR psz);
  181. #endif
  182. int PUBLIC MsgBoxIds (HWND hwndParent, UINT ids, UINT idsCaption, UINT nBoxType);
  183. int PUBLIC MsgBoxSz (HWND hwndParent, LPCSTR lpsz, UINT idsCaption, UINT nBoxType, HANDLE hinst);
  184. #endif // __ERR_H__