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.

143 lines
4.9 KiB

  1. //---------------------------------------------------------------------------
  2. // ParamChecks.h
  3. //---------------------------------------------------------------------------
  4. // these param checkers are needed for both RETAIL and DEBUG
  5. //---------------------------------------------------------------------------
  6. // CThemeApiHelper class:
  7. // - automatically logs entry/exit to function
  8. // - automatically does a "CloseHandle" on pRenderObj at exit
  9. // - holds _pszFuncName for use by param validating macros
  10. //---------------------------------------------------------------------------
  11. class CThemeApiHelper
  12. {
  13. public:
  14. inline CThemeApiHelper(LPCWSTR pszFuncName, HTHEME hTheme)
  15. {
  16. _iRenderSlotNum = -1; // not yet set
  17. _pszFuncName = pszFuncName;
  18. if (! hTheme)
  19. {
  20. LogEntryW(_pszFuncName);
  21. }
  22. }
  23. inline ~CThemeApiHelper()
  24. {
  25. CloseHandle();
  26. LogExit(_pszFuncName);
  27. }
  28. inline HRESULT OpenHandle(HTHEME hTheme, CRenderObj **ppRenderObj)
  29. {
  30. CloseHandle();
  31. HRESULT hr = g_pRenderList->OpenThemeHandle(hTheme,
  32. ppRenderObj, &_iRenderSlotNum);
  33. if (SUCCEEDED(hr))
  34. {
  35. LogEntryCW(_pszFuncName, CLASSPTR(*ppRenderObj));
  36. }
  37. else
  38. {
  39. Log(LOG_PARAMS, L"Bad HTHEME param in call to %s", _pszFuncName);
  40. }
  41. return hr;
  42. }
  43. inline void CloseHandle()
  44. {
  45. if (_iRenderSlotNum > -1)
  46. {
  47. g_pRenderList->CloseThemeHandle(_iRenderSlotNum);
  48. _iRenderSlotNum = -1;
  49. }
  50. }
  51. public:
  52. LPCWSTR _pszFuncName;
  53. private:
  54. int _iRenderSlotNum;
  55. int _iEntryValue; // for log resource leak checking
  56. };
  57. //---------------------------------------------------------------------------
  58. //---------------------------------------------------------------------------
  59. //---------------------------------------------------------------------------
  60. #ifdef DEBUG
  61. #define APIHELPER(Name, hTheme) CThemeApiHelper ApiHelper(Name, hTheme)
  62. #else
  63. #define APIHELPER(Name, hTheme) CThemeApiHelper ApiHelper(NULL, hTheme)
  64. #endif
  65. //---------------------------------------------------------------------------
  66. #define VALIDATE_THEME_HANDLE(helper, hTheme, ppRenderObj) \
  67. { \
  68. HRESULT hr = helper.OpenHandle(hTheme, ppRenderObj); \
  69. RETURN_VALIDATE_RETVAL(hr); \
  70. }
  71. //---------------------------------------------------------------------------
  72. #define VALIDATE_READ_PTR(helper, p, iSize) \
  73. { \
  74. if (IsBadReadPtr(p, iSize)) \
  75. { \
  76. Log(LOG_PARAMS, L"Bad output PTR param in call to %s", helper._pszFuncName); \
  77. RETURN_VALIDATE_RETVAL(E_POINTER); \
  78. } \
  79. }
  80. //---------------------------------------------------------------------------
  81. #define VALIDATE_WRITE_PTR(helper, p, iSize) \
  82. { \
  83. if (IsBadWritePtr(p, iSize)) \
  84. { \
  85. Log(LOG_PARAMS, L"Bad output PTR param in call to %s", helper._pszFuncName); \
  86. RETURN_VALIDATE_RETVAL(E_POINTER); \
  87. } \
  88. }
  89. //---------------------------------------------------------------------------
  90. #define VALIDATE_INPUT_STRING(helper, psz, cchMax) \
  91. { \
  92. if (IsBadStringPtr(psz, cchMax)) \
  93. { \
  94. Log(LOG_PARAMS, L"Bad input STRING param in call to: %s", helper._pszFuncName); \
  95. RETURN_VALIDATE_RETVAL(E_POINTER); \
  96. } \
  97. }
  98. #define VALIDATE_INPUT_UNLIMITED_STRING(helper, psz) VALIDATE_INPUT_STRING(helper, psz, UNICODE_STRING_MAX_CHARS)
  99. //---------------------------------------------------------------------------
  100. #define VALIDATE_HDC(helper, hdc) \
  101. { \
  102. if (! hdc) \
  103. { \
  104. Log(LOG_PARAMS, L"Bad HDC param in call to %s", helper._pszFuncName ); \
  105. RETURN_VALIDATE_RETVAL(E_HANDLE); \
  106. } \
  107. }
  108. //---------------------------------------------------------------------------
  109. #define VALIDATE_HANDLE(helper, h) \
  110. { \
  111. if (! h) \
  112. { \
  113. Log(LOG_PARAMS, L"Bad HANDLE param in call to %s", helper._pszFuncName); \
  114. RETURN_VALIDATE_RETVAL(E_HANDLE); \
  115. } \
  116. }
  117. //---------------------------------------------------------------------------
  118. #define VALIDATE_HWND(helper, hwnd) \
  119. { \
  120. if (! IsWindow(hwnd)) \
  121. { \
  122. Log(LOG_PARAMS, L"Bad HWND handle param in call to: %s", helper._pszFuncName); \
  123. RETURN_VALIDATE_RETVAL(E_HANDLE); \
  124. } \
  125. }
  126. //---------------------------------------------------------------------------
  127. #define VALIDATE_CALLBACK(helper, pfn) \
  128. { \
  129. if (IsBadCodePtr((FARPROC)pfn)) \
  130. { \
  131. Log(LOG_PARAMS, L"Bad CALLBACK param in call to %s", helper._pszFuncName); \
  132. RETURN_VALIDATE_RETVAL(E_POINTER); \
  133. } \
  134. }
  135. //---------------------------------------------------------------------------