Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.7 KiB

  1. /****************************************************************************
  2. **
  3. ** File: STDASSRT.H
  4. ** Purpose: Standard Assert macros and common error handling defines.
  5. ** Notes:
  6. **
  7. ****************************************************************************/
  8. #ifndef STDASSRT_H
  9. #define STDASSRT_H
  10. #ifdef __cplusplus
  11. extern "C" { /* Assume C declarations for C++ */
  12. #endif
  13. /* REVIEW: need to make this DEBUG only when RTChkArg is removed */
  14. #define EnableAssertCode static char THIS_FILE[] = __FILE__;
  15. /* Common Error Validation and Handling */
  16. typedef enum {
  17. vrcFail = 0, /* if IDOK or IDIGNORE or IDNO or no message box */
  18. vrcValid = 1, /* if no error condition */
  19. vrcRetry = 2, /* if IDRETRY or IDYES */
  20. vrcQuit = 3, /* if IDABORT or IDCANCEL */
  21. vrcYes = vrcRetry,
  22. vrcNo = vrcFail,
  23. vrcIgnore= vrcFail,
  24. vrcCancel= vrcQuit,
  25. vrcAbort = vrcQuit,
  26. vrcOk = vrcFail
  27. } VRC;
  28. #define ERROR_PARAM_MAX 4 /* parameters %1, %2, %3, %4 */
  29. /* sets an error parameter from a temp string value, good until Validate() */
  30. VOID PUBLIC SetErrorParam ( UINT iParam, SZC szValue );
  31. /* sets an error parameter from a stable string value, can Validate() later */
  32. VOID PUBLIC SetErrorParamConst ( UINT iParam, CSZC szValue );
  33. /* sets an error message parameter from a string value, make a string copy */
  34. VOID PUBLIC SetErrorParamCopy ( UINT iParam, SZC szValue );
  35. /* sets an error message parameter from an integer value */
  36. VOID PUBLIC SetErrorParamInt ( UINT iParam, INT iValue );
  37. /* sets an error message parameter from an character value */
  38. VOID PUBLIC SetErrorParamChar ( UINT iParam, CHAR chValue );
  39. /* tests a condition, handles error and clears error parameters if false */
  40. VRC PUBLIC Validate ( BOOL fCondition, UINT iStringId );
  41. /* loads a string resource or debug string, calls ProcessMessage() */
  42. VRC PUBLIC ProcessMessageId ( UINT iStringId );
  43. /* formats message template, optionally displays message box, write to log */
  44. VRC PUBLIC ProcessMessage ( SZC szMsg );
  45. /* loads a debug or resource message and writes to the logfile if open */
  46. VRC PUBLIC LogMessageId ( UINT iResId ); /* return status of log write */
  47. /* loads a message, sets status for %V & %v, writes to the logfile if open */
  48. VRC PUBLIC LogValidate ( BOOL fCondition, UINT iResId );/* return log status */
  49. /* prototype for callback to obtain object or pass-specific information */
  50. /* returns the number of characters copied to the buffer, or 0 if no info */
  51. typedef INT (WINAPI *PFNErrorParam)( INT chParam, SZ rgchBuf );
  52. /* entry for ACME only, to setup pass calback for error parameters */
  53. VOID PUBLIC SetPassInfo(SZC szPassName, PFNErrorParam pfnCallback);
  54. /* internal entry to process debug messages, called using DebugMessage(sz) */
  55. VRC PUBLIC ProcessDebugMessage ( SZC szMsg );
  56. /* Sets and gets global last-error message */
  57. VOID PUBLIC SetLastSetupErrMsg ( SZ szMsg );
  58. SZ PUBLIC SzGetLastSetupErrMsg ( VOID );
  59. /* entry for ACME only, to setup pass calback for FED Font change - DBCS only*/
  60. typedef BOOL (WINAPI *PFNFEFont)( HWND hdlg );
  61. VOID PUBLIC SetFEFontProc(PFNFEFont pfnCallback);
  62. /* Bit flag, combined with message IDS values to specify messages that
  63. * should be stored into the LastSetupErrMsg buffer in ProcessMessageId.
  64. * Also macros to test, clear and set the bit flag.
  65. *
  66. * NOTE: 1 << 8 through 8 << 16 are reserved for ProcessMessageId
  67. * internal use. (See setupdll\_assert.h)
  68. */
  69. #define midErrMsg (16 << 16)
  70. #define FIsErrMsg(id) (id & midErrMsg)
  71. #define IdClearErrMsg(id) (id & (~midErrMsg))
  72. #define IdErrMsg(id) (id | midErrMsg)
  73. #ifdef DEBUG
  74. # define DebugErrorParam(p,v) SetErrorParam(p,v)
  75. # define DebugErrorParamCopy(p,v) SetErrorParamCopy(p,v)
  76. # define DebugErrorParamConst(p,v) SetErrorParamConst(p,v)
  77. # define DebugErrorParamInt(p,v) SetErrorParamInt(p,v)
  78. # define DebugErrorParamChar(p,v) SetErrorParamChar(p,v)
  79. # define DebugMessageId(i) ProcessMessageId(i)
  80. # define DebugMessage(s) ProcessDebugMessage(s)
  81. # define DebugLogMessageId(i) LogMessageId(i)
  82. #else
  83. # define DebugErrorParam(p,v)
  84. # define DebugErrorParamCopy(p,v)
  85. # define DebugErrorParamConst(p,v)
  86. # define DebugErrorParamInt(p,v)
  87. # define DebugErrorParamChar(p,v)
  88. # define DebugMessageId(i)
  89. # define DebugMessage(s)
  90. # define DebugLogMessageId(i)
  91. #endif
  92. #ifdef DEBUG
  93. BOOL PUBLIC ResponseFile ( SZ szFile );
  94. #endif
  95. /* Must call as the first call (with hinstAcme) AND as the last
  96. * call (with hinstNull).
  97. */
  98. BOOL PUBLIC SetAcmeInst(HINSTANCE hInst, LPSTR szCmdLine);
  99. /* RunTime Argument Checking */
  100. /* REVIEW: this should be removed, all uses replaced by calls to Validate */
  101. #define RTChkArg(f, retVal) \
  102. { if (!(f)) { FailRTChkArg(THIS_FILE, __LINE__); return (retVal); } }
  103. VRC PUBLIC FailRTChkArg ( SZC szFile, UINT uiLine );
  104. /* Assert macros */
  105. VOID PUBLIC FailAssert (SZC szFile, UINT uiLine ); /* also PreCond, BadParam */
  106. #ifdef DEBUG
  107. #define FailAssertObj(f, l, i) FailAssert(f, (UINT)(l + ((i)<<16)))
  108. #define FailChkArg(f, l, i) FailAssert(f, (UINT)(l + (1<<31) + ((i)<<16)))
  109. #define FailPreCond(f, l) FailAssert(f, (UINT)(l + (1<<31)))
  110. #define Assert(f) ((f) ? (VOID)0 : (VOID)FailAssert(THIS_FILE, __LINE__))
  111. #define EvalAssert(f) ((f) ? (VOID)0 : (VOID)FailAssert(THIS_FILE, __LINE__))
  112. #define AssertRet(f, retVal) \
  113. {if (!(f)) {FailAssert( THIS_FILE, __LINE__); return (retVal);} }
  114. #define EvalAssertRet(f, retVal) \
  115. {if (!(f)) {FailAssert( THIS_FILE, __LINE__); return (retVal);} }
  116. #define PreCondition(f, retVal) \
  117. {if (!(f)) {FailPreCond(THIS_FILE, __LINE__); return (retVal);} }
  118. #define ChkArg(f, iArg, retVal) \
  119. {if (!(f)) {FailChkArg(THIS_FILE, __LINE__, iArg); return (retVal);} }
  120. #else
  121. #define Assert(f)
  122. #define EvalAssert(f) ((VOID)(f))
  123. #define AssertRet( f, retVal)
  124. #define EvalAssertRet(f, retVal) ((VOID)(f))
  125. #define PreCondition( f, retVal) RTChkArg(f, retVal)
  126. #define ChkArg( f, iArg, retVal)
  127. #endif
  128. /* REVIEW: These are obsolete, remove when files using them are updated */
  129. #ifdef DEBUG
  130. #define DisplayAssertMsg() Assert(fFalse);
  131. #define DebugLine(expr) expr;
  132. #define DisplayErrorMsg(sz) ((VOID)FDisplaySystemMsg(sz))
  133. #else
  134. #define DisplayAssertMsg() /* in objodbc.cpp, copylist.c */
  135. #define DebugLine(expr) /* once in copylist.c */
  136. #define DisplayErrorMsg(sz)
  137. #endif
  138. extern BOOL WINAPI FDisplaySystemMsg ( SZ szErr );
  139. #ifdef DEVELOPER
  140. #define BadArgErr(nArg, szApi, szArgs) SetupApiErr(nArg+saeMax, szApi, szArgs)
  141. #else
  142. #define BadArgErr(nArg, szApi, szArgs)
  143. #endif
  144. /* REVIEW: end of obsolete */
  145. #ifdef __cplusplus
  146. } /* End of extern "C" { */
  147. #endif
  148. #endif /* STDASSRT_H */