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.

264 lines
8.1 KiB

  1. /*
  2. * stock.h - Stock header file.
  3. */
  4. /* Constants
  5. ************/
  6. #define FOREVER for (;;)
  7. #define INVALID_SEEK_POSITION (0xffffffff)
  8. #define EMPTY_STRING ""
  9. #ifdef DEBUG
  10. #define NULL_STRING "(null)"
  11. #endif
  12. #define SLASH_SLASH "\\\\"
  13. #define ASTERISK '*'
  14. #define BACKSLASH '/'
  15. #define COLON ':'
  16. #define COMMA ','
  17. #define EQUAL '='
  18. #define PERIOD '.'
  19. #define POUND '#'
  20. #define QMARK '?'
  21. #define QUOTE '\''
  22. #define QUOTES '"'
  23. #define SLASH '\\'
  24. #define SPACE ' '
  25. #define TAB '\t'
  26. /* linkage */
  27. /* #pragma data_seg() doesn't work for variables defined extern. */
  28. #define PUBLIC_CODE
  29. #define PUBLIC_DATA
  30. /* Make private functions and data public for profiling and debugging. */
  31. #define PRIVATE_CODE PUBLIC_CODE
  32. #define PRIVATE_DATA PUBLIC_DATA
  33. #ifdef __cplusplus
  34. #define INLINE inline
  35. #else
  36. #define INLINE __inline
  37. #endif
  38. /* limits */
  39. #define WORD_MAX USHRT_MAX
  40. #define DWORD_MAX ULONG_MAX
  41. /* file system constants */
  42. #define MAX_BUF 260
  43. #define MAX_PATH_LEN MAX_PATH
  44. #define MAX_NAME_LEN MAX_PATH
  45. #define MAX_FOLDER_DEPTH (MAX_PATH / 2)
  46. #define DRIVE_ROOT_PATH_LEN (4)
  47. /* ui constants */
  48. #define MAX_MSG_LEN MAX_PATH_LEN
  49. /* invalid thread ID */
  50. #define INVALID_THREAD_ID (0xffffffff)
  51. /* no context-sensitive help available */
  52. #define NO_HELP ((DWORD)-1)
  53. /* Win32 HRESULTs */
  54. #define E_FILE_NOT_FOUND MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32, ERROR_FILE_NOT_FOUND)
  55. #define E_PATH_NOT_FOUND MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32, ERROR_PATH_NOT_FOUND)
  56. /* file-related flag combinations */
  57. #define ALL_FILE_ACCESS_FLAGS (GENERIC_READ |\
  58. GENERIC_WRITE)
  59. #define ALL_FILE_SHARING_FLAGS (FILE_SHARE_READ |\
  60. FILE_SHARE_WRITE)
  61. #define ALL_FILE_ATTRIBUTES (FILE_ATTRIBUTE_READONLY |\
  62. FILE_ATTRIBUTE_HIDDEN |\
  63. FILE_ATTRIBUTE_SYSTEM |\
  64. FILE_ATTRIBUTE_DIRECTORY |\
  65. FILE_ATTRIBUTE_ARCHIVE |\
  66. FILE_ATTRIBUTE_NORMAL |\
  67. FILE_ATTRIBUTE_TEMPORARY |\
  68. FILE_ATTRIBUTE_ATOMIC_WRITE |\
  69. FILE_ATTRIBUTE_XACTION_WRITE)
  70. #define ALL_FILE_FLAGS (FILE_FLAG_WRITE_THROUGH |\
  71. FILE_FLAG_OVERLAPPED |\
  72. FILE_FLAG_NO_BUFFERING |\
  73. FILE_FLAG_RANDOM_ACCESS |\
  74. FILE_FLAG_SEQUENTIAL_SCAN |\
  75. FILE_FLAG_DELETE_ON_CLOSE |\
  76. FILE_FLAG_BACKUP_SEMANTICS |\
  77. FILE_FLAG_POSIX_SEMANTICS)
  78. #define ALL_FILE_ATTRIBUTES_AND_FLAGS (ALL_FILE_ATTRIBUTES |\
  79. ALL_FILE_FLAGS)
  80. /* Macros
  81. *********/
  82. #ifndef DECLARE_STANDARD_TYPES
  83. /*
  84. * For a type "FOO", define the standard derived types PFOO, CFOO, and PCFOO.
  85. */
  86. #define DECLARE_STANDARD_TYPES(type) typedef type *P##type; \
  87. typedef const type C##type; \
  88. typedef const type *PC##type;
  89. #endif
  90. /*
  91. * For a type "FOO", define the standard derived UNALIGNED types PFOO, CFOO, and PCFOO.
  92. * WINNT: RISC boxes care about ALIGNED, intel does not.
  93. */
  94. #define DECLARE_STANDARD_TYPES_U(type) typedef UNALIGNED type *P##type; \
  95. typedef UNALIGNED const type C##type; \
  96. typedef UNALIGNED const type *PC##type;
  97. /* character manipulation */
  98. #define IS_SLASH(ch) ((ch) == SLASH || (ch) == BACKSLASH)
  99. #ifdef InRange
  100. #undef InRange
  101. #endif
  102. #define InRange(id, idFirst, idLast) ((UINT)(id-idFirst) <= (UINT)(idLast-idFirst))
  103. /* bit flag manipulation */
  104. #define SET_FLAG(dwAllFlags, dwFlag) ((dwAllFlags) |= (dwFlag))
  105. #define CLEAR_FLAG(dwAllFlags, dwFlag) ((dwAllFlags) &= (~dwFlag))
  106. #define IS_FLAG_SET(dwAllFlags, dwFlag) ((BOOL)((dwAllFlags) & (dwFlag)))
  107. #define IS_FLAG_CLEAR(dwAllFlags, dwFlag) (! (IS_FLAG_SET(dwAllFlags, dwFlag)))
  108. #define SetFlag SET_FLAG
  109. #define ClearFlag CLEAR_FLAG
  110. #define IsFlagSet IS_FLAG_SET
  111. #define IsFlagClear IS_FLAG_CLEAR
  112. /* array element count */
  113. #define ARRAY_ELEMENTS(rg) (sizeof(rg) / sizeof((rg)[0]))
  114. #ifdef SIZECHARS
  115. #undef SIZECHARS
  116. #endif
  117. #define SIZECHARS(rg) ARRAY_ELEMENTS(rg)
  118. /* string safety */
  119. #define CHECK_STRING(psz) ((psz) ? (psz) : NULL_STRING)
  120. /* file attribute manipulation */
  121. #define IS_ATTR_DIR(attr) (IS_FLAG_SET((attr), FILE_ATTRIBUTE_DIRECTORY))
  122. #define IS_ATTR_VOLUME(attr) (IS_FLAG_SET((attr), FILE_ATTRIBUTE_VOLUME))
  123. /* stuff a point value packed in an LPARAM into a POINT */
  124. #define LPARAM_TO_POINT(lparam, pt) ((pt).x = (short)LOWORD(lparam), \
  125. (pt).y = (short)HIWORD(lparam))
  126. /* use the Win32 API string equivalents */
  127. #define lstrnicmp(sz1, sz2, cch) (CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, sz1, cch, sz2, cch) - 2)
  128. #define lstrncmp(sz1, sz2, cch) (CompareString(LOCALE_USER_DEFAULT, 0, sz1, cch, sz2, cch) - 2)
  129. // Count of characters to count of bytes
  130. //
  131. #define CbFromCchW(cch) ((cch)*sizeof(WCHAR))
  132. #define CbFromCchA(cch) ((cch)*sizeof(CHAR))
  133. #ifdef UNICODE
  134. #define CbFromCch CbFromCchW
  135. #else // UNICODE
  136. #define CbFromCch CbFromCchA
  137. #endif // UNICODE
  138. //
  139. // SAFECAST(obj, type)
  140. //
  141. // This macro is extremely useful for enforcing strong typechecking on other
  142. // macros. It generates no code.
  143. //
  144. // Simply insert this macro at the beginning of an expression list for
  145. // each parameter that must be typechecked. For example, for the
  146. // definition of MYMAX(x, y), where x and y absolutely must be integers,
  147. // use:
  148. //
  149. // #define MYMAX(x, y) (SAFECAST(x, int), SAFECAST(y, int), ((x) > (y) ? (x) : (y)))
  150. //
  151. //
  152. #define SAFECAST(_obj, _type) (((_type)(_obj)==(_obj)?0:0), (_type)(_obj))
  153. /* Types
  154. ********/
  155. typedef const void *PCVOID;
  156. typedef const INT CINT;
  157. typedef const INT *PCINT;
  158. typedef const UINT CUINT;
  159. typedef const UINT *PCUINT;
  160. typedef const LONG CULONG;
  161. typedef const LONG *PCULONG;
  162. typedef const BYTE CBYTE;
  163. typedef const BYTE *PCBYTE;
  164. typedef const WORD CWORD;
  165. typedef const WORD *PCWORD;
  166. typedef const DWORD CDWORD;
  167. typedef const DWORD *PCDWORD;
  168. typedef const CRITICAL_SECTION CCRITICAL_SECTION;
  169. typedef const CRITICAL_SECTION *PCCRITICAL_SECTION;
  170. typedef const FILETIME CFILETIME;
  171. typedef const FILETIME *PCFILETIME;
  172. typedef const BITMAPINFO CBITMAPINFO;
  173. typedef const BITMAPINFO *PCBITMAPINFO;
  174. typedef const POINT CPOINT;
  175. typedef const POINT *PCPOINT;
  176. typedef const POINTL CPOINTL;
  177. typedef const POINTL *PCPOINTL;
  178. typedef const SECURITY_ATTRIBUTES CSECURITY_ATTRIBUTES;
  179. typedef const SECURITY_ATTRIBUTES *PCSECURITY_ATTRIBUTES;
  180. typedef const WIN32_FIND_DATA CWIN32_FIND_DATA;
  181. typedef const WIN32_FIND_DATA *PCWIN32_FIND_DATA;
  182. DECLARE_STANDARD_TYPES(HGLOBAL);
  183. DECLARE_STANDARD_TYPES(HICON);
  184. DECLARE_STANDARD_TYPES(HMENU);
  185. DECLARE_STANDARD_TYPES(HWND);
  186. DECLARE_STANDARD_TYPES(NMHDR);
  187. #ifndef _COMPARISONRESULT_DEFINED_
  188. /* comparison result */
  189. typedef enum _comparisonresult
  190. {
  191. CR_FIRST_SMALLER = -1,
  192. CR_EQUAL = 0,
  193. CR_FIRST_LARGER = +1
  194. }
  195. COMPARISONRESULT;
  196. DECLARE_STANDARD_TYPES(COMPARISONRESULT);
  197. #define _COMPARISONRESULT_DEFINED_
  198. #endif