1 /***********************************************************************\
2 *                                 dde.d                                 *
3 *                                                                       *
4 *                       Windows API header module                       *
5 *                                                                       *
6 *                 Translated from MinGW Windows headers                 *
7 *                           by Stewart Gordon                           *
8 *                                                                       *
9 *                       Placed into public domain                       *
10 \***********************************************************************/
11 module win32.dde;
12 pragma(lib, "user32");
13 
14 private import win32.windef;
15 
16 enum : uint {
17 	WM_DDE_FIRST     = 0x03E0,
18 	WM_DDE_INITIATE  = WM_DDE_FIRST,
19 	WM_DDE_TERMINATE,
20 	WM_DDE_ADVISE,
21 	WM_DDE_UNADVISE,
22 	WM_DDE_ACK,
23 	WM_DDE_DATA,
24 	WM_DDE_REQUEST,
25 	WM_DDE_POKE,
26 	WM_DDE_EXECUTE,
27 	WM_DDE_LAST      = WM_DDE_EXECUTE
28 }
29 
30 struct DDEACK {
31 	ubyte bAppReturnCode;
32 	ubyte _bf;
33 
34 	@property ubyte reserved() { return cast(ubyte) (_bf & 0x3F); }
35 	@property bool  fBusy()    { return cast(bool)  (_bf & 0x40); }
36 	@property bool  fAck()     { return cast(bool)  (_bf & 0x80); }
37 
38 	@property ubyte reserved(ubyte r) {
39 		_bf = cast(ubyte) ((_bf & ~0x3F) | (r & 0x3F));
40 		return cast(ubyte)(r & 0x3F);
41 	}
42 
43 	@property bool fBusy(bool f) { _bf = cast(ubyte) ((_bf & ~0x40) | (f << 6)); return f; }
44 	@property bool fAck(bool f)  { _bf = cast(ubyte) ((_bf & ~0x80) | (f << 7)); return f; }
45 }
46 
47 struct DDEADVISE {
48 	ushort _bf;
49 	short  cfFormat;
50 
51 	@property ushort reserved()  { return cast(ushort) (_bf & 0x3FFF); }
52 	@property bool   fDeferUpd() { return cast(bool)   (_bf & 0x4000); }
53 	@property bool   fAckReq()   { return cast(bool)   (_bf & 0x8000); }
54 
55 	@property ushort reserved(ushort r) {
56 		_bf = cast(ushort) ((_bf & ~0x3FFF) | (r & 0x3FFF));
57 		return cast(ushort)(r & 0x3FFF);
58 	}
59 
60 	@property bool   fDeferUpd(bool f) { _bf = cast(ushort) ((_bf & ~0x4000) | (f << 14)); return f; }
61 	@property bool   fAckReq(bool f)   { _bf = cast(ushort) ((_bf & ~0x8000) | (f << 15)); return f; }
62 }
63 
64 struct DDEDATA {
65 	ushort _bf;
66 	short  cfFormat;
67 	byte   _Value;
68 
69 	@property ushort unused()    { return cast(ushort) (_bf & 0x0FFF); }
70 	@property bool   fResponse() { return cast(bool)   (_bf & 0x1000); }
71 	@property bool   fRelease()  { return cast(bool)   (_bf & 0x2000); }
72 	@property bool   reserved()  { return cast(bool)   (_bf & 0x4000); }
73 	@property bool   fAckReq()   { return cast(bool)   (_bf & 0x8000); }
74 
75 	@property byte*  Value() { return &_Value; }
76 
77 	@property ushort unused(ushort r) {
78 		_bf = cast(ushort) ((_bf & ~0x0FFF) | (r & 0x0FFF));
79 		return cast(ushort)(r & 0x0FFF);
80 	}
81 
82 	@property bool   fResponse(bool f) { _bf = cast(ushort) ((_bf & ~0x1000) | (f << 12)); return f; }
83 	@property bool   fRelease(bool f)  { _bf = cast(ushort) ((_bf & ~0x2000) | (f << 13)); return f; }
84 	@property bool   reserved(bool f)  { _bf = cast(ushort) ((_bf & ~0x4000) | (f << 14)); return f; }
85 	@property bool   fAckReq(bool f)   { _bf = cast(ushort) ((_bf & ~0x8000) | (f << 15)); return f; }
86 }
87 
88 struct DDEPOKE {
89 	ushort _bf;
90 	short  cfFormat;
91 	byte   _Value;
92 
93 	@property ushort unused()    { return cast(ushort) (_bf & 0x1FFF); }
94 	@property bool   fRelease()  { return cast(bool)   (_bf & 0x2000); }
95 	@property ubyte  fReserved() { return cast(ubyte)  ((_bf & 0xC000) >>> 14); }
96 
97 	@property byte*  Value() { return &_Value; }
98 
99 	@property ushort unused(ushort u) {
100 		_bf = cast(ushort) ((_bf & ~0x1FFF) | (u & 0x1FFF));
101 		return cast(ushort)(u & 0x1FFF);
102 	}
103 
104 	@property bool   fRelease(bool f)   { _bf = cast(ushort) ((_bf & ~0x2000) | (f << 13)); return f; }
105 	@property ubyte  fReserved(ubyte r) { _bf = cast(ushort) ((_bf & ~0xC000) | (r << 14)); return r; }
106 }
107 
108 deprecated struct DDELN {
109 	ushort _bf;
110 	short  cfFormat;
111 
112 	@property ushort unused()    { return cast(ushort) (_bf & 0x1FFF); }
113 	@property bool   fRelease()  { return cast(bool)   (_bf & 0x2000); }
114 	@property bool   fDeferUpd() { return cast(bool)   (_bf & 0x4000); }
115 	@property bool   fAckReq()   { return cast(bool)   (_bf & 0x8000); }
116 
117 	@property ushort unused(ushort u) {
118 		_bf = cast(ushort)((_bf & ~0x1FFF) | (u & 0x1FFF));
119 		return cast(ushort)(u & 0x1FFF);
120 	}
121 
122 	@property bool   fRelease(bool f)  { _bf = cast(ushort) ((_bf & ~0x2000) | (f << 13)); return f; }
123 	@property bool   fDeferUpd(bool f) { _bf = cast(ushort) ((_bf & ~0x4000) | (f << 14)); return f; }
124 	@property bool   fAckReq(bool f)   { _bf = cast(ushort) ((_bf & ~0x8000) | (f << 15)); return f; }
125 }
126 
127 deprecated struct DDEUP {
128 	ushort _bf;
129 	short  cfFormat;
130 	byte   _rgb;
131 
132 	@property ushort unused()    { return cast(ushort) (_bf & 0x0FFF); }
133 	@property bool   fAck()      { return cast(bool)   (_bf & 0x1000); }
134 	@property bool   fRelease()  { return cast(bool)   (_bf & 0x2000); }
135 	@property bool   fReserved() { return cast(bool)   (_bf & 0x4000); }
136 	@property bool   fAckReq()   { return cast(bool)   (_bf & 0x8000); }
137 
138 	@property byte*  rgb() { return &_rgb; }
139 
140 	@property ushort unused(ushort r) {
141 		_bf = cast(ushort) ((_bf & ~0x0FFF) | (r & 0x0FFF));
142 		return cast(ushort)(r & 0x0FFF);
143 	}
144 
145 	@property bool   fAck(bool f)      { _bf = cast(ushort) ((_bf & ~0x1000) | (f << 12)); return f; }
146 	@property bool   fRelease(bool f)  { _bf = cast(ushort) ((_bf & ~0x2000) | (f << 13)); return f; }
147 	@property bool   fReserved(bool f) { _bf = cast(ushort) ((_bf & ~0x4000) | (f << 14)); return f; }
148 	@property bool   fAckReq(bool f)   { _bf = cast(ushort) ((_bf & ~0x8000) | (f << 15)); return f; }
149 }
150 
151 extern (Windows) {
152 	BOOL DdeSetQualityOfService(HWND, const(SECURITY_QUALITY_OF_SERVICE)*,
153 	  PSECURITY_QUALITY_OF_SERVICE);
154 	BOOL ImpersonateDdeClientWindow(HWND, HWND);
155 	LPARAM PackDDElParam(UINT, UINT_PTR, UINT_PTR);
156 	BOOL UnpackDDElParam(UINT, LPARAM, PUINT_PTR, PUINT_PTR);
157 	BOOL FreeDDElParam(UINT, LPARAM);
158 	LPARAM ReuseDDElParam(LPARAM, UINT, UINT, UINT_PTR, UINT_PTR);
159 }
160 
161 debug (WindowsUnitTest) {
162 	unittest {
163 		DDEACK ddeack;
164 
165 		with (ddeack) {
166 			reserved = 10;
167 			assert (_bf == 0x0A);
168 			fBusy = true;
169 			assert (_bf == 0x4A);
170 			fAck = true;
171 			assert (_bf == 0xCA);
172 
173 			assert (reserved == 10);
174 			assert (fBusy == true);
175 			assert (fAck == true);
176 
177 			reserved = 43;
178 			assert (_bf == 0xEB);
179 			fBusy = false;
180 			assert (_bf == 0xAB);
181 			fAck = false;
182 			assert (_bf == 0x2B);
183 
184 			assert (reserved == 43);
185 			assert (fBusy == false);
186 			assert (fAck == false);
187 		}
188 
189 		DDEPOKE ddepoke;
190 
191 		with (ddepoke) {
192 			unused = 3456;
193 			assert (_bf == 0x0D80);
194 			fRelease = true;
195 			assert (_bf == 0x2D80);
196 			fReserved = 2;
197 			assert (_bf == 0xAD80);
198 
199 			assert (unused == 3456);
200 			assert (fRelease == true);
201 			assert (fReserved == 2);
202 
203 			unused = 2109;
204 			assert (_bf == 0xa83d);
205 			fRelease = false;
206 			assert (_bf == 0x883d);
207 			fReserved = 1;
208 			assert (_bf == 0x483d);
209 
210 			assert (unused == 2109);
211 			assert (fRelease == false);
212 			assert (fReserved == 1);
213 		}
214 	}
215 }