Sync to trunk r39350.
[reactos.git] / rostests / winetests / user32 / dde.c
1 /*
2 * Unit tests for DDE functions
3 *
4 * Copyright (c) 2004 Dmitry Timoshkov
5 * Copyright (c) 2007 James Hawkins
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "dde.h"
30 #include "ddeml.h"
31 #include "winerror.h"
32
33 #include "wine/test.h"
34
35 static const WCHAR TEST_DDE_SERVICE[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
36
37 static char exec_cmdA[] = "ANSI dde command";
38 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
39
40 static WNDPROC old_dde_client_wndproc;
41
42 static const DWORD default_timeout = 200;
43
44 static void flush_events(void)
45 {
46 MSG msg;
47 int diff = default_timeout;
48 int min_timeout = 50;
49 DWORD time = GetTickCount() + diff;
50
51 while (diff > 0)
52 {
53 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
54 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
55 diff = time - GetTickCount();
56 min_timeout = 10;
57 }
58 }
59
60 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
61 {
62 WNDCLASSA wcA;
63
64 memset(&wcA, 0, sizeof(wcA));
65 wcA.lpfnWndProc = wndproc;
66 wcA.lpszClassName = name;
67 wcA.hInstance = GetModuleHandleA(0);
68 assert(RegisterClassA(&wcA));
69
70 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
71 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
72 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
73 assert(*hwnd);
74 }
75
76 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
77 {
78 UINT_PTR lo, hi;
79 char str[MAX_PATH], *ptr;
80 HGLOBAL hglobal;
81 DDEDATA *data;
82 DDEPOKE *poke;
83 DWORD size;
84
85 static int msg_index = 0;
86 static HWND client = 0;
87 static BOOL executed = FALSE;
88
89 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
90 return DefWindowProcA(hwnd, msg, wparam, lparam);
91
92 msg_index++;
93
94 switch (msg)
95 {
96 case WM_DDE_INITIATE:
97 {
98 client = (HWND)wparam;
99 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
100
101 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
102 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
103
104 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
105 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
106
107 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
108
109 break;
110 }
111
112 case WM_DDE_REQUEST:
113 {
114 ok((msg_index >= 2 && msg_index <= 4) ||
115 (msg_index >= 7 && msg_index <= 8),
116 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
117 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
118 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
119
120 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
121 if (msg_index < 8)
122 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
123 else
124 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
125
126 if (msg_index == 8)
127 {
128 if (executed)
129 lstrcpyA(str, "command executed\r\n");
130 else
131 lstrcpyA(str, "command not executed\r\n");
132 }
133 else
134 lstrcpyA(str, "requested data\r\n");
135
136 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
137 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
138 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
139
140 data = GlobalLock(hglobal);
141 ZeroMemory(data, size);
142
143 /* setting fResponse to FALSE at this point destroys
144 * the internal messaging state of native dde
145 */
146 data->fResponse = TRUE;
147
148 if (msg_index == 2)
149 data->fRelease = TRUE;
150 else if (msg_index == 3)
151 data->fAckReq = TRUE;
152
153 data->cfFormat = CF_TEXT;
154 lstrcpyA((LPSTR)data->Value, str);
155 GlobalUnlock(hglobal);
156
157 lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
158 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
159
160 break;
161 }
162
163 case WM_DDE_POKE:
164 {
165 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
166 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
167
168 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
169
170 GlobalGetAtomNameA(hi, str, MAX_PATH);
171 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
172
173 poke = GlobalLock((HGLOBAL)lo);
174 ok(poke != NULL, "Expected non-NULL poke\n");
175 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
176 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
177 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
178 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
179
180 if (msg_index == 5)
181 ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
182 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
183 else
184 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
185 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
186
187 GlobalUnlock((HGLOBAL)lo);
188
189 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
190 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
191
192 break;
193 }
194
195 case WM_DDE_EXECUTE:
196 {
197 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
198 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
199
200 ptr = GlobalLock((HGLOBAL)lparam);
201 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
202 GlobalUnlock((HGLOBAL)lparam);
203
204 executed = TRUE;
205
206 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
207 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
208
209 break;
210 }
211
212 case WM_DDE_TERMINATE:
213 {
214 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
215 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
216 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
217
218 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
219
220 break;
221 }
222
223 default:
224 ok(FALSE, "Unhandled msg: %08x\n", msg);
225 }
226
227 return DefWindowProcA(hwnd, msg, wparam, lparam);
228 }
229
230 static void test_msg_server(HANDLE hproc)
231 {
232 MSG msg;
233 HWND hwnd;
234 DWORD res;
235
236 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
237
238 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
239 {
240 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
241 }
242
243 DestroyWindow(hwnd);
244 GetExitCodeProcess( hproc, &res );
245 ok( !res, "client failed with %u error(s)\n", res );
246 }
247
248 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
249 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
250 ULONG_PTR dwData1, ULONG_PTR dwData2)
251 {
252 ok(FALSE, "Unhandled msg: %08x\n", uType);
253 return 0;
254 }
255
256 static void test_ddeml_client(void)
257 {
258 UINT ret;
259 char buffer[32];
260 LPSTR str;
261 DWORD size, res;
262 HDDEDATA hdata, op;
263 HSZ server, topic, item;
264 DWORD client_pid;
265 HCONV conversation;
266
267 client_pid = 0;
268 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
269 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
270
271 /* FIXME: make these atoms global and check them in the server */
272
273 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
274 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
275
276 DdeGetLastError(client_pid);
277 conversation = DdeConnect(client_pid, server, topic, NULL);
278 ok(conversation != NULL, "Expected non-NULL conversation\n");
279 ret = DdeGetLastError(client_pid);
280 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
281
282 DdeFreeStringHandle(client_pid, server);
283
284 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
285
286 /* XTYP_REQUEST, fRelease = TRUE */
287 res = 0xdeadbeef;
288 DdeGetLastError(client_pid);
289 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
290 ret = DdeGetLastError(client_pid);
291 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
292 todo_wine
293 {
294 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", res);
295 }
296 if (hdata == NULL)
297 ok(FALSE, "hdata is NULL\n");
298 else
299 {
300 str = (LPSTR)DdeAccessData(hdata, &size);
301 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
302 ok(size == 19, "Expected 19, got %d\n", size);
303
304 ret = DdeUnaccessData(hdata);
305 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
306 }
307
308 /* XTYP_REQUEST, fAckReq = TRUE */
309 res = 0xdeadbeef;
310 DdeGetLastError(client_pid);
311 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
312 ret = DdeGetLastError(client_pid);
313 todo_wine
314 {
315 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
316 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
317 }
318 if (hdata == NULL)
319 ok(FALSE, "hdata is NULL\n");
320 else
321 {
322 str = (LPSTR)DdeAccessData(hdata, &size);
323 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
324 ok(size == 19, "Expected 19, got %d\n", size);
325
326 ret = DdeUnaccessData(hdata);
327 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
328 }
329
330 /* XTYP_REQUEST, all params normal */
331 res = 0xdeadbeef;
332 DdeGetLastError(client_pid);
333 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
334 ret = DdeGetLastError(client_pid);
335 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
336 todo_wine
337 {
338 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
339 }
340 if (hdata == NULL)
341 ok(FALSE, "hdata is NULL\n");
342 else
343 {
344 str = (LPSTR)DdeAccessData(hdata, &size);
345 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
346 ok(size == 19, "Expected 19, got %d\n", size);
347
348 ret = DdeUnaccessData(hdata);
349 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
350 }
351
352 /* XTYP_REQUEST, no item */
353 res = 0xdeadbeef;
354 DdeGetLastError(client_pid);
355 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
356 ret = DdeGetLastError(client_pid);
357 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
358 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
359 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
360
361 DdeFreeStringHandle(client_pid, item);
362
363 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
364
365 lstrcpyA(buffer, "poke data\r\n");
366 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
367 0, item, CF_TEXT, 0);
368 ok(hdata != NULL, "Expected non-NULL hdata\n");
369
370 /* XTYP_POKE, no item */
371 res = 0xdeadbeef;
372 DdeGetLastError(client_pid);
373 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
374 ret = DdeGetLastError(client_pid);
375 ok(op == NULL, "Expected NULL, got %p\n", op);
376 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
377 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
378
379 /* XTYP_POKE, no data */
380 res = 0xdeadbeef;
381 DdeGetLastError(client_pid);
382 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
383 ret = DdeGetLastError(client_pid);
384 ok(op == NULL, "Expected NULL, got %p\n", op);
385 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
386 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
387
388 /* XTYP_POKE, wrong size */
389 res = 0xdeadbeef;
390 DdeGetLastError(client_pid);
391 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
392 ret = DdeGetLastError(client_pid);
393 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
394 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
395 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
396
397 /* XTYP_POKE, correct params */
398 res = 0xdeadbeef;
399 DdeGetLastError(client_pid);
400 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
401 ret = DdeGetLastError(client_pid);
402 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
403 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
404 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
405
406 DdeFreeDataHandle(hdata);
407
408 lstrcpyA(buffer, "[Command(Var)]");
409 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
410 0, NULL, CF_TEXT, 0);
411 ok(hdata != NULL, "Expected non-NULL hdata\n");
412
413 /* XTYP_EXECUTE, correct params */
414 res = 0xdeadbeef;
415 DdeGetLastError(client_pid);
416 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
417 ret = DdeGetLastError(client_pid);
418 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
419 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
420 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
421
422 /* XTYP_EXECUTE, no data */
423 res = 0xdeadbeef;
424 DdeGetLastError(client_pid);
425 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
426 ret = DdeGetLastError(client_pid);
427 ok(op == NULL, "Expected NULL, got %p\n", op);
428 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
429 todo_wine
430 {
431 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
432 }
433
434 /* XTYP_EXECUTE, no data, -1 size */
435 res = 0xdeadbeef;
436 DdeGetLastError(client_pid);
437 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
438 ret = DdeGetLastError(client_pid);
439 ok(op == NULL, "Expected NULL, got %p\n", op);
440 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
441 todo_wine
442 {
443 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
444 }
445
446 DdeFreeStringHandle(client_pid, topic);
447 DdeFreeDataHandle(hdata);
448
449 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
450
451 /* verify the execute */
452 res = 0xdeadbeef;
453 DdeGetLastError(client_pid);
454 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
455 ret = DdeGetLastError(client_pid);
456 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
457 todo_wine
458 {
459 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
460 }
461 if (hdata == NULL)
462 ok(FALSE, "hdata is NULL\n");
463 else
464 {
465 str = (LPSTR)DdeAccessData(hdata, &size);
466 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
467 ok(size == 21, "Expected 21, got %d\n", size);
468
469 ret = DdeUnaccessData(hdata);
470 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
471 }
472
473 /* invalid transactions */
474 res = 0xdeadbeef;
475 DdeGetLastError(client_pid);
476 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
477 ret = DdeGetLastError(client_pid);
478 ok(op == NULL, "Expected NULL, got %p\n", op);
479 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
480 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
481
482 res = 0xdeadbeef;
483 DdeGetLastError(client_pid);
484 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, default_timeout, &res);
485 ret = DdeGetLastError(client_pid);
486 ok(op == NULL, "Expected NULL, got %p\n", op);
487 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
488 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
489
490 res = 0xdeadbeef;
491 DdeGetLastError(client_pid);
492 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, default_timeout, &res);
493 ret = DdeGetLastError(client_pid);
494 ok(op == NULL, "Expected NULL, got %p\n", op);
495 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
496 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
497
498 res = 0xdeadbeef;
499 DdeGetLastError(client_pid);
500 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, default_timeout, &res);
501 ret = DdeGetLastError(client_pid);
502 ok(op == NULL, "Expected NULL, got %p\n", op);
503 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
504 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
505
506 res = 0xdeadbeef;
507 DdeGetLastError(client_pid);
508 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, default_timeout, &res);
509 ret = DdeGetLastError(client_pid);
510 ok(op == NULL, "Expected NULL, got %p\n", op);
511 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
512 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
513
514 res = 0xdeadbeef;
515 DdeGetLastError(client_pid);
516 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, default_timeout, &res);
517 ret = DdeGetLastError(client_pid);
518 ok(op == NULL, "Expected NULL, got %p\n", op);
519 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
520 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
521
522 res = 0xdeadbeef;
523 DdeGetLastError(client_pid);
524 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, default_timeout, &res);
525 ret = DdeGetLastError(client_pid);
526 ok(op == NULL, "Expected NULL, got %p\n", op);
527 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
528 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
529
530 res = 0xdeadbeef;
531 DdeGetLastError(client_pid);
532 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, default_timeout, &res);
533 ret = DdeGetLastError(client_pid);
534 ok(op == NULL, "Expected NULL, got %p\n", op);
535 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
536 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
537
538 res = 0xdeadbeef;
539 DdeGetLastError(client_pid);
540 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
541 ret = DdeGetLastError(client_pid);
542 ok(op == NULL, "Expected NULL, got %p\n", op);
543 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
544 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
545
546 res = 0xdeadbeef;
547 DdeGetLastError(client_pid);
548 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
549 ret = DdeGetLastError(client_pid);
550 ok(op == NULL, "Expected NULL, got %p\n", op);
551 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
552 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
553
554 DdeFreeStringHandle(client_pid, item);
555
556 ret = DdeDisconnect(conversation);
557 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
558
559 ret = DdeUninitialize(client_pid);
560 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
561 }
562
563 static DWORD server_pid;
564
565 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
566 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
567 ULONG_PTR dwData1, ULONG_PTR dwData2)
568 {
569 char str[MAX_PATH], *ptr;
570 HDDEDATA ret;
571 DWORD size;
572
573 static int msg_index = 0;
574 static HCONV conversation = 0;
575
576 msg_index++;
577
578 switch (uType)
579 {
580 case XTYP_REGISTER:
581 {
582 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
583 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
584 ok(hconv == 0, "Expected 0, got %p\n", hconv);
585 ok(hdata == 0, "Expected 0, got %p\n", hdata);
586 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
587 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
588
589 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
590 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
591 ok(size == 13, "Expected 13, got %d\n", size);
592
593 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
594 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
595 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
596 ok(size == 25, "Expected 25, got %d\n", size);
597
598 return (HDDEDATA)TRUE;
599 }
600
601 case XTYP_CONNECT:
602 {
603 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
604 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
605 ok(hconv == 0, "Expected 0, got %p\n", hconv);
606 ok(hdata == 0, "Expected 0, got %p\n", hdata);
607 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
608 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
609
610 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
611 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
612 ok(size == 12, "Expected 12, got %d\n", size);
613
614 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
615 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
616 ok(size == 13, "Expected 13, got %d\n", size);
617
618 return (HDDEDATA)TRUE;
619 }
620
621 case XTYP_CONNECT_CONFIRM:
622 {
623 conversation = hconv;
624
625 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
626 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
627 ok(hconv != NULL, "Expected non-NULL hconv\n");
628 ok(hdata == 0, "Expected 0, got %p\n", hdata);
629 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
630 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
631
632 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
633 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
634 ok(size == 12, "Expected 12, got %d\n", size);
635
636 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
637 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
638 ok(size == 13, "Expected 13, got %d\n", size);
639
640 return (HDDEDATA)TRUE;
641 }
642
643 case XTYP_REQUEST:
644 {
645 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
646 "Expected 4, 5 or 6, got %d\n", msg_index);
647 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
648 ok(hdata == 0, "Expected 0, got %p\n", hdata);
649 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
650 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
651
652 if (msg_index == 4)
653 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
654 else
655 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
656
657 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
658 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
659 ok(size == 12, "Expected 12, got %d\n", size);
660
661 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
662
663 if (msg_index == 5)
664 {
665 todo_wine
666 {
667 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
668 ok(size == 1, "Expected 1, got %d\n", size);
669 }
670 }
671 else if (msg_index == 6)
672 {
673 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
674 ok(size == 7, "Expected 7, got %d\n", size);
675 }
676
677 if (msg_index == 6)
678 {
679 lstrcpyA(str, "requested data\r\n");
680 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
681 0, hsz2, CF_TEXT, 0);
682 }
683
684 return NULL;
685 }
686
687 case XTYP_POKE:
688 {
689 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
690 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
691 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
692 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
693 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
694
695 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
696 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
697 ok(size == 12, "Expected 12, got %d\n", size);
698
699 ptr = (LPSTR)DdeAccessData(hdata, &size);
700 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
701 todo_wine
702 {
703 ok(size == 14, "Expected 14, got %d\n", size);
704 }
705 DdeUnaccessData(hdata);
706
707 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
708 if (msg_index == 7)
709 {
710 todo_wine
711 {
712 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
713 ok(size == 1, "Expected 1, got %d\n", size);
714 }
715 }
716 else
717 {
718 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
719 ok(size == 4, "Expected 4, got %d\n", size);
720 }
721
722 return (HDDEDATA)DDE_FACK;
723 }
724
725 case XTYP_EXECUTE:
726 {
727 ok(msg_index == 9 || msg_index == 10, "Expected 9 or 10, got %d\n", msg_index);
728 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
729 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
730 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
731 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
732 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
733
734 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
735 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
736 ok(size == 12, "Expected 12, got %d\n", size);
737
738 ptr = (LPSTR)DdeAccessData(hdata, &size);
739
740 if (msg_index == 9)
741 {
742 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
743 ok(size == 15, "Expected 15, got %d\n", size);
744 ret = (HDDEDATA)DDE_FACK;
745 }
746 else
747 {
748 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
749 ok(size == 18, "Expected 18, got %d\n", size);
750 ret = (HDDEDATA)DDE_FNOTPROCESSED;
751 }
752
753 DdeUnaccessData(hdata);
754
755 return ret;
756 }
757
758 case XTYP_DISCONNECT:
759 {
760 ok(msg_index == 11, "Expected 11, got %d\n", msg_index);
761 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
762 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
763 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
764 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
765 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
766 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
767
768 return 0;
769 }
770
771 default:
772 ok(FALSE, "Unhandled msg: %08x\n", uType);
773 }
774
775 return 0;
776 }
777
778 static void test_ddeml_server(HANDLE hproc)
779 {
780 MSG msg;
781 UINT res;
782 BOOL ret;
783 HSZ server;
784 HDDEDATA hdata;
785
786 /* set up DDE server */
787 server_pid = 0;
788 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
789 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
790
791 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
792 ok(server != NULL, "Expected non-NULL string handle\n");
793
794 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
795 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
796
797 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
798 {
799 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
800 }
801 ret = DdeUninitialize(server_pid);
802 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
803 GetExitCodeProcess( hproc, &res );
804 ok( !res, "client failed with %u error(s)\n", res );
805 }
806
807 static HWND client_hwnd, server_hwnd;
808 static ATOM server, topic, item;
809 static HGLOBAL execute_hglobal;
810
811 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
812 {
813 char str[MAX_PATH];
814 UINT_PTR lo, hi;
815 DDEDATA *data;
816 DDEACK *ack;
817 DWORD size;
818 LPSTR ptr;
819
820 static int msg_index = 0;
821
822 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
823 return DefWindowProcA(hwnd, msg, wparam, lparam);
824
825 msg_index++;
826
827 switch (msg)
828 {
829 case WM_DDE_INITIATE:
830 {
831 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
832 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
833
834 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
835 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
836 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
837 ok(size == 13, "Expected 13, got %d\n", size);
838
839 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
840 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
841 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
842 ok(size == 12, "Expected 12, got %d\n", size);
843
844 break;
845 }
846
847 case WM_DDE_ACK:
848 {
849 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 10),
850 "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index);
851
852 if (msg_index == 2)
853 {
854 server_hwnd = (HWND)wparam;
855 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
856
857 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
858 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
859 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
860 ok(size == 13, "Expected 13, got %d\n", size);
861
862 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
863 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
864 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
865 ok(size == 12, "Expected 12, got %d\n", size);
866 }
867 else if (msg_index == 9 || msg_index == 10)
868 {
869 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
870
871 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
872
873 ack = (DDEACK *)&lo;
874 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
875 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
876 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
877
878 ok(hi == (UINT_PTR)execute_hglobal, "Execpted execute hglobal, got %08lx\n", hi);
879 ptr = GlobalLock((HGLOBAL)hi);
880
881 if (msg_index == 9)
882 {
883 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
884 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
885 }
886 else
887 {
888 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
889 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
890 }
891
892 GlobalUnlock((HGLOBAL)hi);
893 }
894 else
895 {
896 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
897
898 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
899
900 ack = (DDEACK *)&lo;
901 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
902 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
903 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
904
905 if (msg_index >= 7)
906 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
907 else
908 {
909 if (msg_index == 6) todo_wine
910 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
911 }
912
913 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
914 if (msg_index == 3)
915 {
916 ok(hi == item, "Expected item atom, got %08lx\n", hi);
917 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
918 ok(size == 7, "Expected 7, got %d\n", size);
919 }
920 else if (msg_index == 4 || msg_index == 7)
921 {
922 ok(hi == 0, "Expected 0, got %08lx\n", hi);
923 ok(size == 0, "Expected empty string, got %d\n", size);
924 }
925 else
926 {
927 ok(hi == item, "Expected item atom, got %08lx\n", hi);
928 if (msg_index == 6) todo_wine
929 {
930 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
931 ok(size == 4, "Expected 4, got %d\n", size);
932 }
933 }
934 }
935
936 break;
937 }
938
939 case WM_DDE_DATA:
940 {
941 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
942 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
943
944 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
945
946 data = GlobalLock((HGLOBAL)lo);
947 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
948 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
949 todo_wine
950 {
951 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
952 }
953 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
954 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
955 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
956 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
957 GlobalUnlock((HGLOBAL)lo);
958
959 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
960 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
961 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
962 ok(size == 7, "Expected 7, got %d\n", size);
963
964 GlobalFree((HGLOBAL)lo);
965 GlobalDeleteAtom(hi);
966
967 break;
968 }
969
970 default:
971 ok(FALSE, "Unhandled msg: %08x\n", msg);
972 }
973
974 return DefWindowProcA(hwnd, msg, wparam, lparam);
975 }
976
977 static HGLOBAL create_poke()
978 {
979 HGLOBAL hglobal;
980 DDEPOKE *poke;
981 DWORD size;
982
983 size = sizeof(DDEPOKE) + lstrlenA("poke data\r\n") + 1;
984 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
985 ok(hglobal != 0, "Expected non-NULL hglobal\n");
986
987 poke = GlobalLock(hglobal);
988 poke->unused = 0;
989 poke->fRelease = TRUE;
990 poke->fReserved = TRUE;
991 poke->cfFormat = CF_TEXT;
992 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
993 GlobalUnlock(hglobal);
994
995 return hglobal;
996 }
997
998 static HGLOBAL create_execute(LPCSTR command)
999 {
1000 HGLOBAL hglobal;
1001 LPSTR ptr;
1002
1003 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1004 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1005
1006 ptr = GlobalLock(hglobal);
1007 lstrcpyA(ptr, command);
1008 GlobalUnlock(hglobal);
1009
1010 return hglobal;
1011 }
1012
1013 static void test_msg_client()
1014 {
1015 HGLOBAL hglobal;
1016 LPARAM lparam;
1017
1018 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1019
1020 server = GlobalAddAtomA("TestDDEServer");
1021 ok(server != 0, "Expected non-NULL server\n");
1022
1023 topic = GlobalAddAtomA("TestDDETopic");
1024 ok(topic != 0, "Expected non-NULL topic\n");
1025
1026 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1027
1028 GlobalDeleteAtom(server);
1029 GlobalDeleteAtom(topic);
1030
1031 flush_events();
1032
1033 item = GlobalAddAtom("request");
1034 ok(item != 0, "Expected non-NULL item\n");
1035
1036 /* WM_DDE_REQUEST, bad clipboard format */
1037 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1038 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1039
1040 flush_events();
1041
1042 /* WM_DDE_REQUEST, no item */
1043 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1044 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1045
1046 flush_events();
1047
1048 /* WM_DDE_REQUEST, no client hwnd */
1049 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1050 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1051
1052 flush_events();
1053
1054 /* WM_DDE_REQUEST, correct params */
1055 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1056 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1057
1058 flush_events();
1059
1060 GlobalDeleteAtom(item);
1061 item = GlobalAddAtomA("poke");
1062 ok(item != 0, "Expected non-NULL item\n");
1063
1064 hglobal = create_poke();
1065
1066 /* WM_DDE_POKE, no ddepoke */
1067 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1068 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1069
1070 flush_events();
1071
1072 /* WM_DDE_POKE, no item */
1073 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1074 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1075
1076 flush_events();
1077
1078 hglobal = create_poke();
1079
1080 /* WM_DDE_POKE, no client hwnd */
1081 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1082 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1083
1084 flush_events();
1085
1086 /* WM_DDE_POKE, all params correct */
1087 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1088 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1089
1090 flush_events();
1091
1092 execute_hglobal = create_execute("[Command(Var)]");
1093
1094 /* WM_DDE_EXECUTE, no lparam */
1095 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1096
1097 flush_events();
1098
1099 /* WM_DDE_EXECUTE, no hglobal */
1100 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1101 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1102
1103 flush_events();
1104
1105 /* WM_DDE_EXECUTE, no client hwnd */
1106 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1107 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1108
1109 flush_events();
1110
1111 /* WM_DDE_EXECUTE, all params correct */
1112 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1113 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1114
1115 flush_events();
1116
1117 GlobalFree(execute_hglobal);
1118 execute_hglobal = create_execute("[BadCommand(Var)]");
1119
1120 /* WM_DDE_EXECUTE that will get rejected */
1121 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1122 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1123
1124 flush_events();
1125
1126 DestroyWindow(client_hwnd);
1127 }
1128
1129 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1130 {
1131 UINT_PTR lo, hi;
1132
1133 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1134
1135 switch (msg)
1136 {
1137 case WM_DDE_ACK:
1138 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1139 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1140 break;
1141
1142 default:
1143 break;
1144 }
1145 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1146 }
1147
1148 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1149 {
1150 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1151
1152 switch (msg)
1153 {
1154 case WM_DDE_INITIATE:
1155 {
1156 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1157
1158 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
1159
1160 if (LOWORD(lparam) == aService)
1161 {
1162 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
1163 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
1164 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1165 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
1166 }
1167 else
1168 GlobalDeleteAtom(aService);
1169 return 0;
1170 }
1171
1172 case WM_DDE_EXECUTE:
1173 {
1174 DDEACK ack;
1175 WORD status;
1176 LPCSTR cmd;
1177 UINT_PTR lo, hi;
1178
1179 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1180
1181 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1182 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1183
1184 ack.bAppReturnCode = 0;
1185 ack.reserved = 0;
1186 ack.fBusy = 0;
1187
1188 cmd = GlobalLock((HGLOBAL)hi);
1189
1190 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
1191 {
1192 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1193 /* We have to send a negative acknowledge even if we don't
1194 * accept the command, otherwise Windows goes mad and next time
1195 * we send an acknowledge DDEML drops the connection.
1196 * Not sure how to call it: a bug or a feature.
1197 */
1198 ack.fAck = 0;
1199 }
1200 else
1201 ack.fAck = 1;
1202 GlobalUnlock((HGLOBAL)hi);
1203
1204 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1205
1206 status = *((WORD *)&ack);
1207 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1208
1209 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1210 return 0;
1211 }
1212
1213 case WM_DDE_TERMINATE:
1214 {
1215 DDEACK ack;
1216 WORD status;
1217
1218 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1219
1220 ack.bAppReturnCode = 0;
1221 ack.reserved = 0;
1222 ack.fBusy = 0;
1223 ack.fAck = 1;
1224
1225 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1226
1227 status = *((WORD *)&ack);
1228 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1229
1230 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1231 return 0;
1232 }
1233
1234 default:
1235 break;
1236 }
1237
1238 return DefWindowProcW(hwnd, msg, wparam, lparam);
1239 }
1240
1241 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1242 {
1243 return DefWindowProcA(hwnd, msg, wparam, lparam);
1244 }
1245
1246 static BOOL create_dde_windows(HWND *client, HWND *server)
1247 {
1248 WNDCLASSA wcA;
1249 WNDCLASSW wcW;
1250 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1251 static const char client_class_name[] = "dde_client_window";
1252
1253 memset(&wcW, 0, sizeof(wcW));
1254 wcW.lpfnWndProc = dde_server_wndprocW;
1255 wcW.lpszClassName = server_class_name;
1256 wcW.hInstance = GetModuleHandleA(0);
1257 if (!RegisterClassW(&wcW)) return FALSE;
1258
1259 memset(&wcA, 0, sizeof(wcA));
1260 wcA.lpfnWndProc = dde_client_wndproc;
1261 wcA.lpszClassName = client_class_name;
1262 wcA.hInstance = GetModuleHandleA(0);
1263 assert(RegisterClassA(&wcA));
1264
1265 *server = CreateWindowExW(0, server_class_name, NULL,
1266 WS_POPUP,
1267 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1268 GetDesktopWindow(), 0,
1269 GetModuleHandleA(0), NULL);
1270 assert(*server);
1271
1272 *client = CreateWindowExA(0, client_class_name, NULL,
1273 WS_POPUP,
1274 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1275 GetDesktopWindow(), 0,
1276 GetModuleHandleA(0), NULL);
1277 assert(*client);
1278
1279 trace("server hwnd %p, client hwnd %p\n", *server, *client);
1280
1281 ok(IsWindowUnicode(*server), "server has to be a unicode window\n");
1282 ok(!IsWindowUnicode(*client), "client has to be an ANSI window\n");
1283
1284 return TRUE;
1285 }
1286
1287 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1288 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1289 ULONG_PTR dwData1, ULONG_PTR dwData2)
1290 {
1291 static const char * const cmd_type[15] = {
1292 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1293 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1294 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1295 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1296 UINT type;
1297 const char *cmd_name;
1298
1299 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1300 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1301
1302 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1303 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1304 return 0;
1305 }
1306
1307 static void test_dde_aw_transaction(void)
1308 {
1309 HSZ hsz_server;
1310 DWORD dde_inst, ret, err;
1311 HCONV hconv;
1312 HWND hwnd_client, hwnd_server;
1313 CONVINFO info;
1314 HDDEDATA hdata;
1315 static char test_cmd[] = "test dde command";
1316
1317 /* server: unicode, client: ansi */
1318 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
1319
1320 dde_inst = 0;
1321 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1322 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
1323 ret, DdeGetLastError(dde_inst));
1324
1325 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1326
1327 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1328 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1329 err = DdeGetLastError(dde_inst);
1330 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1331
1332 info.cb = sizeof(info);
1333 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1334 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1335 /* should be CP_WINANSI since we used DdeInitializeA */
1336 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1337 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1338 todo_wine {
1339 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1340 }
1341 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1342 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1343 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1344
1345 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
1346
1347 trace("sending test client transaction command\n");
1348 ret = 0xdeadbeef;
1349 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1350 ok(!hdata, "DdeClientTransaction succeeded\n");
1351 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1352 err = DdeGetLastError(dde_inst);
1353 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1354
1355 trace("sending ANSI client transaction command\n");
1356 ret = 0xdeadbeef;
1357 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1358 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1359 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1360
1361 err = DdeGetLastError(dde_inst);
1362 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1363
1364 trace("sending unicode client transaction command\n");
1365 ret = 0xdeadbeef;
1366 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1367 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1368 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1369 err = DdeGetLastError(dde_inst);
1370 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1371
1372 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1373
1374 info.cb = sizeof(info);
1375 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1376 ok(!ret, "DdeQueryConvInfo should fail\n");
1377 err = DdeGetLastError(dde_inst);
1378 todo_wine {
1379 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1380 }
1381
1382 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1383
1384 /* This call hangs on win2k SP4 and XP SP1.
1385 DdeUninitialize(dde_inst);*/
1386
1387 DestroyWindow(hwnd_client);
1388 DestroyWindow(hwnd_server);
1389 }
1390
1391 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1392 {
1393 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1394 HSZ str_handle;
1395 WCHAR bufW[256];
1396 char buf[256];
1397 ATOM atom;
1398 int ret;
1399
1400 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1401 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1402 DdeGetLastError(dde_inst));
1403
1404 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1405 if (codepage == CP_WINANSI)
1406 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1407 else
1408 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1409
1410 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1411 if (codepage == CP_WINANSI)
1412 {
1413 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1414 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1415 }
1416 else
1417 {
1418 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1419 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1420 }
1421
1422 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1423 if (codepage == CP_WINANSI)
1424 {
1425 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1426 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1427 }
1428 else
1429 {
1430 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1431 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1432 }
1433
1434 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1435 if (codepage == CP_WINANSI)
1436 {
1437 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1438 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1439 }
1440 else
1441 {
1442 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1443 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1444 }
1445
1446 if (codepage == CP_WINANSI)
1447 {
1448 atom = FindAtomA((LPSTR)dde_string);
1449 ok(atom != 0, "Expected a valid atom\n");
1450
1451 SetLastError(0xdeadbeef);
1452 atom = GlobalFindAtomA((LPSTR)dde_string);
1453 ok(atom == 0, "Expected 0, got %d\n", atom);
1454 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1455 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1456 }
1457 else
1458 {
1459 atom = FindAtomW(dde_string);
1460 ok(atom != 0, "Expected a valid atom\n");
1461
1462 SetLastError(0xdeadbeef);
1463 atom = GlobalFindAtomW(dde_string);
1464 ok(atom == 0, "Expected 0, got %d\n", atom);
1465 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1466 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1467 }
1468
1469 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1470 }
1471
1472 static void test_DdeCreateDataHandle(void)
1473 {
1474 HDDEDATA hdata;
1475 DWORD dde_inst;
1476 DWORD size;
1477 UINT res, err;
1478 BOOL ret;
1479 HSZ item;
1480 LPBYTE ptr;
1481
1482 dde_inst = 0;
1483 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1484 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1485
1486 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1487 ok(item != NULL, "Expected non-NULL hsz\n");
1488
1489 /* invalid instance id */
1490 DdeGetLastError(dde_inst);
1491 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1492 err = DdeGetLastError(dde_inst);
1493 todo_wine
1494 {
1495 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1496 ok(err == DMLERR_INVALIDPARAMETER,
1497 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1498 }
1499
1500 /* 0 instance id */
1501 DdeGetLastError(dde_inst);
1502 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1503 err = DdeGetLastError(dde_inst);
1504 todo_wine
1505 {
1506 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1507 ok(err == DMLERR_INVALIDPARAMETER,
1508 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1509 }
1510
1511 /* NULL pSrc */
1512 DdeGetLastError(dde_inst);
1513 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1514 err = DdeGetLastError(dde_inst);
1515 ok(hdata != NULL, "Expected non-NULL hdata\n");
1516 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1517
1518 ptr = GlobalLock(hdata);
1519 todo_wine
1520 {
1521 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1522 }
1523
1524 ptr = DdeAccessData(hdata, &size);
1525 ok(ptr != NULL, "Expected non-NULL ptr\n");
1526 ok(size == 260, "Expected 260, got %d\n", size);
1527
1528 ret = DdeUnaccessData(hdata);
1529 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1530
1531 ret = DdeFreeDataHandle(hdata);
1532 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1533
1534 /* cb is zero */
1535 DdeGetLastError(dde_inst);
1536 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1537 err = DdeGetLastError(dde_inst);
1538 ok(hdata != NULL, "Expected non-NULL hdata\n");
1539 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1540
1541 ptr = GlobalLock(hdata);
1542 todo_wine
1543 {
1544 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1545 }
1546
1547 ptr = DdeAccessData(hdata, &size);
1548 ok(ptr != NULL, "Expected non-NULL ptr\n");
1549 ok(size == 0, "Expected 0, got %d\n", size);
1550
1551 ret = DdeUnaccessData(hdata);
1552 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1553
1554 ret = DdeFreeDataHandle(hdata);
1555 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1556
1557 /* cbOff is non-zero */
1558 DdeGetLastError(dde_inst);
1559 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1560 err = DdeGetLastError(dde_inst);
1561 ok(hdata != NULL, "Expected non-NULL hdata\n");
1562 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1563
1564 ptr = GlobalLock(hdata);
1565 todo_wine
1566 {
1567 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1568 }
1569
1570 ptr = DdeAccessData(hdata, &size);
1571 ok(ptr != NULL, "Expected non-NULL ptr\n");
1572 ok(size == 262, "Expected 262, got %d\n", size);
1573 todo_wine
1574 {
1575 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1576 }
1577
1578 ret = DdeUnaccessData(hdata);
1579 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1580
1581 ret = DdeFreeDataHandle(hdata);
1582 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1583
1584 /* NULL item */
1585 DdeGetLastError(dde_inst);
1586 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1587 err = DdeGetLastError(dde_inst);
1588 ok(hdata != NULL, "Expected non-NULL hdata\n");
1589 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1590
1591 ptr = GlobalLock(hdata);
1592 todo_wine
1593 {
1594 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1595 }
1596
1597 ptr = DdeAccessData(hdata, &size);
1598 ok(ptr != NULL, "Expected non-NULL ptr\n");
1599 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1600 ok(size == 260, "Expected 260, got %d\n", size);
1601
1602 ret = DdeUnaccessData(hdata);
1603 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1604
1605 ret = DdeFreeDataHandle(hdata);
1606 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1607
1608 /* NULL item */
1609 DdeGetLastError(dde_inst);
1610 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1611 err = DdeGetLastError(dde_inst);
1612 ok(hdata != NULL, "Expected non-NULL hdata\n");
1613 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1614
1615 ptr = GlobalLock(hdata);
1616 todo_wine
1617 {
1618 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1619 }
1620
1621 ptr = DdeAccessData(hdata, &size);
1622 ok(ptr != NULL, "Expected non-NULL ptr\n");
1623 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1624 ok(size == 260, "Expected 260, got %d\n", size);
1625
1626 ret = DdeUnaccessData(hdata);
1627 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1628
1629 ret = DdeFreeDataHandle(hdata);
1630 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1631
1632 /* invalid clipboard format */
1633 DdeGetLastError(dde_inst);
1634 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
1635 err = DdeGetLastError(dde_inst);
1636 ok(hdata != NULL, "Expected non-NULL hdata\n");
1637 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1638
1639 ptr = GlobalLock(hdata);
1640 todo_wine
1641 {
1642 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1643 }
1644
1645 ptr = DdeAccessData(hdata, &size);
1646 ok(ptr != NULL, "Expected non-NULL ptr\n");
1647 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1648 ok(size == 260, "Expected 260, got %d\n", size);
1649
1650 ret = DdeUnaccessData(hdata);
1651 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1652
1653 ret = DdeFreeDataHandle(hdata);
1654 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1655
1656 ret = DdeUninitialize(dde_inst);
1657 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1658 }
1659
1660 static void test_DdeCreateStringHandle(void)
1661 {
1662 DWORD dde_inst, ret;
1663
1664 dde_inst = 0xdeadbeef;
1665 SetLastError(0xdeadbeef);
1666 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1667 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1668 {
1669 trace("Skipping the DDE test on a Win9x platform\n");
1670 return;
1671 }
1672
1673 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
1674 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
1675
1676 dde_inst = 0;
1677 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1678 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
1679 ret, DdeGetLastError(dde_inst));
1680
1681 test_DdeCreateStringHandleW(dde_inst, 0);
1682 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
1683 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
1684
1685 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
1686 }
1687
1688 static void test_FreeDDElParam(void)
1689 {
1690 HGLOBAL val, hglobal;
1691 BOOL ret;
1692
1693 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
1694 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1695
1696 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1697 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
1698 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1699 val = GlobalFree(hglobal);
1700 ok(val == NULL, "Expected NULL, got %p\n", val);
1701
1702 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1703 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
1704 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1705 val = GlobalFree(hglobal);
1706 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1707 ok(GetLastError() == ERROR_INVALID_HANDLE,
1708 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1709
1710 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1711 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
1712 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1713 val = GlobalFree(hglobal);
1714 ok(val == NULL, "Expected NULL, got %p\n", val);
1715
1716 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1717 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
1718 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1719 val = GlobalFree(hglobal);
1720 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1721 ok(GetLastError() == ERROR_INVALID_HANDLE,
1722 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1723
1724 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1725 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
1726 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1727 val = GlobalFree(hglobal);
1728 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1729 ok(GetLastError() == ERROR_INVALID_HANDLE,
1730 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1731
1732 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1733 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
1734 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1735 val = GlobalFree(hglobal);
1736 ok(val == NULL, "Expected NULL, got %p\n", val);
1737
1738 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1739 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1740 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1741 val = GlobalFree(hglobal);
1742 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1743 ok(GetLastError() == ERROR_INVALID_HANDLE,
1744 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1745
1746 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1747 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1748 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1749 val = GlobalFree(hglobal);
1750 ok(val == NULL, "Expected NULL, got %p\n", val);
1751 }
1752
1753 static void test_PackDDElParam(void)
1754 {
1755 UINT_PTR lo, hi, *ptr;
1756 HGLOBAL hglobal;
1757 LPARAM lparam;
1758 BOOL ret;
1759
1760 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1761 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1762 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1763 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1764 ok(GetLastError() == ERROR_INVALID_HANDLE,
1765 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1766
1767 lo = hi = 0;
1768 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1769 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1770 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1771 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1772
1773 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1774 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1775
1776 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1777 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1778 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1779 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1780 ok(GetLastError() == ERROR_INVALID_HANDLE,
1781 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1782
1783 lo = hi = 0;
1784 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1785 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1786 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1787 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1788
1789 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1790 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1791
1792 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1793 ptr = GlobalLock((HGLOBAL)lparam);
1794 ok(ptr != NULL, "Expected non-NULL ptr\n");
1795 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1796 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1797
1798 ret = GlobalUnlock((HGLOBAL)lparam);
1799 ok(ret == 1, "Expected 1, got %d\n", ret);
1800
1801 lo = hi = 0;
1802 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1803 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1804 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1805 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1806
1807 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1808 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1809
1810 hglobal = GlobalFree((HGLOBAL)lparam);
1811 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1812 ok(GetLastError() == ERROR_INVALID_HANDLE,
1813 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1814
1815 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1816 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1817 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1818 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1819 ok(GetLastError() == ERROR_INVALID_HANDLE,
1820 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1821
1822 lo = hi = 0;
1823 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1824 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1825 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1826 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1827
1828 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1829 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1830
1831 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1832 ptr = GlobalLock((HGLOBAL)lparam);
1833 ok(ptr != NULL, "Expected non-NULL ptr\n");
1834 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1835 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1836
1837 ret = GlobalUnlock((HGLOBAL)lparam);
1838 ok(ret == 1, "Expected 1, got %d\n", ret);
1839
1840 lo = hi = 0;
1841 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1842 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1843 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1844 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1845
1846 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1847 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1848
1849 hglobal = GlobalFree((HGLOBAL)lparam);
1850 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1851 ok(GetLastError() == ERROR_INVALID_HANDLE,
1852 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1853
1854 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1855 ptr = GlobalLock((HGLOBAL)lparam);
1856 ok(ptr != NULL, "Expected non-NULL ptr\n");
1857 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1858 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1859
1860 ret = GlobalUnlock((HGLOBAL)lparam);
1861 ok(ret == 1, "Expected 1, got %d\n", ret);
1862
1863 lo = hi = 0;
1864 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1865 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1866 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1867 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1868
1869 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1870 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1871
1872 hglobal = GlobalFree((HGLOBAL)lparam);
1873 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1874 ok(GetLastError() == ERROR_INVALID_HANDLE,
1875 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1876
1877 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1878 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1879 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1880 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1881 ok(GetLastError() == ERROR_INVALID_HANDLE,
1882 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1883
1884 lo = hi = 0;
1885 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1886 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1887 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1888 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1889
1890 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1891 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1892
1893 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1894 ptr = GlobalLock((HGLOBAL)lparam);
1895 ok(ptr != NULL, "Expected non-NULL ptr\n");
1896 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1897 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1898
1899 ret = GlobalUnlock((HGLOBAL)lparam);
1900 ok(ret == 1, "Expected 1, got %d\n", ret);
1901
1902 lo = hi = 0;
1903 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1904 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1905 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1906 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1907
1908 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1909 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1910
1911 hglobal = GlobalFree((HGLOBAL)lparam);
1912 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1913 ok(GetLastError() == ERROR_INVALID_HANDLE,
1914 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1915
1916 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1917 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1918 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1919 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1920 ok(GetLastError() == ERROR_INVALID_HANDLE,
1921 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1922
1923 lo = hi = 0;
1924 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1925 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1926 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1927 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1928
1929 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1930 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1931 }
1932
1933 static void test_UnpackDDElParam(void)
1934 {
1935 UINT_PTR lo, hi, *ptr;
1936 HGLOBAL hglobal;
1937 BOOL ret;
1938
1939 /* NULL lParam */
1940 lo = 0xdead;
1941 hi = 0xbeef;
1942 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1943 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1944 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1945 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1946
1947 /* NULL lo */
1948 lo = 0xdead;
1949 hi = 0xbeef;
1950 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1951 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1952 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1953 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1954
1955 /* NULL hi */
1956 lo = 0xdead;
1957 hi = 0xbeef;
1958 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1959 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1960 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1961 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1962
1963 lo = 0xdead;
1964 hi = 0xbeef;
1965 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1966 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1967 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1968 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1969
1970 lo = 0xdead;
1971 hi = 0xbeef;
1972 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1973 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1974 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1975 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1976
1977 lo = 0xdead;
1978 hi = 0xbeef;
1979 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1980 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1981 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1982 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1983
1984 lo = 0xdead;
1985 hi = 0xbeef;
1986 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1987 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1988 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1989 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1990
1991 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1992 ptr = GlobalLock(hglobal);
1993 ptr[0] = 0xcafebabe;
1994 ptr[1] = 0xdeadbeef;
1995 GlobalUnlock(hglobal);
1996
1997 lo = 0xdead;
1998 hi = 0xbeef;
1999 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2000 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2001 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2002 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2003
2004 lo = 0xdead;
2005 hi = 0xbeef;
2006 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2007 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2008 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2009 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2010
2011 lo = 0xdead;
2012 hi = 0xbeef;
2013 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
2014 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2015 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2016 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2017
2018 lo = 0xdead;
2019 hi = 0xbeef;
2020 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2021 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2022 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2023 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2024
2025 lo = 0xdead;
2026 hi = 0xbeef;
2027 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
2028 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2029 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2030 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2031
2032 lo = 0xdead;
2033 hi = 0xbeef;
2034 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2035 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2036 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2037 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2038
2039 lo = 0xdead;
2040 hi = 0xbeef;
2041 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2042 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2043 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2044 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2045
2046 lo = 0xdead;
2047 hi = 0xbeef;
2048 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
2049 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2050 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2051 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2052
2053 lo = 0xdead;
2054 hi = 0xbeef;
2055 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2056 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2057 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2058 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2059
2060 lo = 0xdead;
2061 hi = 0xbeef;
2062 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2063 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2064 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2065 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2066 }
2067
2068 START_TEST(dde)
2069 {
2070 int argc;
2071 char **argv;
2072 char buffer[MAX_PATH];
2073 STARTUPINFO startup;
2074 PROCESS_INFORMATION proc;
2075
2076 argc = winetest_get_mainargs(&argv);
2077 if (argc == 3)
2078 {
2079 if (!lstrcmpA(argv[2], "ddeml"))
2080 test_ddeml_client();
2081 else if (!lstrcmpA(argv[2], "msg"))
2082 test_msg_client();
2083
2084 return;
2085 }
2086
2087 ZeroMemory(&startup, sizeof(STARTUPINFO));
2088 sprintf(buffer, "%s dde ddeml", argv[0]);
2089 startup.cb = sizeof(startup);
2090 startup.dwFlags = STARTF_USESHOWWINDOW;
2091 startup.wShowWindow = SW_SHOWNORMAL;
2092
2093 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2094 0, NULL, NULL, &startup, &proc);
2095
2096 test_msg_server(proc.hProcess);
2097
2098 sprintf(buffer, "%s dde msg", argv[0]);
2099 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2100 0, NULL, NULL, &startup, &proc);
2101
2102 test_ddeml_server(proc.hProcess);
2103
2104 test_dde_aw_transaction();
2105
2106 test_DdeCreateDataHandle();
2107 test_DdeCreateStringHandle();
2108 test_FreeDDElParam();
2109 test_PackDDElParam();
2110 test_UnpackDDElParam();
2111 }