root/trunk/win32/basetsd.d

Revision 372, 4.0 kB (checked in by CyberShadow, 1 month ago)

win32: Replace typedef with compatibility wrapper template

Line 
1 /***********************************************************************\
2 *                               basetsd.d                               *
3 *                                                                       *
4 *                       Windows API header module                       *
5 *                                                                       *
6 *             Translated from MinGW API for MS-Windows 3.12             *
7 *                           by Stewart Gordon                           *
8 *                                                                       *
9 *                       Placed into public domain                       *
10 \***********************************************************************/
11 module win32.basetsd;
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  */
16 template CPtr(T) {
17     version (D_Version2) {
18         // must use mixin so that it doesn't cause a syntax error under D1
19         mixin("alias const(T)* CPtr;");
20     } else {
21         alias T* CPtr;
22     }
23 }
24
25 /*  [CyberShadow VP 2011.12.22] typedef is now deprecated in D2.
26  */
27 template TypeDef(T) {
28     version (D_Version2) {
29         alias T TypeDef;
30     } else {
31         // must use mixin so that it doesn't cause a deprecation error under D2
32         mixin("typedef T TypeDef;");
33     }
34 }
35
36 // [SnakE 2009-02-23] Moved HANDLE definition here from winnt.d to avoid
37 // 'forwatd template reference' to CPtr from winnt.d caused by a circular
38 // import.
39
40 alias TypeDef!(void*) HANDLE;
41
42 alias HANDLE* PHANDLE, LPHANDLE;
43
44 version (Win64) {
45     alias long __int3264;
46     const ulong ADDRESS_TAG_BIT = 0x40000000000;
47
48     alias long INT_PTR, LONG_PTR;
49     alias long* PINT_PTR, PLONG_PTR;
50     alias ulong UINT_PTR, ULONG_PTR, HANDLE_PTR;
51     alias ulong* PUINT_PTR, PULONG_PTR;
52     alias int HALF_PTR;
53     alias int* PHALF_PTR;
54     alias uint UHALF_PTR;
55     alias uint* PUHALF_PTR;
56
57     /*  *To* functions are conditioned out in MinGW.
58      *  Presumably they're not working/tested yet.  Comment:
59             TODO when WIN64 is here
60      */
61 } else {
62     alias int __int3264;
63     const uint ADDRESS_TAG_BIT = 0x80000000;
64
65     alias int INT_PTR, LONG_PTR;
66     alias int* PINT_PTR, PLONG_PTR;
67     alias uint UINT_PTR, ULONG_PTR, HANDLE_PTR;
68     alias uint* PUINT_PTR, PULONG_PTR;
69     alias short HALF_PTR;
70     alias short* PHALF_PTR;
71     alias ushort UHALF_PTR;
72     alias ushort* PUHALF_PTR;
73
74     uint HandleToUlong(HANDLE h)      { return cast(uint) h; }
75     int HandleToLong(HANDLE h)        { return cast(int) h; }
76     HANDLE LongToHandle(LONG_PTR h)   { return cast(HANDLE) h; }
77     uint PtrToUlong(CPtr!(void) p)    { return cast(uint) p; }
78     uint PtrToUint(CPtr!(void) p)     { return cast(uint) p; }
79     int PtrToInt(CPtr!(void) p)       { return cast(int) p; }
80     ushort PtrToUshort(CPtr!(void) p) { return cast(ushort) p; }
81     short PtrToShort(CPtr!(void) p)   { return cast(short) p; }
82     void* IntToPtr(int i)             { return cast(void*) i; }
83     void* UIntToPtr(uint ui)          { return cast(void*) ui; }
84     alias IntToPtr LongToPtr;
85     alias UIntToPtr ULongToPtr;
86 }
87
88 alias UIntToPtr UintToPtr, UlongToPtr;
89
90 enum : UINT_PTR {
91     MAXUINT_PTR = UINT_PTR.max
92 }
93
94 enum : INT_PTR {
95     MAXINT_PTR = INT_PTR.max,
96     MININT_PTR = INT_PTR.min
97 }
98
99 enum : ULONG_PTR {
100     MAXULONG_PTR = ULONG_PTR.max
101 }
102
103 enum : LONG_PTR {
104     MAXLONG_PTR = LONG_PTR.max,
105     MINLONG_PTR = LONG_PTR.min
106 }
107
108 enum : UHALF_PTR {
109     MAXUHALF_PTR = UHALF_PTR.max
110 }
111
112 enum : HALF_PTR {
113     MAXHALF_PTR = HALF_PTR.max,
114     MINHALF_PTR = HALF_PTR.min
115 }
116
117 alias byte INT8;
118 alias byte* PINT8;
119 alias ubyte UINT8;
120 alias ubyte* PUINT8;
121
122 alias short INT16;
123 alias short* PINT16;
124 alias ushort UINT16;
125 alias ushort* PUINT16;
126
127 alias int LONG32, INT32;
128 alias int* PLONG32, PINT32;
129 alias uint ULONG32, DWORD32, UINT32;
130 alias uint* PULONG32, PDWORD32, PUINT32;
131
132 alias ULONG_PTR SIZE_T, DWORD_PTR;
133 alias ULONG_PTR* PSIZE_T, PDWORD_PTR;
134 alias LONG_PTR SSIZE_T;
135 alias LONG_PTR* PSSIZE_T;
136
137 alias long LONG64, INT64;
138 alias long* PLONG64, PINT64;
139 alias ulong ULONG64, DWORD64, UINT64;
140 alias ulong* PULONG64, PDWORD64, PUINT64;
Note: See TracBrowser for help on using the browser.