1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW API for MS-Windows 3.12
5  *
6  * Authors: Stewart Gordon
7  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8  * Source: $(DRUNTIMESRC core/sys/windows/_basetsd.d)
9  */
10 /// Automatically imported and edited from the druntime module
11 /// core.sys.windows.basetsd for the auto-generated win32 package.
12 module win32.basetsd;
13 //version (Windows):
14 @system:
15 
16 /*  This template is used in these modules to declare constant pointer types,
17  *  in order to support both D 1.x and 2.x.
18  *  Since removed - now supporting only D2
19  */
20 /*template CPtr(T) {
21     version (D_Version2) {
22         // must use mixin so that it doesn't cause a syntax error under D1
23         mixin("alias const(T)* CPtr;");
24     } else {
25         alias T* CPtr;
26     }
27 }*/
28 
29 /*  [CyberShadow VP 2011.12.22] typedef is now deprecated in D2.
30  */
31 template TypeDef(T) {
32     version (D_Version2) {
33         alias T TypeDef;
34     } else {
35         // must use mixin so that it doesn't cause a deprecation error under D2
36         mixin("typedef T TypeDef;");
37     }
38 }
39 
40 // [SnakE 2009-02-23] Moved HANDLE definition here from winnt.d to avoid
41 // 'forwatd template reference' to CPtr from winnt.d caused by a circular
42 // import.
43 
44 alias TypeDef!(void*) HANDLE;
45 /+struct HANDLE {
46 const(void)* h;
47     alias h this;
48 }+/
49 
50 package template DECLARE_HANDLE(string name, base = HANDLE) {
51     mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");
52 }
53 alias HANDLE* PHANDLE, LPHANDLE;
54 
55 // helper for aligned structs
56 // alignVal 0 means the default align.
57 // _alignSpec as parameter does not pollute namespace.
58 package mixin template AlignedStr(int alignVal, string name, string memberlist,
59                                     string _alignSpec = !alignVal ? "align" : "align("~alignVal.stringof~")" )
60 {
61     mixin( _alignSpec ~ " struct " ~ name ~" { " ~ _alignSpec ~":"~ memberlist~" }" );
62 }
63 
64 version (CoreUnittest) {
65     private mixin AlignedStr!(16, "_Test_Aligned_Str", q{char a; char b;});
66     private mixin AlignedStr!(0, "_Test_NoAligned_Str", q{char a; char b;});
67 }
68 
69 version (Win64) {
70     alias long __int3264;
71 enum ulong ADDRESS_TAG_BIT = 0x40000000000;
72 
73     alias long INT_PTR, LONG_PTR;
74     alias long* PINT_PTR, PLONG_PTR;
75     alias ulong UINT_PTR, ULONG_PTR, HANDLE_PTR;
76     alias ulong* PUINT_PTR, PULONG_PTR;
77     alias int HALF_PTR;
78     alias int* PHALF_PTR;
79     alias uint UHALF_PTR;
80     alias uint* PUHALF_PTR;
81 
82     uint HandleToULong()(void* h) { return(cast(uint) cast(ULONG_PTR) h); }
83     int HandleToLong()(void* h)   { return(cast(int) cast(LONG_PTR) h); }
84     void* ULongToHandle()(uint h) { return(cast(void*) cast(UINT_PTR) h); }
85     void* LongToHandle()(int h)   { return(cast(void*) cast(INT_PTR) h); }
86     uint PtrToUlong()(void* p)    { return(cast(uint) cast(ULONG_PTR) p); }
87     uint PtrToUint()(void* p)     { return(cast(uint) cast(UINT_PTR) p); }
88     ushort PtrToUshort()(void* p) { return(cast(ushort) cast(uint) cast(ULONG_PTR) p); }
89     int PtrToLong()(void* p)      { return(cast(int) cast(LONG_PTR) p); }
90     int PtrToInt()(void* p)       { return(cast(int) cast(INT_PTR) p); }
91     short PtrToShort()(void* p)   { return(cast(short) cast(int) cast(LONG_PTR) p); }
92     void* IntToPtr()(int i)       { return(cast(void*) cast(INT_PTR) i); }
93     void* UIntToPtr()(uint ui)    { return(cast(void*) cast(UINT_PTR) ui); }
94     void* LongToPtr()(int l)      { return(cast(void*) cast(LONG_PTR) l); }
95     void* ULongToPtr()(uint ul)   { return(cast(void*) cast(ULONG_PTR) ul); }
96 
97 } else {
98     alias int __int3264;
99 enum uint ADDRESS_TAG_BIT = 0x80000000;
100 
101     alias int INT_PTR, LONG_PTR;
102     alias int* PINT_PTR, PLONG_PTR;
103     alias uint UINT_PTR, ULONG_PTR, HANDLE_PTR;
104     alias uint* PUINT_PTR, PULONG_PTR;
105     alias short HALF_PTR;
106     alias short* PHALF_PTR;
107     alias ushort UHALF_PTR;
108     alias ushort* PUHALF_PTR;
109 
110     uint HandleToUlong()(HANDLE h)      { return cast(uint) h; }
111     int HandleToLong()(HANDLE h)        { return cast(int) h; }
112     HANDLE LongToHandle()(LONG_PTR h)   { return cast(HANDLE)h; }
113     uint PtrToUlong()(const(void)* p)    { return cast(uint) p; }
114     uint PtrToUint()(const(void)* p)     { return cast(uint) p; }
115     int PtrToInt()(const(void)* p)       { return cast(int) p; }
116     ushort PtrToUshort()(const(void)* p) { return cast(ushort) p; }
117     short PtrToShort()(const(void)* p)   { return cast(short) p; }
118     void* IntToPtr()(int i)             { return cast(void*) i; }
119     void* UIntToPtr()(uint ui)          { return cast(void*) ui; }
120     alias IntToPtr LongToPtr;
121     alias UIntToPtr ULongToPtr;
122 }
123 
124 alias UIntToPtr UintToPtr, UlongToPtr;
125 
126 enum : UINT_PTR {
127     MAXUINT_PTR = UINT_PTR.max
128 }
129 
130 enum : INT_PTR {
131     MAXINT_PTR = INT_PTR.max,
132     MININT_PTR = INT_PTR.min
133 }
134 
135 enum : ULONG_PTR {
136     MAXULONG_PTR = ULONG_PTR.max
137 }
138 
139 enum : LONG_PTR {
140     MAXLONG_PTR = LONG_PTR.max,
141     MINLONG_PTR = LONG_PTR.min
142 }
143 
144 enum : UHALF_PTR {
145     MAXUHALF_PTR = UHALF_PTR.max
146 }
147 
148 enum : HALF_PTR {
149     MAXHALF_PTR = HALF_PTR.max,
150     MINHALF_PTR = HALF_PTR.min
151 }
152 
153 alias byte INT8;
154 alias byte* PINT8;
155 alias ubyte UINT8;
156 alias ubyte* PUINT8;
157 
158 alias short INT16;
159 alias short* PINT16;
160 alias ushort UINT16;
161 alias ushort* PUINT16;
162 
163 alias int LONG32, INT32;
164 alias int* PLONG32, PINT32;
165 alias uint ULONG32, DWORD32, UINT32;
166 alias uint* PULONG32, PDWORD32, PUINT32;
167 
168 alias ULONG_PTR SIZE_T, DWORD_PTR;
169 alias ULONG_PTR* PSIZE_T, PDWORD_PTR;
170 alias LONG_PTR SSIZE_T;
171 alias LONG_PTR* PSSIZE_T;
172 
173 alias long LONG64, INT64;
174 alias long* PLONG64, PINT64;
175 alias ulong ULONG64, DWORD64, UINT64;
176 alias ulong* PULONG64, PDWORD64, PUINT64;