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 win32.ddeml;
12 pragma(lib, "user32.lib");
13 
14 private import win32.basetsd, win32.windef, win32.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 alias HANDLE HCONVLIST, HCONV, HSZ, HDDEDATA;
193 
194 extern (Windows) alias HDDEDATA
195   function(UINT, UINT, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD) PFNCALLBACK;
196 
197 struct HSZPAIR {
198 	HSZ hszSvc;
199 	HSZ hszTopic;
200 }
201 alias HSZPAIR* PHSZPAIR;
202 
203 struct CONVCONTEXT {
204 	UINT                        cb = CONVCONTEXT.sizeof;
205 	UINT                        wFlags;
206 	UINT                        wCountryID;
207 	int                         iCodePage;
208 	DWORD                       dwLangID;
209 	DWORD                       dwSecurity;
210 	SECURITY_QUALITY_OF_SERVICE qos;
211 }
212 alias CONVCONTEXT* PCONVCONTEXT;
213 
214 struct CONVINFO {
215 	DWORD       cb = CONVINFO.sizeof;
216 	DWORD       hUser;
217 	HCONV       hConvPartner;
218 	HSZ         hszSvcPartner;
219 	HSZ         hszServiceReq;
220 	HSZ         hszTopic;
221 	HSZ         hszItem;
222 	UINT        wFmt;
223 	UINT        wType;
224 	UINT        wStatus;
225 	UINT        wConvst;
226 	UINT        wLastError;
227 	HCONVLIST   hConvList;
228 	CONVCONTEXT ConvCtxt;
229 	HWND        hwnd;
230 	HWND        hwndPartner;
231 }
232 alias CONVINFO* PCONVINFO;
233 
234 struct DDEML_MSG_HOOK_DATA {
235 	UINT     uiLo;
236 	UINT     uiHi;
237 	DWORD    cbData;
238 	DWORD[8] Data;
239 }
240 
241 struct MONHSZSTRUCT {
242 	UINT     cb = MONHSZSTRUCT.sizeof;
243 	int      fsAction;
244 	DWORD    dwTime;
245 	HSZ      hsz;
246 	HANDLE   hTask;
247 	TCHAR[1] _str;
248 
249 	TCHAR* str() { return _str.ptr; }
250 }
251 alias MONHSZSTRUCT* PMONHSZSTRUCT;
252 
253 struct MONLINKSTRUCT {
254 	UINT   cb = MONLINKSTRUCT.sizeof;
255 	DWORD  dwTime;
256 	HANDLE hTask;
257 	BOOL   fEstablished;
258 	BOOL   fNoData;
259 	HSZ    hszSvc;
260 	HSZ    hszTopic;
261 	HSZ    hszItem;
262 	UINT   wFmt;
263 	BOOL   fServer;
264 	HCONV  hConvServer;
265 	HCONV  hConvClient;
266 }
267 alias MONLINKSTRUCT* PMONLINKSTRUCT;
268 
269 struct MONCONVSTRUCT {
270 	UINT   cb = MONCONVSTRUCT.sizeof;
271 	BOOL   fConnect;
272 	DWORD  dwTime;
273 	HANDLE hTask;
274 	HSZ    hszSvc;
275 	HSZ    hszTopic;
276 	HCONV  hConvClient;
277 	HCONV  hConvServer;
278 }
279 alias MONCONVSTRUCT* PMONCONVSTRUCT;
280 
281 struct MONCBSTRUCT {
282 	UINT        cb = MONCBSTRUCT.sizeof;
283 	DWORD       dwTime;
284 	HANDLE      hTask;
285 	DWORD       dwRet;
286 	UINT        wType;
287 	UINT        wFmt;
288 	HCONV       hConv;
289 	HSZ         hsz1;
290 	HSZ         hsz2;
291 	HDDEDATA    hData;
292 	ULONG_PTR   dwData1;
293 	ULONG_PTR   dwData2;
294 	CONVCONTEXT cc;
295 	DWORD       cbData;
296 	DWORD[8]    Data;
297 }
298 alias MONCBSTRUCT* PMONCBSTRUCT;
299 
300 struct MONERRSTRUCT {
301 	UINT   cb = MONERRSTRUCT.sizeof;
302 	UINT   wLastError;
303 	DWORD  dwTime;
304 	HANDLE hTask;
305 }
306 alias MONERRSTRUCT* PMONERRSTRUCT;
307 
308 struct MONMSGSTRUCT {
309 	UINT   cb = MONMSGSTRUCT.sizeof;
310 	HWND   hwndTo;
311 	DWORD  dwTime;
312 	HANDLE hTask;
313 	UINT   wMsg;
314 	WPARAM wParam;
315 	LPARAM lParam;
316 	DDEML_MSG_HOOK_DATA dmhd;
317 }
318 alias MONMSGSTRUCT* PMONMSGSTRUCT;
319 
320 extern (Windows) {
321 	BOOL DdeAbandonTransaction(DWORD, HCONV, DWORD);
322 	PBYTE DdeAccessData(HDDEDATA, PDWORD);
323 	HDDEDATA DdeAddData(HDDEDATA, PBYTE, DWORD, DWORD);
324 	HDDEDATA DdeClientTransaction(PBYTE, DWORD, HCONV, HSZ, UINT, UINT,
325 	  DWORD, PDWORD);
326 	int DdeCmpStringHandles(HSZ, HSZ);
327 	HCONV DdeConnect(DWORD, HSZ, HSZ, PCONVCONTEXT);
328 	HCONVLIST DdeConnectList(DWORD, HSZ, HSZ, HCONVLIST, PCONVCONTEXT);
329 	HDDEDATA DdeCreateDataHandle(DWORD, PBYTE, DWORD, DWORD, HSZ, UINT,
330 	  UINT);
331 	HSZ DdeCreateStringHandleA(DWORD, LPSTR, int);
332 	HSZ DdeCreateStringHandleW(DWORD, LPWSTR, int);
333 	BOOL DdeDisconnect(HCONV);
334 	BOOL DdeDisconnectList(HCONVLIST);
335 	BOOL DdeEnableCallback(DWORD, HCONV, UINT);
336 	BOOL DdeFreeDataHandle(HDDEDATA);
337 	BOOL DdeFreeStringHandle(DWORD, HSZ);
338 	DWORD DdeGetData(HDDEDATA, PBYTE, DWORD, DWORD);
339 	UINT DdeGetLastError(DWORD);
340 	BOOL DdeImpersonateClient(HCONV);
341 	UINT DdeInitializeA(PDWORD, PFNCALLBACK, DWORD, DWORD);
342 	UINT DdeInitializeW(PDWORD, PFNCALLBACK, DWORD, DWORD);
343 	BOOL DdeKeepStringHandle(DWORD, HSZ);
344 	HDDEDATA DdeNameService(DWORD, HSZ, HSZ, UINT);
345 	BOOL DdePostAdvise(DWORD, HSZ, HSZ);
346 	UINT DdeQueryConvInfo(HCONV, DWORD, PCONVINFO);
347 	HCONV DdeQueryNextServer(HCONVLIST, HCONV);
348 	DWORD DdeQueryStringA(DWORD, HSZ, LPSTR, DWORD, int);
349 	DWORD DdeQueryStringW(DWORD, HSZ, LPWSTR, DWORD, int);
350 	HCONV DdeReconnect(HCONV);
351 	BOOL DdeSetUserHandle(HCONV, DWORD, DWORD);
352 	BOOL DdeUnaccessData(HDDEDATA);
353 	BOOL DdeUninitialize(DWORD);
354 }
355 
356 const TCHAR[]
357 	SZDDESYS_TOPIC         = "System",
358 	SZDDESYS_ITEM_TOPICS   = "Topics",
359 	SZDDESYS_ITEM_SYSITEMS = "SysItems",
360 	SZDDESYS_ITEM_RTNMSG   = "ReturnMessage",
361 	SZDDESYS_ITEM_STATUS   = "Status",
362 	SZDDESYS_ITEM_FORMATS  = "Formats",
363 	SZDDESYS_ITEM_HELP     = "Help",
364 	SZDDE_ITEM_ITEMLIST    = "TopicItemList";
365 
366 version (Unicode) {
367 	alias DdeCreateStringHandleW DdeCreateStringHandle;
368 	alias DdeInitializeW DdeInitialize;
369 	alias DdeQueryStringW DdeQueryString;
370 } else {
371 	alias DdeCreateStringHandleA DdeCreateStringHandle;
372 	alias DdeInitializeA DdeInitialize;
373 	alias DdeQueryStringA DdeQueryString;
374 }