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