Source code of Windows XP (NT5)
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.

245 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1994-1995 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. Common.hxx
  6. Abstract:
  7. Standard macros/typedefs for include files.
  8. Author:
  9. Albert Ting (AlbertT)
  10. Revision History:
  11. --*/
  12. #ifndef _COMMON_HXX
  13. #define _COMMON_HXX
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef
  18. HANDLE (WINAPI *pfCreateThread)(
  19. LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes
  20. SIZE_T dwStackSize, // initial thread stack size, in bytes
  21. LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function
  22. LPVOID lpParameter, // argument for new thread
  23. DWORD dwCreationFlags, // creation flags
  24. LPDWORD lpThreadId // pointer to returned thread identifier
  25. );
  26. BOOL
  27. bSplLibInit(
  28. #ifdef __cplusplus
  29. pfCreateThread pfSafeCreateThread = NULL
  30. #else
  31. pfCreateThread pfSafeCreateThread
  32. #endif
  33. );
  34. VOID
  35. vSplLibFree(
  36. VOID
  37. );
  38. EXTERN_C
  39. DWORD
  40. WINAPIV
  41. StrCatAlloc(
  42. IN OUT PCTSTR *ppszString,
  43. ...
  44. );
  45. EXTERN_C
  46. DWORD
  47. WINAPIV
  48. StrNCatBuff(
  49. IN PTSTR pszBuffer,
  50. IN UINT cchBuffer,
  51. ...
  52. );
  53. typedef enum {
  54. kWindowsDir,
  55. kSystemWindowsDir,
  56. kSystemDir,
  57. kCurrentDir
  58. } EStrCatDir;
  59. EXTERN_C
  60. DWORD
  61. WINAPI
  62. StrCatSystemPath(
  63. IN LPCTSTR pszFile,
  64. IN EStrCatDir eDir,
  65. OUT LPTSTR *ppszFullPath
  66. );
  67. EXTERN_C
  68. PTSTR
  69. SubChar(
  70. IN PCTSTR pszIn,
  71. IN TCHAR cIn,
  72. IN TCHAR cOut
  73. );
  74. EXTERN_C
  75. HRESULT
  76. GetLastErrorAsHResult(
  77. VOID
  78. );
  79. EXTERN_C
  80. HRESULT
  81. HResultFromWin32(
  82. IN DWORD dwError
  83. );
  84. EXTERN_C
  85. HRESULT
  86. GetLastErrorAsHResultAndFail(
  87. void
  88. );
  89. EXTERN_C
  90. HRESULT
  91. GetFileNamePart(
  92. IN PCWSTR pszFullPath,
  93. OUT PCWSTR *ppszFileName
  94. );
  95. EXTERN_C
  96. BOOL
  97. BoolFromHResult(
  98. IN HRESULT hr
  99. );
  100. EXTERN_C
  101. DWORD
  102. StatusFromHResult(
  103. IN HRESULT hr
  104. );
  105. EXTERN_C
  106. BOOL
  107. BoolFromStatus(
  108. IN DWORD Status
  109. );
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #include "dbgmsg.h"
  114. //
  115. // This reverses a DWORD so that the bytes can be easily read
  116. // as characters ('prnt' can be read from debugger forward).
  117. //
  118. #define BYTE_SWAP_DWORD( val ) \
  119. ( (val & 0xff) << 24 | \
  120. (val & 0xff00) << 8 | \
  121. (val & 0xff0000) >> 8 | \
  122. (val & 0xff000000) >> 24 )
  123. #define COUNTOF(x) (sizeof(x)/sizeof(*x))
  124. #define BITCOUNTOF(x) (sizeof(x)*8)
  125. #define COUNT2BYTES(x) ((x)*sizeof(TCHAR))
  126. #define OFFSETOF(type, id) ((DWORD)(ULONG_PTR)(&(((type*)0)->id)))
  127. #define OFFSETOF_BASE(type, baseclass) ((DWORD)(ULONG_PTR)((baseclass*)((type*)0x10))-0x10)
  128. #define ERRORP(Status) (Status != ERROR_SUCCESS)
  129. #define SUCCESSP(Status) (Status == ERROR_SUCCESS)
  130. //
  131. // COUNT and COUNT BYTES
  132. //
  133. typedef UINT COUNT, *PCOUNT;
  134. typedef UINT COUNTB, *PCOUNTB;
  135. typedef DWORD STATUS;
  136. //
  137. // Conversion between PPM (Page per minute), LPM (Line per minute)
  138. // and CPS (Character per second)
  139. //
  140. #define CPS2PPM(x) ((x)/48)
  141. #define LPM2PPM(x) ((x)/48)
  142. //
  143. // C++ specific functionality.
  144. //
  145. #ifdef __cplusplus
  146. const DWORD kStrMax = MAX_PATH;
  147. #if defined( CHECKMEM ) || DBG
  148. #define SAFE_NEW \
  149. public: \
  150. PVOID operator new(size_t size) { return ::SafeNew(size); } \
  151. VOID operator delete(PVOID p, size_t) { ::SafeDelete(p); } \
  152. private:
  153. #define DBG_SAFE_NEW \
  154. public: \
  155. PVOID operator new(size_t size) { return ::DbgAllocMem(size); } \
  156. VOID operator delete(PVOID p, size_t) { ::DbgFreeMem(p); } \
  157. private:
  158. #else
  159. #define SAFE_NEW
  160. #define DBG_SAFE_NEW
  161. #endif
  162. #define SIGNATURE( sig ) \
  163. public: \
  164. class TSignature { \
  165. public: \
  166. DWORD _Signature; \
  167. TSignature() : _Signature( BYTE_SWAP_DWORD( sig )) { } \
  168. }; \
  169. TSignature _Signature; \
  170. \
  171. BOOL bSigCheck() const \
  172. { return _Signature._Signature == BYTE_SWAP_DWORD( sig ); } \
  173. private:
  174. #define ALWAYS_VALID \
  175. public: \
  176. BOOL bValid() const \
  177. { return TRUE; } \
  178. private:
  179. #define VAR(type,var) \
  180. inline type& var() \
  181. { return _##var; } \
  182. inline type const & var() const \
  183. { return _##var; } \
  184. type _##var
  185. #define SVAR(type,var) \
  186. static inline type& var() \
  187. { return _##var; } \
  188. static type _##var
  189. //
  190. // Allow debug extensions to be friends of all classes so that
  191. // they can dump private fields. Forward class definition here.
  192. //
  193. class TDebugExt;
  194. //
  195. // Include any common inlines.
  196. //
  197. #include "commonil.hxx"
  198. #endif // def __cplusplus
  199. #endif // _COMMON_HXX