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.

203 lines
5.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: srheader.hxx
  7. //
  8. // Contents: Common precompiled header for all System Restore Test utilities
  9. // and applications.
  10. //
  11. // Notes:
  12. //
  13. // History: 6-29-2000 jgreen Created
  14. // 9-15-2000 annah Added defines for compatibility
  15. // with STL.
  16. //
  17. //----------------------------------------------------------------------------
  18. #ifndef _CSRHEADER
  19. #define _CSRHEADER
  20. #include <nt.h>
  21. #include <ntrtl.h>
  22. #include <nturtl.h>
  23. #include <ntioapi.h>
  24. #include "killwarn.h" // Kill useless informational warnings
  25. #include <windows.h> // For Win32 functions
  26. #include <windowsx.h> // UI/control helper functions
  27. #include <stdio.h> // For STDIO stuff
  28. #include <stdarg.h>
  29. #include <stdlib.h> // For STDLIB stuff
  30. #include <malloc.h>
  31. #include <memory.h>
  32. #include <string.h>
  33. #include <direct.h>
  34. #include <ctype.h>
  35. #include <time.h>
  36. #include <math.h>
  37. #include <tchar.h> // For TCHAR functions
  38. #include <limits.h>
  39. #include <io.h>
  40. #include <assert.h>
  41. #include <commctrl.h> // Common controls
  42. #include <commdlg.h>
  43. #include <shlwapi.h> // shell utility api
  44. #include "tstparam.hxx" // CTestParams parameter container
  45. #ifndef ARRAYSIZE
  46. #define ARRAYSIZE(ar) sizeof(ar)/sizeof(ar[0])
  47. #endif
  48. // BUGs on ole headers. Fix it here.
  49. #undef OLESTR
  50. #undef __OLESTR
  51. #ifndef _MAC
  52. #define __OLESTR(str) L##str
  53. #else
  54. #define __OLESTR(str) str
  55. #endif //_MAC
  56. #define OLESTR(str) __OLESTR(str)
  57. // Definition for compatibility of TCHAR with STL
  58. #ifdef UNICODE
  59. #define TSTRING wstring
  60. #else
  61. #define TSTRING string
  62. #endif
  63. //--------------------------------------------------------------------------
  64. // Macros
  65. //--------------------------------------------------------------------------
  66. #define DH_VDATEPTRIN( ptr, type ) \
  67. { \
  68. if ((NULL == ptr) || (FALSE != IsBadReadPtr(ptr, sizeof(type)))) \
  69. { \
  70. return E_INVALIDARG ; \
  71. } \
  72. }
  73. #define DH_VDATEPTROUT( ptr, type ) \
  74. { \
  75. if ((NULL == ptr) || (FALSE != IsBadWritePtr(ptr, sizeof(type)))) \
  76. { \
  77. return E_INVALIDARG ; \
  78. } \
  79. }
  80. #define DH_ABORTIF(condition,err_code,msg) \
  81. { \
  82. if ((condition)) \
  83. { \
  84. hr=err_code; \
  85. if (S_OK == hr) \
  86. { \
  87. hr = E_FAIL; \
  88. } \
  89. goto ErrReturn; \
  90. } \
  91. }
  92. #define DH_HRCHECK_ABORT(hresult,message) \
  93. { \
  94. if (S_OK != hresult) \
  95. { \
  96. hr = hresult; \
  97. goto ErrReturn; \
  98. } \
  99. }
  100. #define DH_ABORT_ALWAYS(err_code,msg) \
  101. { \
  102. hr = err_code; \
  103. goto ErrReturn; \
  104. }
  105. #define DH_ASSERT(cond) \
  106. { \
  107. assert(cond); \
  108. }
  109. //--------------------------------------------------------------------------
  110. // Inline functions
  111. //--------------------------------------------------------------------------
  112. inline void CleanupTStr(LPTSTR *ptszToClean)
  113. {
  114. if (NULL != *ptszToClean)
  115. {
  116. delete [] *ptszToClean;
  117. *ptszToClean = NULL;
  118. }
  119. }
  120. inline void CleanupStr(LPSTR *pszToClean)
  121. {
  122. if (NULL != *pszToClean)
  123. {
  124. delete [] *pszToClean;
  125. *pszToClean = NULL;
  126. }
  127. }
  128. inline void CleanupWStr(LPWSTR *pwszToClean)
  129. {
  130. if (NULL != *pwszToClean)
  131. {
  132. delete [] *pwszToClean;
  133. *pwszToClean = NULL;
  134. }
  135. }
  136. inline void CleanupHandle(HANDLE &Hnd)
  137. {
  138. if (INVALID_HANDLE_VALUE != Hnd)
  139. {
  140. CloseHandle(Hnd);
  141. Hnd = INVALID_HANDLE_VALUE;
  142. }
  143. }
  144. inline void CleanupNullHandle(HANDLE &Hnd)
  145. {
  146. if (NULL != Hnd)
  147. {
  148. CloseHandle(Hnd);
  149. Hnd = NULL;
  150. }
  151. }
  152. inline void CleanupBlock(PVOID &rpvBlock)
  153. {
  154. if (NULL != rpvBlock)
  155. {
  156. delete [] rpvBlock;
  157. rpvBlock = NULL;
  158. }
  159. }
  160. //--------------------------------------------------------------------------
  161. // Function prototypes
  162. //--------------------------------------------------------------------------
  163. HRESULT SrTstStrCat(IN LPCSTR szStr1,
  164. IN LPCSTR szStr2,
  165. OUT LPSTR *ppDest);
  166. HRESULT SrTstTStrCat(IN LPCTSTR szStr1,
  167. IN LPCTSTR szStr2,
  168. OUT LPTSTR *ppDest);
  169. HRESULT CopyString(LPCWSTR, LPSTR *);
  170. HRESULT CopyString(LPCSTR, LPWSTR *);
  171. HRESULT CopyString(LPCSTR, LPSTR *);
  172. HRESULT CopyString(LPCWSTR, LPWSTR *);
  173. #endif