home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / basetsd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  6.3 KB  |  318 lines

  1. /*++
  2.  
  3. Copyright (c) 1997-1999  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     basetsd.h
  8.  
  9. Abstract:
  10.  
  11.     Type definitions for the basic sized types.
  12.  
  13. Author:
  14.  
  15.     Jeff Havens (jhavens)   23-Oct-1997
  16.  
  17. Revision History:
  18.  
  19. --*/
  20.  
  21. #ifndef _BASETSD_H_
  22. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  23. #define _BASETSD_H_
  24.  
  25. #if _MSC_VER > 1000
  26. #pragma once
  27. #endif
  28.  
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33. //
  34. // The following types are guaranteed to be signed and 32 bits wide.
  35. //
  36.  
  37. typedef int LONG32, *PLONG32;
  38. typedef int INT32, *PINT32;
  39.  
  40. //
  41. // The following types are guaranteed to be unsigned and 32 bits wide.
  42. //
  43.  
  44. typedef unsigned int ULONG32, *PULONG32;
  45. typedef unsigned int DWORD32, *PDWORD32;
  46. typedef unsigned int UINT32, *PUINT32;
  47.  
  48. #if !defined(__midl) && defined(_X86_) && _MSC_VER >= 1300
  49. #define _W64 __w64
  50. #else
  51. #define _W64
  52. #endif
  53.  
  54. //
  55. // The INT_PTR is guaranteed to be the same size as a pointer.  Its
  56. // size with change with pointer size (32/64).  It should be used
  57. // anywhere that a pointer is cast to an integer type. UINT_PTR is
  58. // the unsigned variation.
  59. //
  60. // __int3264 is intrinsic to 64b MIDL but not to old MIDL or to C compiler.
  61. //
  62. #if ( 501 < __midl )
  63.  
  64.     typedef [public] __int3264 INT_PTR, *PINT_PTR;
  65.     typedef [public] unsigned __int3264 UINT_PTR, *PUINT_PTR;
  66.  
  67.     typedef [public] __int3264 LONG_PTR, *PLONG_PTR;
  68.     typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR;
  69.  
  70. #else  // midl64
  71. // old midl and C++ compiler
  72.  
  73. #if defined(_WIN64)
  74.     typedef __int64 INT_PTR, *PINT_PTR;
  75.     typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
  76.  
  77.     typedef __int64 LONG_PTR, *PLONG_PTR;
  78.     typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
  79.  
  80.     #define __int3264   __int64
  81.  
  82. #else
  83.     typedef _W64 int INT_PTR, *PINT_PTR;
  84.     typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
  85.  
  86.     typedef _W64 long LONG_PTR, *PLONG_PTR;
  87.     typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
  88.  
  89.     #define __int3264   __int32
  90.  
  91. #endif
  92. #endif // midl64
  93.  
  94. //
  95. // HALF_PTR is half the size of a pointer it intended for use with
  96. // within strcuture which contain a pointer and two small fields.
  97. // UHALF_PTR is the unsigned variation.
  98. //
  99.  
  100. #ifdef _WIN64
  101.  
  102. #define ADDRESS_TAG_BIT 0x40000000000UI64
  103.  
  104. typedef unsigned __int64 HANDLE_PTR;
  105. typedef unsigned int UHALF_PTR, *PUHALF_PTR;
  106. typedef int HALF_PTR, *PHALF_PTR;
  107.  
  108. #pragma warning(disable:4311)   // type cast truncation
  109. #if _MSC_VER >= 1200
  110. #pragma warning(push)
  111. #endif
  112. #pragma warning(disable:4305)   // type cast truncation
  113.  
  114. #if !defined(__midl)
  115. __inline
  116. unsigned long
  117. HandleToUlong(
  118.     const void *h
  119.     )
  120. {
  121.     return((unsigned long) h );
  122. }
  123.  
  124. __inline
  125. long
  126. HandleToLong(
  127.     const void *h
  128.     )
  129. {
  130.     return((long) h );
  131. }
  132.  
  133. __inline
  134. void *
  135. LongToHandle(
  136.     const long h
  137.     )
  138. {
  139.     return((void *) (INT_PTR) h );
  140. }
  141.  
  142.  
  143. __inline
  144. unsigned long
  145. PtrToUlong(
  146.     const void  *p
  147.     )
  148. {
  149.     return((unsigned long) p );
  150. }
  151.  
  152. __inline
  153. unsigned int
  154. PtrToUint(
  155.     const void  *p
  156.     )
  157. {
  158.     return((unsigned int) p );
  159. }
  160.  
  161. __inline
  162. unsigned short
  163. PtrToUshort(
  164.     const void  *p
  165.     )
  166. {
  167.     return((unsigned short) p );
  168. }
  169.  
  170. __inline
  171. long
  172. PtrToLong(
  173.     const void  *p
  174.     )
  175. {
  176.     return((long) p );
  177. }
  178.  
  179. __inline
  180. int
  181. PtrToInt(
  182.     const void  *p
  183.     )
  184. {
  185.     return((int) p );
  186. }
  187.  
  188. __inline
  189. short
  190. PtrToShort(
  191.     const void  *p
  192.     )
  193. {
  194.     return((short) p );
  195. }
  196.  
  197. __inline
  198. void *
  199. IntToPtr(
  200.     const int i
  201.     )
  202. // Caution: IntToPtr() sign-extends the int value.
  203. {
  204.     return( (void *)(INT_PTR)i );
  205. }
  206.  
  207. __inline
  208. void *
  209. UIntToPtr(
  210.     const unsigned int ui
  211.     )
  212. // Caution: UIntToPtr() zero-extends the unsigned int value.
  213. {
  214.     return( (void *)(UINT_PTR)ui );
  215. }
  216.  
  217. __inline
  218. void *
  219. LongToPtr(
  220.     const long l
  221.     )
  222. // Caution: LongToPtr() sign-extends the long value.
  223. {
  224.     return( (void *)(LONG_PTR)l );
  225. }
  226.  
  227. __inline
  228. void *
  229. ULongToPtr(
  230.     const unsigned long ul
  231.     )
  232. // Caution: ULongToPtr() zero-extends the unsigned long value.
  233. {
  234.     return( (void *)(ULONG_PTR)ul );
  235. }
  236.  
  237. #endif // !_midl
  238. #if _MSC_VER >= 1200
  239. #pragma warning(pop)      // restore 4305
  240. #endif
  241. #pragma warning(3:4311)   // bump 4311 to a level 3
  242.  
  243. #else  // !_WIN64
  244.  
  245. #define ADDRESS_TAG_BIT 0x80000000UL
  246.  
  247. typedef unsigned short UHALF_PTR, *PUHALF_PTR;
  248. typedef short HALF_PTR, *PHALF_PTR;
  249. typedef _W64 unsigned long HANDLE_PTR;
  250.  
  251. #define HandleToUlong( h ) ((ULONG)(ULONG_PTR)(h) )
  252. #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
  253. #define LongToHandle( h) ((HANDLE)(LONG_PTR) (h))
  254. #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
  255. #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
  256. #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
  257. #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
  258. #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
  259. #define PtrToShort( p ) ((short)(LONG_PTR)(p) )
  260. #define IntToPtr( i )    ((VOID *)(INT_PTR)((int)i))
  261. #define UIntToPtr( ui )  ((VOID *)(UINT_PTR)((unsigned int)ui))
  262. #define LongToPtr( l )   ((VOID *)(LONG_PTR)((long)l))
  263. #define ULongToPtr( ul )  ((VOID *)(ULONG_PTR)((unsigned long)ul))
  264.  
  265. #endif // !_WIN64
  266.  
  267. #define UlongToPtr(ul) ULongToPtr(ul)
  268. #define UintToPtr(ui) UIntToPtr(ui)
  269.  
  270. #define MAXUINT_PTR  (~((UINT_PTR)0))
  271. #define MAXINT_PTR   ((INT_PTR)(MAXUINT_PTR >> 1))
  272. #define MININT_PTR   (~MAXINT_PTR)
  273.  
  274. #define MAXULONG_PTR (~((ULONG_PTR)0))
  275. #define MAXLONG_PTR  ((LONG_PTR)(MAXULONG_PTR >> 1))
  276. #define MINLONG_PTR  (~MAXLONG_PTR)
  277.  
  278. #define MAXUHALF_PTR ((UHALF_PTR)~0)
  279. #define MAXHALF_PTR  ((HALF_PTR)(MAXUHALF_PTR >> 1))
  280. #define MINHALF_PTR  (~MAXHALF_PTR)
  281.  
  282. //
  283. // SIZE_T used for counts or ranges which need to span the range of
  284. // of a pointer.  SSIZE_T is the signed variation.
  285. //
  286.  
  287. typedef ULONG_PTR SIZE_T, *PSIZE_T;
  288. typedef LONG_PTR SSIZE_T, *PSSIZE_T;
  289.  
  290. //
  291. // Add Windows flavor DWORD_PTR types
  292. //
  293.  
  294. typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
  295.  
  296. //
  297. // The following types are guaranteed to be signed and 64 bits wide.
  298. //
  299.  
  300. typedef __int64 LONG64, *PLONG64;
  301. typedef __int64 INT64,  *PINT64;
  302.  
  303.  
  304. //
  305. // The following types are guaranteed to be unsigned and 64 bits wide.
  306. //
  307.  
  308. typedef unsigned __int64 ULONG64, *PULONG64;
  309. typedef unsigned __int64 DWORD64, *PDWORD64;
  310. typedef unsigned __int64 UINT64,  *PUINT64;
  311.  
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315.  
  316. #pragma option pop /*P_O_Pop*/
  317. #endif // _BASETSD_H_
  318.