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 // [SnakE 2009-02-23] Moved HANDLE definition here from winnt.d to avoid
14 // 'forwatd template reference' to CPtr from winnt.d caused by a circular
15 // import.
16 alias HANDLE = void*;
17 
18 package template DECLARE_HANDLE(string name, base = HANDLE) {
19     mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");
20 }
21 alias HANDLE* PHANDLE, LPHANDLE;
22 
23 // helper for aligned structs
24 // alignVal 0 means the default align.
25 // _alignSpec as parameter does not pollute namespace.
26 package mixin template AlignedStr(int alignVal, string name, string memberlist,
27                                     string _alignSpec = !alignVal ? "align" : "align("~alignVal.stringof~")" )
28 {
29     mixin( _alignSpec ~ " struct " ~ name ~" { " ~ _alignSpec ~":"~ memberlist~" }" );
30 }
31 
32 version (CoreUnittest) {
33     private mixin AlignedStr!(16, "_Test_Aligned_Str", q{char a; char b;});
34     private mixin AlignedStr!(0, "_Test_NoAligned_Str", q{char a; char b;});
35 }
36 
37 version (Win64) {
38     alias long __int3264;
39 enum ulong ADDRESS_TAG_BIT = 0x40000000000;
40 
41     alias long INT_PTR, LONG_PTR;
42     alias long* PINT_PTR, PLONG_PTR;
43     alias ulong UINT_PTR, ULONG_PTR, HANDLE_PTR;
44     alias ulong* PUINT_PTR, PULONG_PTR;
45     alias int HALF_PTR;
46     alias int* PHALF_PTR;
47     alias uint UHALF_PTR;
48     alias uint* PUHALF_PTR;
49 
50     uint HandleToULong(void* h) { return(cast(uint) cast(ULONG_PTR) h); }
51     int HandleToLong(void* h)   { return(cast(int) cast(LONG_PTR) h); }
52     void* ULongToHandle(uint h) { return(cast(void*) cast(UINT_PTR) h); }
53     void* LongToHandle(int h)   { return(cast(void*) cast(INT_PTR) h); }
54     uint PtrToUlong(void* p)    { return(cast(uint) cast(ULONG_PTR) p); }
55     uint PtrToUint(void* p)     { return(cast(uint) cast(UINT_PTR) p); }
56     ushort PtrToUshort(void* p) { return(cast(ushort) cast(uint) cast(ULONG_PTR) p); }
57     int PtrToLong(void* p)      { return(cast(int) cast(LONG_PTR) p); }
58     int PtrToInt(void* p)       { return(cast(int) cast(INT_PTR) p); }
59     short PtrToShort(void* p)   { return(cast(short) cast(int) cast(LONG_PTR) p); }
60     void* IntToPtr(int i)       { return(cast(void*) cast(INT_PTR) i); }
61     void* UIntToPtr(uint ui)    { return(cast(void*) cast(UINT_PTR) ui); }
62     void* LongToPtr(int l)      { return(cast(void*) cast(LONG_PTR) l); }
63     void* ULongToPtr(uint ul)   { return(cast(void*) cast(ULONG_PTR) ul); }
64 
65 } else {
66     alias int __int3264;
67 enum uint ADDRESS_TAG_BIT = 0x80000000;
68 
69     alias int INT_PTR, LONG_PTR;
70     alias int* PINT_PTR, PLONG_PTR;
71     alias uint UINT_PTR, ULONG_PTR, HANDLE_PTR;
72     alias uint* PUINT_PTR, PULONG_PTR;
73     alias short HALF_PTR;
74     alias short* PHALF_PTR;
75     alias ushort UHALF_PTR;
76     alias ushort* PUHALF_PTR;
77 
78     uint HandleToUlong(HANDLE h)      { return cast(uint) h; }
79     int HandleToLong(HANDLE h)        { return cast(int) h; }
80     HANDLE LongToHandle(LONG_PTR h)   { return cast(HANDLE)h; }
81     uint PtrToUlong(const(void)* p)    { return cast(uint) p; }
82     uint PtrToUint(const(void)* p)     { return cast(uint) p; }
83     int PtrToInt(const(void)* p)       { return cast(int) p; }
84     ushort PtrToUshort(const(void)* p) { return cast(ushort) p; }
85     short PtrToShort(const(void)* p)   { return cast(short) p; }
86     void* IntToPtr(int i)             { return cast(void*) i; }
87     void* UIntToPtr(uint ui)          { return cast(void*) ui; }
88     alias IntToPtr LongToPtr;
89     alias UIntToPtr ULongToPtr;
90 }
91 
92 alias UIntToPtr UintToPtr, UlongToPtr;
93 
94 enum : UINT_PTR {
95     MAXUINT_PTR = UINT_PTR.max
96 }
97 
98 enum : INT_PTR {
99     MAXINT_PTR = INT_PTR.max,
100     MININT_PTR = INT_PTR.min
101 }
102 
103 enum : ULONG_PTR {
104     MAXULONG_PTR = ULONG_PTR.max
105 }
106 
107 enum : LONG_PTR {
108     MAXLONG_PTR = LONG_PTR.max,
109     MINLONG_PTR = LONG_PTR.min
110 }
111 
112 enum : UHALF_PTR {
113     MAXUHALF_PTR = UHALF_PTR.max
114 }
115 
116 enum : HALF_PTR {
117     MAXHALF_PTR = HALF_PTR.max,
118     MINHALF_PTR = HALF_PTR.min
119 }
120 
121 alias byte INT8;
122 alias byte* PINT8;
123 alias ubyte UINT8;
124 alias ubyte* PUINT8;
125 
126 alias short INT16;
127 alias short* PINT16;
128 alias ushort UINT16;
129 alias ushort* PUINT16;
130 
131 alias int LONG32, INT32;
132 alias int* PLONG32, PINT32;
133 alias uint ULONG32, DWORD32, UINT32;
134 alias uint* PULONG32, PDWORD32, PUINT32;
135 
136 alias ULONG_PTR SIZE_T, DWORD_PTR;
137 alias ULONG_PTR* PSIZE_T, PDWORD_PTR;
138 alias LONG_PTR SSIZE_T;
139 alias LONG_PTR* PSSIZE_T;
140 
141 alias long LONG64, INT64;
142 alias long* PLONG64, PINT64;
143 alias ulong ULONG64, DWORD64, UINT64;
144 alias ulong* PULONG64, PDWORD64, PUINT64;