1 /***********************************************************************\
2 *                                ddeml.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 windows.ddeml;
12 pragma(lib, "user32");
13 nothrow:
14 private import windows.basetsd, windows.windef, windows.winnt;
15 
16 enum : int {
17 	CP_WINANSI    = 1004,
18 	CP_WINUNICODE = 1200
19 }
20 
21 enum : UINT {
22 	XTYPF_NOBLOCK = 2,
23 	XTYPF_NODATA  = 4,
24 	XTYPF_ACKREQ  = 8
25 }
26 
27 enum : UINT {
28 	XCLASS_MASK         = 0xFC00,
29 	XCLASS_BOOL         = 0x1000,
30 	XCLASS_DATA         = 0x2000,
31 	XCLASS_FLAGS        = 0x4000,
32 	XCLASS_NOTIFICATION = 0x8000
33 }
34 
35 enum : UINT {
36 	XST_NULL,
37 	XST_INCOMPLETE,
38 	XST_CONNECTED,
39 	XST_INIT1,
40 	XST_INIT2,
41 	XST_REQSENT,
42 	XST_DATARCVD,
43 	XST_POKESENT,
44 	XST_POKEACKRCVD,
45 	XST_EXECSENT,
46 	XST_EXECACKRCVD,
47 	XST_ADVSENT,
48 	XST_UNADVSENT,
49 	XST_ADVACKRCVD,
50 	XST_UNADVACKRCVD,
51 	XST_ADVDATASENT,
52 	XST_ADVDATAACKRCVD // = 16
53 }
54 
55 enum : UINT {
56 	XTYP_ERROR           = XCLASS_NOTIFICATION | XTYPF_NOBLOCK,
57 	XTYP_ADVDATA         = 0x0010 | XCLASS_FLAGS,
58 	XTYP_ADVREQ          = 0x0020 | XCLASS_DATA | XTYPF_NOBLOCK,
59 	XTYP_ADVSTART        = 0x0030 | XCLASS_BOOL,
60 	XTYP_ADVSTOP         = 0x0040 | XCLASS_NOTIFICATION,
61 	XTYP_EXECUTE         = 0x0050 | XCLASS_FLAGS,
62 	XTYP_CONNECT         = 0x0060 | XCLASS_BOOL | XTYPF_NOBLOCK,
63 	XTYP_CONNECT_CONFIRM = 0x0070 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK,
64 	XTYP_XACT_COMPLETE   = 0x0080 | XCLASS_NOTIFICATION,
65 	XTYP_POKE            = 0x0090 | XCLASS_FLAGS,
66 	XTYP_REGISTER        = 0x00A0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK,
67 	XTYP_REQUEST         = 0x00B0 | XCLASS_DATA,
68 	XTYP_DISCONNECT      = 0x00C0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK,
69 	XTYP_UNREGISTER      = 0x00D0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK,
70 	XTYP_WILDCONNECT     = 0x00E0 | XCLASS_DATA | XTYPF_NOBLOCK,
71 	XTYP_MONITOR         = 0X00F0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK,
72 	XTYP_MASK            = 0x00F0,
73 	XTYP_SHIFT           = 4
74 }
75 
76 /+
77 #define TIMEOUT_ASYNC  0xFFFFFFFF
78 #define QID_SYNC       0xFFFFFFFF
79 +/
80 
81 enum : UINT {
82 	ST_CONNECTED  =   1,
83 	ST_ADVISE     =   2,
84 	ST_ISLOCAL    =   4,
85 	ST_BLOCKED    =   8,
86 	ST_CLIENT     =  16,
87 	ST_TERMINATED =  32,
88 	ST_INLIST     =  64,
89 	ST_BLOCKNEXT  = 128,
90 	ST_ISSELF     = 256
91 }
92 
93 /+
94 #define CADV_LATEACK 0xFFFF
95 +/
96 
97 enum : UINT {
98 	DMLERR_NO_ERROR      = 0,
99 	DMLERR_FIRST         = 0x4000,
100 	DMLERR_ADVACKTIMEOUT = DMLERR_FIRST,
101 	DMLERR_BUSY,
102 	DMLERR_DATAACKTIMEOUT,
103 	DMLERR_DLL_NOT_INITIALIZED,
104 	DMLERR_DLL_USAGE,
105 	DMLERR_EXECACKTIMEOUT,
106 	DMLERR_INVALIDPARAMETER,
107 	DMLERR_LOW_MEMORY,
108 	DMLERR_MEMORY_ERROR,
109 	DMLERR_NOTPROCESSED,
110 	DMLERR_NO_CONV_ESTABLISHED,
111 	DMLERR_POKEACKTIMEOUT,
112 	DMLERR_POSTMSG_FAILED,
113 	DMLERR_REENTRANCY,
114 	DMLERR_SERVER_DIED,
115 	DMLERR_SYS_ERROR,
116 	DMLERR_UNADVACKTIMEOUT,
117 	DMLERR_UNFOUND_QUEUE_ID, // = 0x4011
118 	DMLERR_LAST          = DMLERR_UNFOUND_QUEUE_ID
119 }
120 
121 /+
122 #define DDE_FACK	0x8000
123 #define DDE_FBUSY	0x4000
124 #define DDE_FDEFERUPD	0x4000
125 #define DDE_FACKREQ	0x8000
126 #define DDE_FRELEASE	0x2000
127 #define DDE_FREQUESTED	0x1000
128 #define DDE_FAPPSTATUS	0x00ff
129 #define DDE_FNOTPROCESSED	0
130 #define DDE_FACKRESERVED	(~(DDE_FACK|DDE_FBUSY|DDE_FAPPSTATUS))
131 #define DDE_FADVRESERVED	(~(DDE_FACKREQ|DDE_FDEFERUPD))
132 #define DDE_FDATRESERVED	(~(DDE_FACKREQ|DDE_FRELEASE|DDE_FREQUESTED))
133 #define DDE_FPOKRESERVED	(~DDE_FRELEASE)
134 #define MSGF_DDEMGR	0x8001
135 #define CBR_BLOCK	((HDDEDATA)0xffffffff)
136 +/
137 
138 const DWORD
139 	APPCLASS_STANDARD         = 0,
140 	APPCLASS_MONITOR          = 0x00000001,
141 	APPCLASS_MASK             = 0x0000000F,
142 	APPCMD_CLIENTONLY         = 0x00000010,
143 	APPCMD_FILTERINITS        = 0x00000020,
144 	APPCMD_MASK               = 0x00000FF0,
145 	CBF_FAIL_SELFCONNECTIONS  = 0x00001000,
146 	CBF_FAIL_CONNECTIONS      = 0x00002000,
147 	CBF_FAIL_ADVISES          = 0x00004000,
148 	CBF_FAIL_EXECUTES         = 0x00008000,
149 	CBF_FAIL_POKES            = 0x00010000,
150 	CBF_FAIL_REQUESTS         = 0x00020000,
151 	CBF_FAIL_ALLSVRXACTIONS   = 0x0003f000,
152 	CBF_SKIP_CONNECT_CONFIRMS = 0x00040000,
153 	CBF_SKIP_REGISTRATIONS    = 0x00080000,
154 	CBF_SKIP_UNREGISTRATIONS  = 0x00100000,
155 	CBF_SKIP_DISCONNECTS      = 0x00200000,
156 	CBF_SKIP_ALLNOTIFICATIONS = 0x003c0000,
157 	MF_HSZ_INFO               = 0x01000000,
158 	MF_SENDMSGS               = 0x02000000,
159 	MF_POSTMSGS               = 0x04000000,
160 	MF_CALLBACKS              = 0x08000000,
161 	MF_ERRORS                 = 0x10000000,
162 	MF_LINKS                  = 0x20000000,
163 	MF_CONV                   = 0x40000000,
164 	MF_MASK                   = 0xFF000000;
165 
166 enum : UINT {
167 	EC_ENABLEALL    = 0,
168 	EC_ENABLEONE    = ST_BLOCKNEXT,
169 	EC_DISABLE      = ST_BLOCKED,
170 	EC_QUERYWAITING = 2
171 }
172 
173 enum : UINT {
174 	DNS_REGISTER   = 1,
175 	DNS_UNREGISTER = 2,
176 	DNS_FILTERON   = 4,
177 	DNS_FILTEROFF  = 8
178 }
179 
180 /+
181 #define HDATA_APPOWNED	1
182 #define MAX_MONITORS	4
183 +/
184 
185 enum : int {
186 	MH_CREATE  = 1,
187 	MH_KEEP    = 2,
188 	MH_DELETE  = 3,
189 	MH_CLEANUP = 4
190 }
191 
192 mixin DECLARE_HANDLE!("HCONVLIST");
193 mixin DECLARE_HANDLE!("HCONV");
194 mixin DECLARE_HANDLE!("HSZ");
195 mixin DECLARE_HANDLE!("HDDEDATA");
196 
197 extern (Windows) alias HDDEDATA
198   function(UINT, UINT, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD) PFNCALLBACK;
199 
200 struct HSZPAIR {
201 	HSZ hszSvc;
202 	HSZ hszTopic;
203 }
204 alias HSZPAIR* PHSZPAIR;
205 
206 struct CONVCONTEXT {
207 	UINT                        cb = CONVCONTEXT.sizeof;
208 	UINT                        wFlags;
209 	UINT                        wCountryID;
210 	int                         iCodePage;
211 	DWORD                       dwLangID;
212 	DWORD                       dwSecurity;
213 	SECURITY_QUALITY_OF_SERVICE qos;
214 }
215 alias CONVCONTEXT* PCONVCONTEXT;
216 
217 struct CONVINFO {
218 	DWORD       cb = CONVINFO.sizeof;
219 	DWORD       hUser;
220 	HCONV       hConvPartner;
221 	HSZ         hszSvcPartner;
222 	HSZ         hszServiceReq;
223 	HSZ         hszTopic;
224 	HSZ         hszItem;
225 	UINT        wFmt;
226 	UINT        wType;
227 	UINT        wStatus;
228 	UINT        wConvst;
229 	UINT        wLastError;
230 	HCONVLIST   hConvList;
231 	CONVCONTEXT ConvCtxt;
232 	HWND        hwnd;
233 	HWND        hwndPartner;
234 }
235 alias CONVINFO* PCONVINFO;
236 
237 struct DDEML_MSG_HOOK_DATA {
238 	UINT_PTR uiLo;
239 	UINT_PTR uiHi;
240 	DWORD    cbData;
241 	DWORD[8] Data;
242 }
243 
244 struct MONHSZSTRUCT {
245 	UINT     cb = MONHSZSTRUCT.sizeof;
246 	int      fsAction;
247 	DWORD    dwTime;
248 	HSZ      hsz;
249 	HANDLE   hTask;
250 	TCHAR[1] _str;
251 
252 	TCHAR* str() { return _str.ptr; }
253 }
254 alias MONHSZSTRUCT* PMONHSZSTRUCT;
255 
256 struct MONLINKSTRUCT {
257 	UINT   cb = MONLINKSTRUCT.sizeof;
258 	DWORD  dwTime;
259 	HANDLE hTask;
260 	BOOL   fEstablished;
261 	BOOL   fNoData;
262 	HSZ    hszSvc;
263 	HSZ    hszTopic;
264 	HSZ    hszItem;
265 	UINT   wFmt;
266 	BOOL   fServer;
267 	HCONV  hConvServer;
268 	HCONV  hConvClient;
269 }
270 alias MONLINKSTRUCT* PMONLINKSTRUCT;
271 
272 struct MONCONVSTRUCT {
273 	UINT   cb = MONCONVSTRUCT.sizeof;
274 	BOOL   fConnect;
275 	DWORD  dwTime;
276 	HANDLE hTask;
277 	HSZ    hszSvc;
278 	HSZ    hszTopic;
279 	HCONV  hConvClient;
280 	HCONV  hConvServer;
281 }
282 alias MONCONVSTRUCT* PMONCONVSTRUCT;
283 
284 struct MONCBSTRUCT {
285 	UINT        cb = MONCBSTRUCT.sizeof;
286 	DWORD       dwTime;
287 	HANDLE      hTask;
288 	DWORD       dwRet;
289 	UINT        wType;
290 	UINT        wFmt;
291 	HCONV       hConv;
292 	HSZ         hsz1;
293 	HSZ         hsz2;
294 	HDDEDATA    hData;
295 	ULONG_PTR   dwData1;
296 	ULONG_PTR   dwData2;
297 	CONVCONTEXT cc;
298 	DWORD       cbData;
299 	DWORD[8]    Data;
300 }
301 alias MONCBSTRUCT* PMONCBSTRUCT;
302 
303 struct MONERRSTRUCT {
304 	UINT   cb = MONERRSTRUCT.sizeof;
305 	UINT   wLastError;
306 	DWORD  dwTime;
307 	HANDLE hTask;
308 }
309 alias MONERRSTRUCT* PMONERRSTRUCT;
310 
311 struct MONMSGSTRUCT {
312 	UINT   cb = MONMSGSTRUCT.sizeof;
313 	HWND   hwndTo;
314 	DWORD  dwTime;
315 	HANDLE hTask;
316 	UINT   wMsg;
317 	WPARAM wParam;
318 	LPARAM lParam;
319 	DDEML_MSG_HOOK_DATA dmhd;
320 }
321 alias MONMSGSTRUCT* PMONMSGSTRUCT;
322 
323 extern (Windows) {
324 	BOOL DdeAbandonTransaction(DWORD, HCONV, DWORD);
325 	PBYTE DdeAccessData(HDDEDATA, PDWORD);
326 	HDDEDATA DdeAddData(HDDEDATA, PBYTE, DWORD, DWORD);
327 	HDDEDATA DdeClientTransaction(PBYTE, DWORD, HCONV, HSZ, UINT, UINT,
328 	  DWORD, PDWORD);
329 	int DdeCmpStringHandles(HSZ, HSZ);
330 	HCONV DdeConnect(DWORD, HSZ, HSZ, PCONVCONTEXT);
331 	HCONVLIST DdeConnectList(DWORD, HSZ, HSZ, HCONVLIST, PCONVCONTEXT);
332 	HDDEDATA DdeCreateDataHandle(DWORD, PBYTE, DWORD, DWORD, HSZ, UINT,
333 	  UINT);
334 	HSZ DdeCreateStringHandleA(DWORD, LPSTR, int);
335 	HSZ DdeCreateStringHandleW(DWORD, LPWSTR, int);
336 	BOOL DdeDisconnect(HCONV);
337 	BOOL DdeDisconnectList(HCONVLIST);
338 	BOOL DdeEnableCallback(DWORD, HCONV, UINT);
339 	BOOL DdeFreeDataHandle(HDDEDATA);
340 	BOOL DdeFreeStringHandle(DWORD, HSZ);
341 	DWORD DdeGetData(HDDEDATA, PBYTE, DWORD, DWORD);
342 	UINT DdeGetLastError(DWORD);
343 	BOOL DdeImpersonateClient(HCONV);
344 	UINT DdeInitializeA(PDWORD, PFNCALLBACK, DWORD, DWORD);
345 	UINT DdeInitializeW(PDWORD, PFNCALLBACK, DWORD, DWORD);
346 	BOOL DdeKeepStringHandle(DWORD, HSZ);
347 	HDDEDATA DdeNameService(DWORD, HSZ, HSZ, UINT);
348 	BOOL DdePostAdvise(DWORD, HSZ, HSZ);
349 	UINT DdeQueryConvInfo(HCONV, DWORD, PCONVINFO);
350 	HCONV DdeQueryNextServer(HCONVLIST, HCONV);
351 	DWORD DdeQueryStringA(DWORD, HSZ, LPSTR, DWORD, int);
352 	DWORD DdeQueryStringW(DWORD, HSZ, LPWSTR, DWORD, int);
353 	HCONV DdeReconnect(HCONV);
354 	BOOL DdeSetUserHandle(HCONV, DWORD, DWORD);
355 	BOOL DdeUnaccessData(HDDEDATA);
356 	BOOL DdeUninitialize(DWORD);
357 }
358 
359 const TCHAR[]
360 	SZDDESYS_TOPIC         = "System",
361 	SZDDESYS_ITEM_TOPICS   = "Topics",
362 	SZDDESYS_ITEM_SYSITEMS = "SysItems",
363 	SZDDESYS_ITEM_RTNMSG   = "ReturnMessage",
364 	SZDDESYS_ITEM_STATUS   = "Status",
365 	SZDDESYS_ITEM_FORMATS  = "Formats",
366 	SZDDESYS_ITEM_HELP     = "Help",
367 	SZDDE_ITEM_ITEMLIST    = "TopicItemList";
368 
369 version (Unicode) {
370 	alias DdeCreateStringHandleW DdeCreateStringHandle;
371 	alias DdeInitializeW DdeInitialize;
372 	alias DdeQueryStringW DdeQueryString;
373 } else {
374 	alias DdeCreateStringHandleA DdeCreateStringHandle;
375 	alias DdeInitializeA DdeInitialize;
376 	alias DdeQueryStringA DdeQueryString;
377 }