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