2 * Unit tests for DDE functions
4 * Copyright (c) 2004 Dmitry Timoshkov
5 * Copyright (c) 2007 James Hawkins
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.
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.
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
33 #include "wine/test.h"
35 static const WCHAR TEST_DDE_SERVICE[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
37 static char exec_cmdA[] = "ANSI dde command";
38 static WCHAR exec_cmdAW[] = {'A','N','S','I',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
39 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
40 static char exec_cmdWA[] = "unicode dde command";
42 static WNDPROC old_dde_client_wndproc;
44 static const DWORD default_timeout = 200;
46 static void flush_events(void)
49 int diff = default_timeout;
51 DWORD time = GetTickCount() + diff;
55 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
56 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
57 diff = time - GetTickCount();
62 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
67 memset(&wcA, 0, sizeof(wcA));
68 wcA.lpfnWndProc = wndproc;
69 wcA.lpszClassName = name;
70 wcA.hInstance = GetModuleHandleA(0);
71 aclass = RegisterClassA(&wcA);
72 ok (aclass, "RegisterClass failed\n");
74 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
75 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
76 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
77 ok(*hwnd != NULL, "CreateWindowExA failed\n");
80 static void destroy_dde_window(HWND *hwnd, LPCSTR name)
83 UnregisterClass(name, GetModuleHandleA(0));
86 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
89 char str[MAX_PATH], *ptr;
95 static int msg_index = 0;
96 static HWND client = 0;
97 static BOOL executed = FALSE;
99 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
100 return DefWindowProcA(hwnd, msg, wparam, lparam);
106 case WM_DDE_INITIATE:
108 client = (HWND)wparam;
109 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
111 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
112 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
114 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
115 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
117 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
124 ok((msg_index >= 2 && msg_index <= 4) ||
125 (msg_index >= 7 && msg_index <= 8),
126 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
127 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
128 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
130 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
132 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
134 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
139 lstrcpyA(str, "command executed\r\n");
141 lstrcpyA(str, "command not executed\r\n");
144 lstrcpyA(str, "requested data\r\n");
146 size = FIELD_OFFSET(DDEDATA, Value[lstrlenA(str) + 1]);
147 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
148 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
150 data = GlobalLock(hglobal);
151 ZeroMemory(data, size);
153 /* setting fResponse to FALSE at this point destroys
154 * the internal messaging state of native dde
156 data->fResponse = TRUE;
159 data->fRelease = TRUE;
160 else if (msg_index == 3)
161 data->fAckReq = TRUE;
163 data->cfFormat = CF_TEXT;
164 lstrcpyA((LPSTR)data->Value, str);
165 GlobalUnlock(hglobal);
167 lparam = PackDDElParam(WM_DDE_DATA, (UINT_PTR)hglobal, HIWORD(lparam));
168 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
175 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
176 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
178 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
180 GlobalGetAtomNameA(hi, str, MAX_PATH);
181 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
183 poke = GlobalLock((HGLOBAL)lo);
184 ok(poke != NULL, "Expected non-NULL poke\n");
185 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
186 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
187 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
188 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
192 size = GlobalSize((HGLOBAL)lo);
193 ok(size == 4 || broken(size == 32), /* sizes are rounded up on win9x */ "got %d\n", size);
196 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
197 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
199 GlobalUnlock((HGLOBAL)lo);
201 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
202 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
209 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
210 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
212 ptr = GlobalLock((HGLOBAL)lparam);
213 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
214 GlobalUnlock((HGLOBAL)lparam);
218 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, lparam);
219 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
224 case WM_DDE_TERMINATE:
226 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
227 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
228 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
230 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
235 case WM_DDE_ACK: /* happens on win9x when fAckReq is TRUE, ignore it */
236 ok(msg_index == 4, "Expected 4, got %d\n", msg_index);
241 ok(FALSE, "Unhandled msg: %08x\n", msg);
244 return DefWindowProcA(hwnd, msg, wparam, lparam);
247 static void test_msg_server(HANDLE hproc, HANDLE hthread)
253 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
254 ResumeThread( hthread );
256 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
258 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
261 destroy_dde_window(&hwnd, "dde_server");
262 GetExitCodeProcess( hproc, &res );
263 ok( !res, "client failed with %u error(s)\n", res );
266 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
267 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
268 ULONG_PTR dwData1, ULONG_PTR dwData2)
270 ok(FALSE, "Unhandled msg: %08x\n", uType);
274 static void test_ddeml_client(void)
281 HSZ server, topic, item;
286 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
287 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
289 /* FIXME: make these atoms global and check them in the server */
291 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
292 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
294 DdeGetLastError(client_pid);
295 conversation = DdeConnect(client_pid, server, topic, NULL);
296 ok(conversation != NULL, "Expected non-NULL conversation\n");
297 ret = DdeGetLastError(client_pid);
298 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
300 DdeFreeStringHandle(client_pid, server);
302 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
304 /* XTYP_REQUEST, fRelease = TRUE */
306 DdeGetLastError(client_pid);
307 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
308 ret = DdeGetLastError(client_pid);
309 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
310 ok(res == DDE_FNOTPROCESSED || broken(res == 0xdeadbeef), /* win9x */
311 "Expected DDE_FNOTPROCESSED, got %08x\n", res);
312 ok( hdata != NULL, "hdata is NULL\n" );
315 str = (LPSTR)DdeAccessData(hdata, &size);
316 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
317 ok(size == 17, "Expected 17, got %d\n", size);
319 ret = DdeUnaccessData(hdata);
320 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
323 /* XTYP_REQUEST, fAckReq = TRUE */
325 DdeGetLastError(client_pid);
326 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
327 ret = DdeGetLastError(client_pid);
328 ok(res == DDE_FNOTPROCESSED || broken(res == 0xdeadbeef), /* win9x */
329 "Expected DDE_FNOTPROCESSED, got %x\n", res);
331 ok(ret == DMLERR_MEMORY_ERROR || broken(ret == 0), /* win9x */
332 "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
333 ok( hdata != NULL, "hdata is NULL\n" );
336 str = (LPSTR)DdeAccessData(hdata, &size);
337 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
338 ok(size == 17, "Expected 17, got %d\n", size);
340 ret = DdeUnaccessData(hdata);
341 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
344 /* XTYP_REQUEST, all params normal */
346 DdeGetLastError(client_pid);
347 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
348 ret = DdeGetLastError(client_pid);
349 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
350 ok(res == DDE_FNOTPROCESSED || broken(res == 0xdeadbeef), /* win9x */
351 "Expected DDE_FNOTPROCESSED, got %x\n", res);
353 ok(FALSE, "hdata is NULL\n");
356 str = (LPSTR)DdeAccessData(hdata, &size);
357 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
358 ok(size == 17, "Expected 17, got %d\n", size);
360 ret = DdeUnaccessData(hdata);
361 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
364 /* XTYP_REQUEST, no item */
366 DdeGetLastError(client_pid);
367 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
368 ret = DdeGetLastError(client_pid);
369 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
370 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
371 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
373 DdeFreeStringHandle(client_pid, item);
375 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
377 lstrcpyA(buffer, "poke data\r\n");
378 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
379 0, item, CF_TEXT, 0);
380 ok(hdata != NULL, "Expected non-NULL hdata\n");
382 /* XTYP_POKE, no item */
384 DdeGetLastError(client_pid);
385 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
386 ret = DdeGetLastError(client_pid);
387 ok(op == NULL, "Expected NULL, got %p\n", op);
388 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
389 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
391 /* XTYP_POKE, no data */
393 DdeGetLastError(client_pid);
394 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
395 ret = DdeGetLastError(client_pid);
396 ok(op == NULL, "Expected NULL, got %p\n", op);
397 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
398 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
400 /* XTYP_POKE, wrong size */
402 DdeGetLastError(client_pid);
403 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
404 ret = DdeGetLastError(client_pid);
405 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
406 ok(res == DDE_FACK || broken(res == (0xdead0000 | DDE_FACK)), /* win9x */
407 "Expected DDE_FACK, got %x\n", res);
408 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
410 /* XTYP_POKE, correct params */
412 DdeGetLastError(client_pid);
413 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
414 ret = DdeGetLastError(client_pid);
415 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
416 ok(res == DDE_FACK || broken(res == (0xdead0000 | DDE_FACK)), /* win9x */
417 "Expected DDE_FACK, got %x\n", res);
418 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
420 DdeFreeDataHandle(hdata);
422 lstrcpyA(buffer, "[Command(Var)]");
423 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
424 0, NULL, CF_TEXT, 0);
425 ok(hdata != NULL, "Expected non-NULL hdata\n");
427 /* XTYP_EXECUTE, correct params */
429 DdeGetLastError(client_pid);
430 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
431 ret = DdeGetLastError(client_pid);
432 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
433 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
434 ok(res == DDE_FACK || broken(res == (0xdead0000 | DDE_FACK)), /* win9x */
435 "Expected DDE_FACK, got %x\n", res);
437 /* XTYP_EXECUTE, no data */
439 DdeGetLastError(client_pid);
440 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
441 ret = DdeGetLastError(client_pid);
442 ok(op == NULL || broken(op == (HDDEDATA)TRUE), /* win9x */ "Expected NULL, got %p\n", op);
445 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
446 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
450 ok(res == (0xdead0000 | DDE_FACK), "Expected DDE_FACK, got %x\n", res);
451 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
454 /* XTYP_EXECUTE, no data, -1 size */
456 DdeGetLastError(client_pid);
457 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
458 ret = DdeGetLastError(client_pid);
459 ok(op == NULL, "Expected NULL, got %p\n", op);
460 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
461 ok(ret == DMLERR_INVALIDPARAMETER || broken(ret == DMLERR_NO_ERROR), /* win9x */
462 "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
464 DdeFreeStringHandle(client_pid, topic);
465 DdeFreeDataHandle(hdata);
467 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
469 /* verify the execute */
471 DdeGetLastError(client_pid);
472 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
473 ret = DdeGetLastError(client_pid);
474 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
475 ok(res == DDE_FNOTPROCESSED || broken(res == (0xdead0000 | DDE_FNOTPROCESSED)), /* win9x */
476 "Expected DDE_FNOTPROCESSED, got %d\n", res);
478 ok(FALSE, "hdata is NULL\n");
481 str = (LPSTR)DdeAccessData(hdata, &size);
482 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
483 ok(size == 19, "Expected 19, got %d\n", size);
485 ret = DdeUnaccessData(hdata);
486 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
489 /* invalid transactions */
491 DdeGetLastError(client_pid);
492 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, 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);
499 DdeGetLastError(client_pid);
500 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, 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);
507 DdeGetLastError(client_pid);
508 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, 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);
515 DdeGetLastError(client_pid);
516 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, 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);
523 DdeGetLastError(client_pid);
524 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, 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);
531 DdeGetLastError(client_pid);
532 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, 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);
539 DdeGetLastError(client_pid);
540 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, 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);
547 DdeGetLastError(client_pid);
548 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, 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);
555 DdeGetLastError(client_pid);
556 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
557 ret = DdeGetLastError(client_pid);
558 ok(op == NULL, "Expected NULL, got %p\n", op);
559 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
560 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
563 DdeGetLastError(client_pid);
564 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
565 ret = DdeGetLastError(client_pid);
566 ok(op == NULL, "Expected NULL, got %p\n", op);
567 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
568 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
570 DdeFreeStringHandle(client_pid, item);
572 ret = DdeDisconnect(conversation);
573 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
575 ret = DdeUninitialize(client_pid);
576 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
579 static DWORD server_pid;
581 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
582 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
583 ULONG_PTR dwData1, ULONG_PTR dwData2)
585 char str[MAX_PATH], *ptr;
589 static int msg_index = 0;
590 static HCONV conversation = 0;
598 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
599 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
600 ok(hconv == 0, "Expected 0, got %p\n", hconv);
601 ok(hdata == 0, "Expected 0, got %p\n", hdata);
602 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
603 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
605 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
606 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
607 ok(size == 13, "Expected 13, got %d\n", size);
609 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
610 if (!strncmp( str, "TestDDEServer:(", 15 )) /* win9x style */
612 ok(size == 16 + 2*sizeof(WORD), "Got size %d for %s\n", size, str);
616 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
617 ok(size == 17 + 2*sizeof(ULONG_PTR), "Got size %d for %s\n", size, str);
619 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
621 return (HDDEDATA)TRUE;
626 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
627 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
628 ok(hconv == 0, "Expected 0, got %p\n", hconv);
629 ok(hdata == 0, "Expected 0, got %p\n", hdata);
630 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
631 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
633 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
634 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
635 ok(size == 12, "Expected 12, got %d\n", size);
637 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
638 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
639 ok(size == 13, "Expected 13, got %d\n", size);
641 return (HDDEDATA)TRUE;
644 case XTYP_CONNECT_CONFIRM:
646 conversation = hconv;
648 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
649 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
650 ok(hconv != NULL, "Expected non-NULL hconv\n");
651 ok(hdata == 0, "Expected 0, got %p\n", hdata);
652 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
653 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
655 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
656 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
657 ok(size == 12, "Expected 12, got %d\n", size);
659 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
660 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
661 ok(size == 13, "Expected 13, got %d\n", size);
663 return (HDDEDATA)TRUE;
668 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
669 "Expected 4, 5 or 6, got %d\n", msg_index);
670 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
671 ok(hdata == 0, "Expected 0, got %p\n", hdata);
672 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
673 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
676 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
678 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
680 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
681 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
682 ok(size == 12, "Expected 12, got %d\n", size);
684 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
689 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
690 ok(size == 1, "Expected 1, got %d\n", size);
693 else if (msg_index == 6)
695 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
696 ok(size == 7, "Expected 7, got %d\n", size);
701 lstrcpyA(str, "requested data\r\n");
702 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
703 0, hsz2, CF_TEXT, 0);
711 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
712 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
713 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
714 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
715 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
717 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
718 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
719 ok(size == 12, "Expected 12, got %d\n", size);
721 ptr = (LPSTR)DdeAccessData(hdata, &size);
722 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
723 ok(size == 12 || broken(size == 28), /* sizes are rounded up on win9x */
724 "Expected 12, got %d\n", size);
725 DdeUnaccessData(hdata);
727 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
731 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
732 ok(size == 1, "Expected 1, got %d\n", size);
737 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
738 ok(size == 4, "Expected 4, got %d\n", size);
741 return (HDDEDATA)DDE_FACK;
746 ok(msg_index >= 9 && msg_index <= 11, "Expected 9 or 11, got %d\n", msg_index);
747 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
748 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
749 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
750 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
751 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
753 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
754 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
755 ok(size == 12, "Expected 12, got %d\n", size);
757 if (msg_index == 9 || msg_index == 11)
759 ptr = (LPSTR)DdeAccessData(hdata, &size);
763 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
764 ok(size == 15, "Expected 15, got %d\n", size);
765 ret = (HDDEDATA)DDE_FACK;
769 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
770 ok(size == 18, "Expected 18, got %d\n", size);
771 ret = DDE_FNOTPROCESSED;
774 DdeUnaccessData(hdata);
776 else if (msg_index == 10)
781 size = DdeGetData(hdata, NULL, 0, 0);
782 ok(size == 17, "DdeGetData should have returned 17 not %d\n", size);
783 ptr = HeapAlloc(GetProcessHeap(), 0, size);
784 ok(ptr != NULL,"HeapAlloc should have returned ptr not NULL\n");
785 rsize = DdeGetData(hdata, (LPBYTE)ptr, size, 0);
786 ok(rsize == size, "DdeGetData did not return %d bytes but %d\n", size, rsize);
788 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr);
789 ok(size == 17, "Expected 17, got %d\n", size);
790 ret = (HDDEDATA)DDE_FACK;
792 HeapFree(GetProcessHeap(), 0, ptr);
798 case XTYP_DISCONNECT:
800 ok(msg_index == 12, "Expected 12, got %d\n", msg_index);
801 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
802 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
803 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
804 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
805 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
806 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
812 ok(FALSE, "Unhandled msg: %08x\n", uType);
818 static void test_ddeml_server(HANDLE hproc)
826 /* set up DDE server */
828 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
829 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
831 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
832 ok(server != NULL, "Expected non-NULL string handle\n");
834 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
835 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
837 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
839 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
841 ret = DdeUninitialize(server_pid);
842 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
843 GetExitCodeProcess( hproc, &res );
844 ok( !res, "client failed with %u error(s)\n", res );
847 static HWND client_hwnd, server_hwnd;
848 static ATOM server, topic, item;
849 static HGLOBAL execute_hglobal;
851 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
860 static int msg_index = 0;
862 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
863 return DefWindowProcA(hwnd, msg, wparam, lparam);
869 case WM_DDE_INITIATE:
871 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
872 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
874 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
875 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
876 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
877 ok(size == 13, "Expected 13, got %d\n", size);
879 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
880 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
881 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
882 ok(size == 12, "Expected 12, got %d\n", size);
889 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 11),
890 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index);
894 server_hwnd = (HWND)wparam;
895 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
897 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
898 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
899 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
900 ok(size == 13, "Expected 13, got %d\n", size);
902 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
903 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
904 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
905 ok(size == 12, "Expected 12, got %d\n", size);
907 else if (msg_index >= 9 && msg_index <= 11)
909 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
911 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
914 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
915 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
916 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
918 ok(hi == (UINT_PTR)execute_hglobal, "Expected execute hglobal, got %08lx\n", hi);
919 ptr = GlobalLock((HGLOBAL)hi);
923 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
924 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
925 } else if (msg_index == 10)
927 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
928 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr);
932 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
933 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
936 GlobalUnlock((HGLOBAL)hi);
940 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
942 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
945 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
946 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
947 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
950 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
953 if (msg_index == 6) todo_wine
954 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
957 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
960 ok(hi == item, "Expected item atom, got %08lx\n", hi);
961 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
962 ok(size == 7, "Expected 7, got %d\n", size);
964 else if (msg_index == 4 || msg_index == 7)
966 ok(hi == 0, "Expected 0, got %08lx\n", hi);
967 ok(size == 0, "Expected empty string, got %d\n", size);
971 ok(hi == item, "Expected item atom, got %08lx\n", hi);
972 if (msg_index == 6) todo_wine
974 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
975 ok(size == 4, "Expected 4, got %d\n", size);
985 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
986 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
988 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
990 data = GlobalLock((HGLOBAL)lo);
991 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
992 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
995 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
997 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
998 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
999 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
1000 "Expected 'requested data\\r\\n', got %s\n", data->Value);
1001 GlobalUnlock((HGLOBAL)lo);
1003 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
1004 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
1005 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
1006 ok(size == 7, "Expected 7, got %d\n", size);
1008 GlobalFree((HGLOBAL)lo);
1009 GlobalDeleteAtom(hi);
1015 ok(FALSE, "Unhandled msg: %08x\n", msg);
1018 return DefWindowProcA(hwnd, msg, wparam, lparam);
1021 static HGLOBAL create_poke(void)
1027 size = FIELD_OFFSET(DDEPOKE, Value[sizeof("poke data\r\n")]);
1028 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
1029 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1031 poke = GlobalLock(hglobal);
1033 poke->fRelease = TRUE;
1034 poke->fReserved = TRUE;
1035 poke->cfFormat = CF_TEXT;
1036 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
1037 GlobalUnlock(hglobal);
1042 static HGLOBAL create_execute(LPCSTR command)
1047 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1048 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1050 ptr = GlobalLock(hglobal);
1051 lstrcpyA(ptr, command);
1052 GlobalUnlock(hglobal);
1057 static void test_msg_client(void)
1062 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1064 server = GlobalAddAtomA("TestDDEServer");
1065 ok(server != 0, "Expected non-NULL server\n");
1067 topic = GlobalAddAtomA("TestDDETopic");
1068 ok(topic != 0, "Expected non-NULL topic\n");
1070 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1072 GlobalDeleteAtom(server);
1073 GlobalDeleteAtom(topic);
1077 item = GlobalAddAtom("request");
1078 ok(item != 0, "Expected non-NULL item\n");
1080 /* WM_DDE_REQUEST, bad clipboard format */
1081 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1082 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1086 /* WM_DDE_REQUEST, no item */
1087 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1088 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1092 /* WM_DDE_REQUEST, no client hwnd */
1093 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1094 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1098 /* WM_DDE_REQUEST, correct params */
1099 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1100 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1104 GlobalDeleteAtom(item);
1105 item = GlobalAddAtomA("poke");
1106 ok(item != 0, "Expected non-NULL item\n");
1108 hglobal = create_poke();
1110 /* WM_DDE_POKE, no ddepoke */
1111 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1112 /* win9x returns 0 here and crashes in PostMessageA */
1114 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1118 win_skip("no lparam for WM_DDE_POKE\n");
1121 /* WM_DDE_POKE, no item */
1122 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1123 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1127 hglobal = create_poke();
1129 /* WM_DDE_POKE, no client hwnd */
1130 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1131 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1135 /* WM_DDE_POKE, all params correct */
1136 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1137 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1141 execute_hglobal = create_execute("[Command(Var)]");
1143 /* WM_DDE_EXECUTE, no lparam */
1144 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1148 /* WM_DDE_EXECUTE, no hglobal */
1149 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1150 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1154 /* WM_DDE_EXECUTE, no client hwnd */
1155 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1156 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1160 /* WM_DDE_EXECUTE, all params correct */
1161 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1162 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1166 GlobalFree(execute_hglobal);
1167 execute_hglobal = create_execute("[Command-2(Var)]");
1169 /* WM_DDE_EXECUTE, all params correct */
1170 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1171 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1175 GlobalFree(execute_hglobal);
1176 execute_hglobal = create_execute("[BadCommand(Var)]");
1178 /* WM_DDE_EXECUTE that will get rejected */
1179 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1180 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1184 destroy_dde_window(&client_hwnd, "dde_client");
1187 static LRESULT WINAPI hook_dde_client_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1191 trace("hook_dde_client_wndprocA: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1196 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1197 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1203 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1206 static LRESULT WINAPI hook_dde_client_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1210 trace("hook_dde_client_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1215 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1216 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1222 return CallWindowProcW(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1225 static LRESULT WINAPI dde_server_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1227 static BOOL client_unicode, conv_unicode;
1232 case WM_DDE_INITIATE:
1234 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1236 trace("server A: got WM_DDE_INITIATE from %p (%s) with %08lx\n",
1237 (HWND)wparam, client_unicode ? "Unicode" : "ANSI", lparam);
1239 if (LOWORD(lparam) == aService)
1241 client_unicode = IsWindowUnicode((HWND)wparam);
1242 conv_unicode = client_unicode;
1243 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1246 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1247 (ULONG_PTR)hook_dde_client_wndprocW);
1249 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1250 (ULONG_PTR)hook_dde_client_wndprocA);
1251 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1252 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1255 GlobalDeleteAtom(aService);
1259 case WM_DDE_EXECUTE:
1266 trace("server A: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1268 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1269 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1271 ack.bAppReturnCode = 0;
1274 /* We have to send a negative acknowledge even if we don't
1275 * accept the command, otherwise Windows goes mad and next time
1276 * we send an acknowledge DDEML drops the connection.
1277 * Not sure how to call it: a bug or a feature.
1281 if ((cmd = GlobalLock((HGLOBAL)hi)))
1283 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1287 case 0: /* bad command */
1288 trace( "server A got unhandled command\n" );
1291 case 1: /* ANSI command */
1293 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1294 else /* we get garbage as the A command was mapped W->A */
1295 ok( cmd[0] != exec_cmdA[0], "server A got wrong command '%s'\n", cmd );
1298 case 2: /* ANSI command in Unicode format */
1300 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1302 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server A got wrong command '%s'\n", cmd );
1305 case 3: /* Unicode command */
1307 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server A got wrong command '%s'\n", cmd );
1308 else /* correctly mapped W->A */
1309 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1312 case 4: /* Unicode command in ANSI format */
1314 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1315 else /* we get garbage as the A command was mapped W->A */
1316 ok( cmd[0] != exec_cmdWA[0], "server A got wrong command '%s'\n", cmd );
1319 GlobalUnlock((HGLOBAL)hi);
1321 else ok( 0, "bad command data %lx\n", hi );
1324 trace("server A: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1326 status = *((WORD *)&ack);
1327 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1329 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1333 case WM_DDE_TERMINATE:
1338 trace("server A: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1340 ack.bAppReturnCode = 0;
1345 trace("server A: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1347 status = *((WORD *)&ack);
1348 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1350 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1358 return DefWindowProcA(hwnd, msg, wparam, lparam);
1361 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1363 static BOOL client_unicode, conv_unicode;
1368 case WM_DDE_INITIATE:
1370 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1372 if (LOWORD(lparam) == aService)
1374 client_unicode = IsWindowUnicode((HWND)wparam);
1375 conv_unicode = client_unicode;
1376 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1379 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1380 (ULONG_PTR)hook_dde_client_wndprocW);
1382 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1383 (ULONG_PTR)hook_dde_client_wndprocA);
1384 trace("server W: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1385 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1388 GlobalDeleteAtom(aService);
1390 trace("server W: got WM_DDE_INITIATE from %p with %08lx (client %s conv %s)\n", (HWND)wparam,
1391 lparam, client_unicode ? "Unicode" : "ANSI", conv_unicode ? "Unicode" : "ANSI" );
1396 case WM_DDE_EXECUTE:
1403 trace("server W: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1405 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1406 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1408 ack.bAppReturnCode = 0;
1411 /* We have to send a negative acknowledge even if we don't
1412 * accept the command, otherwise Windows goes mad and next time
1413 * we send an acknowledge DDEML drops the connection.
1414 * Not sure how to call it: a bug or a feature.
1418 if ((cmd = GlobalLock((HGLOBAL)hi)))
1420 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1424 case 0: /* bad command */
1425 trace( "server W got unhandled command\n" );
1428 case 1: /* ANSI command */
1429 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1430 ok( cmd[0] != exec_cmdA[0], "server W got wrong command '%s'\n", cmd );
1431 else if (!conv_unicode && client_unicode) /* A->W mapping */
1432 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1434 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1437 case 2: /* ANSI command in Unicode format */
1438 if (conv_unicode && !client_unicode) /* W->A mapping */
1439 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1440 else if (!conv_unicode && client_unicode) /* A->W mapping */
1441 ok( *(WCHAR *)cmd == exec_cmdAW[0], "server W got wrong command '%s'\n", cmd );
1443 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1446 case 3: /* Unicode command */
1447 if (conv_unicode && !client_unicode) /* W->A mapping */
1448 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1449 else if (!conv_unicode && client_unicode) /* A->W mapping */
1450 ok( *(WCHAR *)cmd == exec_cmdW[0], "server W got wrong command '%s'\n", cmd );
1452 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1455 case 4: /* Unicode command in ANSI format */
1456 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1457 ok( cmd[0] != exec_cmdWA[0], "server W got wrong command '%s'\n", cmd );
1458 else if (!conv_unicode && client_unicode) /* A->W mapping */
1459 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1461 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1464 GlobalUnlock((HGLOBAL)hi);
1466 else ok( 0, "bad command data %lx\n", hi );
1469 trace("server W: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1471 status = *((WORD *)&ack);
1472 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1474 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1478 case WM_DDE_TERMINATE:
1483 trace("server W: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1485 ack.bAppReturnCode = 0;
1490 trace("server W: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1492 status = *((WORD *)&ack);
1493 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1495 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1503 return DefWindowProcW(hwnd, msg, wparam, lparam);
1506 static HWND create_dde_server( BOOL unicode )
1511 static const char server_class_nameA[] = "dde_server_windowA";
1512 static const WCHAR server_class_nameW[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w','W',0};
1516 memset(&wcW, 0, sizeof(wcW));
1517 wcW.lpfnWndProc = dde_server_wndprocW;
1518 wcW.lpszClassName = server_class_nameW;
1519 wcW.hInstance = GetModuleHandleA(0);
1520 RegisterClassW(&wcW);
1522 server = CreateWindowExW(0, server_class_nameW, NULL, WS_POPUP,
1523 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1524 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1528 memset(&wcA, 0, sizeof(wcA));
1529 wcA.lpfnWndProc = dde_server_wndprocA;
1530 wcA.lpszClassName = server_class_nameA;
1531 wcA.hInstance = GetModuleHandleA(0);
1532 RegisterClassA(&wcA);
1534 server = CreateWindowExA(0, server_class_nameA, NULL, WS_POPUP,
1535 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1536 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1538 ok(!IsWindowUnicode(server) == !unicode, "wrong unicode type\n");
1542 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1543 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1544 ULONG_PTR dwData1, ULONG_PTR dwData2)
1546 static const char * const cmd_type[15] = {
1547 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1548 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1549 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1550 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1552 const char *cmd_name;
1554 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1555 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1557 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1558 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1562 static void test_dde_aw_transaction( BOOL client_unicode, BOOL server_unicode )
1565 DWORD dde_inst, ret, err;
1570 BOOL conv_unicode = client_unicode;
1572 static char test_cmd[] = "test dde command";
1574 if (!(hwnd_server = create_dde_server( server_unicode ))) return;
1578 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1580 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1581 ok(ret == DMLERR_NO_ERROR, "DdeInitializeA failed with error %04x (%x)\n",
1582 ret, DdeGetLastError(dde_inst));
1584 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1586 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1587 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1588 err = DdeGetLastError(dde_inst);
1589 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1591 info.cb = sizeof(info);
1592 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1593 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1594 ok(info.ConvCtxt.iCodePage == client_unicode ? CP_WINUNICODE : CP_WINANSI,
1595 "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1596 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1598 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1600 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1601 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1602 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1604 client_unicode = IsWindowUnicode( info.hwnd );
1605 trace("hwnd %p, hwndPartner %p, unicode %u\n", info.hwnd, info.hwndPartner, client_unicode);
1607 trace("sending test client transaction command\n");
1609 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1610 ok(!hdata, "DdeClientTransaction succeeded\n");
1611 ok(ret == DDE_FNOTPROCESSED || broken(ret == (0xdead0000 | DDE_FNOTPROCESSED)), /* win9x */
1612 "wrong status code %04x\n", ret);
1613 err = DdeGetLastError(dde_inst);
1614 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1616 trace("sending ANSI client transaction command\n");
1618 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1619 err = DdeGetLastError(dde_inst);
1620 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1622 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1623 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1624 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1626 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> wrong cmd */
1628 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1629 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1630 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1632 else /* no mapping */
1634 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1635 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1636 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1639 trace("sending ANSI-as-Unicode client transaction command\n");
1641 hdata = DdeClientTransaction((LPBYTE)exec_cmdAW, (lstrlenW(exec_cmdAW) + 1) * sizeof(WCHAR),
1642 hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1643 err = DdeGetLastError(dde_inst);
1644 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping */
1646 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1647 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1648 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1650 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1652 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1653 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1654 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1656 else /* no mapping */
1658 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1659 ok(ret == DDE_FNOTPROCESSED || broken(ret == (0xdead0000 | DDE_FNOTPROCESSED)), /* win9x */
1660 "wrong status code %04x\n", ret);
1661 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1664 trace("sending unicode client transaction command\n");
1666 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1667 err = DdeGetLastError(dde_inst);
1668 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> wrong cmd */
1670 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1671 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1672 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1674 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1676 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1677 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1678 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1680 else /* no mapping */
1682 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1683 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1684 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1687 trace("sending Unicode-as-ANSI client transaction command\n");
1689 hdata = DdeClientTransaction((LPBYTE)exec_cmdWA, lstrlenA(exec_cmdWA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1690 err = DdeGetLastError(dde_inst);
1691 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1693 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1694 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1695 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1697 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping */
1699 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1700 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1701 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1703 else /* no mapping */
1705 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1706 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1707 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1710 got = DdeDisconnect(hconv);
1711 ok(got, "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1713 info.cb = sizeof(info);
1714 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1715 ok(!ret, "DdeQueryConvInfo should fail\n");
1716 err = DdeGetLastError(dde_inst);
1718 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1721 got = DdeFreeStringHandle(dde_inst, hsz_server);
1722 ok(got, "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1724 /* This call hangs on win2k SP4 and XP SP1.
1725 DdeUninitialize(dde_inst);*/
1727 DestroyWindow(hwnd_server);
1730 static void test_initialisation(void)
1735 HSZ server, topic, item;
1739 /* Initialise without a valid server window. */
1741 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1742 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
1745 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
1746 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
1748 DdeGetLastError(client_pid);
1750 /* There is no server window so no conversation can be extracted */
1751 conversation = DdeConnect(client_pid, server, topic, NULL);
1752 ok(conversation == NULL, "Expected NULL conversation, %p\n", conversation);
1753 ret = DdeGetLastError(client_pid);
1754 ok(ret == DMLERR_NO_CONV_ESTABLISHED, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret);
1756 DdeFreeStringHandle(client_pid, server);
1758 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
1760 /* There is no conversation so an invalid parameter results */
1762 DdeGetLastError(client_pid);
1763 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
1764 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1765 ret = DdeGetLastError(client_pid);
1767 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
1768 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
1770 DdeFreeStringHandle(client_pid, server);
1771 ret = DdeDisconnect(conversation);
1772 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1774 ret = DdeUninitialize(client_pid);
1775 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1778 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1780 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1787 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1788 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1789 DdeGetLastError(dde_inst));
1791 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1792 if (codepage == CP_WINANSI)
1793 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1795 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1797 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1798 if (codepage == CP_WINANSI)
1800 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1801 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1805 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1806 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1809 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1810 if (codepage == CP_WINANSI)
1812 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1813 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1817 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1818 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1821 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1822 if (codepage == CP_WINANSI)
1824 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1825 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1829 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1830 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1833 if (codepage == CP_WINANSI)
1835 atom = FindAtomA((LPSTR)dde_string);
1836 ok(atom != 0, "Expected a valid atom\n");
1838 SetLastError(0xdeadbeef);
1839 atom = GlobalFindAtomA((LPSTR)dde_string);
1840 ok(atom == 0, "Expected 0, got %d\n", atom);
1841 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1842 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1846 atom = FindAtomW(dde_string);
1847 ok(atom != 0, "Expected a valid atom\n");
1849 SetLastError(0xdeadbeef);
1850 atom = GlobalFindAtomW(dde_string);
1851 ok(atom == 0, "Expected 0, got %d\n", atom);
1852 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1853 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1856 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1859 static void test_DdeCreateDataHandle(void)
1862 DWORD dde_inst, dde_inst2;
1868 WCHAR item_str[] = {'i','t','e','m',0};
1872 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1873 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1875 res = DdeInitializeA(&dde_inst2, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1876 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1879 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1880 * is invalid then the lastError of all instances is set to the error. There are two instances
1881 * created, lastError is cleared, an error is generated and then both instances are checked to
1882 * ensure that they both have the same error set
1884 item = DdeCreateStringHandleA(0, "item", CP_WINANSI);
1885 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1886 err = DdeGetLastError(dde_inst);
1887 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1888 err = DdeGetLastError(dde_inst2);
1889 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1890 item = DdeCreateStringHandleW(0, item_str, CP_WINUNICODE);
1891 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1892 err = DdeGetLastError(dde_inst);
1893 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1894 err = DdeGetLastError(dde_inst2);
1895 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1897 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1898 ok(item != NULL, "Expected non-NULL hsz\n");
1899 item = DdeCreateStringHandleA(dde_inst2, "item", CP_WINANSI);
1900 ok(item != NULL, "Expected non-NULL hsz\n");
1903 /* do not test with an invalid instance id: that crashes on win9x */
1904 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1908 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1909 * is invalid then the lastError of all instances is set to the error. There are two instances
1910 * created, lastError is cleared, an error is generated and then both instances are checked to
1911 * ensure that they both have the same error set
1913 DdeGetLastError(dde_inst);
1914 DdeGetLastError(dde_inst2);
1915 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1916 err = DdeGetLastError(dde_inst);
1917 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1918 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1919 err = DdeGetLastError(dde_inst2);
1920 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1922 ret = DdeUninitialize(dde_inst2);
1923 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1927 DdeGetLastError(dde_inst);
1928 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1929 err = DdeGetLastError(dde_inst);
1930 ok(hdata != NULL, "Expected non-NULL hdata\n");
1931 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1933 ptr = DdeAccessData(hdata, &size);
1934 ok(ptr != NULL, "Expected non-NULL ptr\n");
1935 ok(size == 260, "Expected 260, got %d\n", size);
1937 ret = DdeUnaccessData(hdata);
1938 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1940 ret = DdeFreeDataHandle(hdata);
1941 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1944 DdeGetLastError(dde_inst);
1945 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1946 err = DdeGetLastError(dde_inst);
1947 ok(hdata != NULL, "Expected non-NULL hdata\n");
1948 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1950 ptr = DdeAccessData(hdata, &size);
1951 ok(ptr != NULL, "Expected non-NULL ptr\n");
1952 ok(size == 0, "Expected 0, got %d\n", size);
1954 ret = DdeUnaccessData(hdata);
1955 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1957 ret = DdeFreeDataHandle(hdata);
1958 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1960 /* cbOff is non-zero */
1961 DdeGetLastError(dde_inst);
1962 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1963 err = DdeGetLastError(dde_inst);
1964 ok(hdata != NULL, "Expected non-NULL hdata\n");
1965 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1967 ptr = DdeAccessData(hdata, &size);
1968 ok(ptr != NULL, "Expected non-NULL ptr\n");
1969 ok(size == 262, "Expected 262, got %d\n", size);
1972 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1975 ret = DdeUnaccessData(hdata);
1976 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1978 ret = DdeFreeDataHandle(hdata);
1979 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1982 DdeGetLastError(dde_inst);
1983 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1984 err = DdeGetLastError(dde_inst);
1985 ok(hdata != NULL, "Expected non-NULL hdata\n");
1986 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1988 ptr = DdeAccessData(hdata, &size);
1989 ok(ptr != NULL, "Expected non-NULL ptr\n");
1990 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1991 ok(size == 260, "Expected 260, got %d\n", size);
1993 ret = DdeUnaccessData(hdata);
1994 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1996 ret = DdeFreeDataHandle(hdata);
1997 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2000 DdeGetLastError(dde_inst);
2001 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
2002 err = DdeGetLastError(dde_inst);
2003 ok(hdata != NULL, "Expected non-NULL hdata\n");
2004 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
2006 ptr = DdeAccessData(hdata, &size);
2007 ok(ptr != NULL, "Expected non-NULL ptr\n");
2008 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
2009 ok(size == 260, "Expected 260, got %d\n", size);
2011 ret = DdeUnaccessData(hdata);
2012 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2014 ret = DdeFreeDataHandle(hdata);
2015 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2017 /* invalid clipboard format */
2018 DdeGetLastError(dde_inst);
2019 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
2020 err = DdeGetLastError(dde_inst);
2021 ok(hdata != NULL, "Expected non-NULL hdata\n");
2022 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
2024 ptr = DdeAccessData(hdata, &size);
2025 ok(ptr != NULL, "Expected non-NULL ptr\n");
2026 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
2027 ok(size == 260, "Expected 260, got %d\n", size);
2029 ret = DdeUnaccessData(hdata);
2030 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2032 ret = DdeFreeDataHandle(hdata);
2033 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2035 ret = DdeUninitialize(dde_inst);
2036 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2039 static void test_DdeCreateStringHandle(void)
2041 DWORD dde_inst, ret;
2043 dde_inst = 0xdeadbeef;
2044 SetLastError(0xdeadbeef);
2045 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2046 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
2047 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
2050 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2051 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
2052 ret, DdeGetLastError(dde_inst));
2054 test_DdeCreateStringHandleW(dde_inst, 0);
2055 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
2056 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
2058 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
2061 static void test_FreeDDElParam(void)
2063 HGLOBAL val, hglobal;
2066 ret = FreeDDElParam(WM_DDE_INITIATE, 0);
2067 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2069 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2070 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
2071 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2072 val = GlobalFree(hglobal);
2073 ok(val == NULL, "Expected NULL, got %p\n", val);
2075 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2076 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
2077 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2079 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2080 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
2081 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2082 val = GlobalFree(hglobal);
2083 ok(val == NULL, "Expected NULL, got %p\n", val);
2085 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2086 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
2087 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2089 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2090 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
2091 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2093 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2094 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
2095 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2096 val = GlobalFree(hglobal);
2097 ok(val == NULL, "Expected NULL, got %p\n", val);
2099 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2100 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
2101 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2103 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2104 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
2105 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2106 val = GlobalFree(hglobal);
2107 ok(val == NULL, "Expected NULL, got %p\n", val);
2110 static void test_PackDDElParam(void)
2112 UINT_PTR lo, hi, *ptr;
2116 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
2117 /* value gets sign-extended despite being an LPARAM */
2118 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2121 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
2122 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2123 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2124 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2126 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
2127 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2129 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
2130 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2133 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
2134 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2135 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2136 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2138 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
2139 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2141 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
2142 /* win9x returns 0 here */
2144 ptr = GlobalLock((HGLOBAL)lparam);
2145 ok(ptr != NULL, "Expected non-NULL ptr\n");
2146 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2147 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2149 ret = GlobalUnlock((HGLOBAL)lparam);
2150 ok(ret == 1, "Expected 1, got %d\n", ret);
2153 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
2154 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2155 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2156 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2159 win_skip("no lparam for WM_DDE_ADVISE\n");
2161 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
2162 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2164 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
2165 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2168 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
2169 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2170 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2171 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2173 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
2174 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2176 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
2177 /* win9x returns the input (0xbeef<<16 | 0xcafe) here */
2178 if (lparam != (int)0xbeefcafe) {
2179 ptr = GlobalLock((HGLOBAL)lparam);
2180 ok(ptr != NULL, "Expected non-NULL ptr\n");
2181 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2182 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2184 ret = GlobalUnlock((HGLOBAL)lparam);
2185 ok(ret == 1, "Expected 1, got %d\n", ret);
2188 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
2189 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2190 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2191 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2193 ret = FreeDDElParam(WM_DDE_ACK, lparam);
2194 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2197 win_skip("got lparam 0x%lx for WM_DDE_ACK\n", lparam);
2199 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
2200 /* win9x returns 0 here */
2202 ptr = GlobalLock((HGLOBAL)lparam);
2203 ok(ptr != NULL, "Expected non-NULL ptr\n");
2204 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2205 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2207 ret = GlobalUnlock((HGLOBAL)lparam);
2208 ok(ret == 1, "Expected 1, got %d\n", ret);
2211 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
2212 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2213 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2214 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2217 win_skip("no lparam for WM_DDE_DATA\n");
2219 ret = FreeDDElParam(WM_DDE_DATA, lparam);
2220 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2222 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
2223 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2226 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
2227 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2228 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2229 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2231 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
2232 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2234 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
2235 /* win9x returns 0 here */
2237 ptr = GlobalLock((HGLOBAL)lparam);
2238 ok(ptr != NULL, "Expected non-NULL ptr\n");
2239 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2240 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2242 ret = GlobalUnlock((HGLOBAL)lparam);
2243 ok(ret == 1, "Expected 1, got %d\n", ret);
2246 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
2247 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2248 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2249 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2252 win_skip("no lparam for WM_DDE_POKE\n");
2254 ret = FreeDDElParam(WM_DDE_POKE, lparam);
2255 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2257 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
2258 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
2261 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
2262 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2263 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2264 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2266 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
2267 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2270 static void test_UnpackDDElParam(void)
2272 UINT_PTR lo, hi, *ptr;
2279 ret = UnpackDDElParam(WM_DDE_INITIATE, 0, &lo, &hi);
2280 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2281 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2282 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2287 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
2288 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2289 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
2290 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2295 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
2296 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2297 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2298 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2302 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
2303 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2304 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2305 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2309 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
2310 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2311 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2312 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2316 ret = UnpackDDElParam(WM_DDE_ADVISE, 0, &lo, &hi);
2317 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2319 broken(lo == 0xdead), /* win2k */
2320 "Expected 0, got %08lx\n", lo);
2322 broken(hi == 0xbeef), /* win2k */
2323 "Expected 0, got %08lx\n", hi);
2325 hglobal = GlobalAlloc(GMEM_DDESHARE, 2 * sizeof(*ptr));
2326 ptr = GlobalLock(hglobal);
2327 ptr[0] = 0xcafebabe;
2328 ptr[1] = 0xdeadbeef;
2329 GlobalUnlock(hglobal);
2333 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2334 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2335 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2336 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2340 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2341 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2342 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2343 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2347 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2348 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2349 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2350 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2354 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2355 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2356 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2357 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2361 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2362 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2363 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2364 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2368 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2369 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2370 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2371 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2375 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2376 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2377 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2378 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2380 GlobalFree(hglobal);
2383 static char test_cmd_a_to_a[] = "Test dde command";
2384 static WCHAR test_cmd_w_to_w[][32] = {
2385 {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0},
2386 { 0x2018, 0x2019, 0x0161, 0x0041, 0x02dc, 0 }, /* some chars that should map properly to CP1252 */
2387 { 0x2026, 0x2020, 0x2021, 0x0d0a, 0 }, /* false negative for IsTextUnicode */
2388 { 0x4efa, 0x4efc, 0x0061, 0x4efe, 0 }, /* some Chinese chars */
2390 static const int nb_callbacks = 5 + sizeof(test_cmd_w_to_w)/sizeof(test_cmd_w_to_w[0]);
2392 static HDDEDATA CALLBACK server_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2393 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2394 ULONG_PTR dwData1, ULONG_PTR dwData2)
2398 static int msg_index = 0;
2399 static HCONV conversation = 0;
2400 static char test_service [] = "TestDDEService";
2401 static char test_topic [] = "TestDDETopic";
2409 ok(msg_index % nb_callbacks == 1, "Expected 1 modulo %u, got %d\n", nb_callbacks, msg_index);
2410 return (HDDEDATA)TRUE;
2415 ok(msg_index % nb_callbacks == 2, "Expected 2 modulo %u, got %d\n", nb_callbacks, msg_index);
2416 ok(uFmt == 0, "Expected 0, got %d, msg_index=%d\n", uFmt, msg_index);
2417 ok(hconv == 0, "Expected 0, got %p, msg_index=%d\n", hconv, msg_index);
2418 ok(hdata == 0, "Expected 0, got %p, msg_index=%d\n", hdata, msg_index);
2419 ok(dwData1 != 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2420 ok(dwData2 == FALSE, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2, msg_index);
2422 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2423 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2424 test_topic, str, msg_index);
2425 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2427 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
2428 ok(!lstrcmpA(str, test_service), "Expected %s, got %s, msg_index=%d\n",
2429 test_service, str, msg_index);
2430 ok(size == 14, "Expected 14, got %d, msg_index=%d\n", size, msg_index);
2432 return (HDDEDATA) TRUE;
2434 case XTYP_CONNECT_CONFIRM:
2436 ok(msg_index % nb_callbacks == 3, "Expected 3 modulo %u, got %d\n", nb_callbacks, msg_index);
2437 conversation = hconv;
2438 return (HDDEDATA) TRUE;
2442 BYTE *buffer = NULL;
2444 char test_cmd_w_to_a[64];
2445 WCHAR test_cmd_a_to_w[64];
2446 DWORD size_a, size_w, size_w_to_a, size_a_to_w;
2447 BOOL unicode_server, unicode_client, str_index;
2449 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
2450 ok(hconv == conversation, "Expected conversation handle, got %p, msg_index=%d\n",
2452 ok(dwData1 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2453 ok(dwData2 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2, msg_index);
2454 ok(hsz2 == 0, "Expected 0, got %p, msg_index=%d\n", hsz2, msg_index);
2455 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2456 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2457 test_topic, str, msg_index);
2458 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2460 size = DdeGetData(hdata, NULL, 0, 0);
2461 ok((buffer = HeapAlloc(GetProcessHeap(), 0, size)) != NULL, "should not be null\n");
2462 rsize = DdeGetData(hdata, buffer, size, 0);
2463 ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2464 size, rsize, msg_index);
2465 trace("msg %u strA \"%s\" strW %s\n", msg_index, buffer, wine_dbgstr_w((WCHAR*)buffer));
2467 unicode_server = (msg_index / nb_callbacks == 1 || msg_index / nb_callbacks == 2);
2468 unicode_client = (msg_index / nb_callbacks == 1 || msg_index / nb_callbacks == 3);
2469 str_index = msg_index % nb_callbacks - 4;
2470 cmd_w = test_cmd_w_to_w[str_index - 1];
2471 size_a = strlen(test_cmd_a_to_a) + 1;
2472 size_w = (lstrlenW(cmd_w) + 1) * sizeof(WCHAR);
2473 size_a_to_w = MultiByteToWideChar( CP_ACP, 0, test_cmd_a_to_a, -1, test_cmd_a_to_w,
2474 sizeof(test_cmd_a_to_w)/sizeof(WCHAR) ) * sizeof(WCHAR);
2475 size_w_to_a = WideCharToMultiByte( CP_ACP, 0, cmd_w, -1,
2476 test_cmd_w_to_a, sizeof(test_cmd_w_to_a), NULL, NULL );
2479 case 0: /* ASCII string */
2482 ok(size == size_a_to_w, "Wrong size %d/%d, msg_index=%d\n", size, size_a_to_w, msg_index);
2483 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2484 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2486 else if (unicode_client)
2488 /* ASCII string mapped W->A -> garbage */
2492 ok(size == size_a, "Wrong size %d/%d, msg_index=%d\n", size, size_a, msg_index);
2493 ok(!lstrcmpA((CHAR*)buffer, test_cmd_a_to_a), "Expected %s, got %s, msg_index=%d\n",
2494 test_cmd_a_to_a, buffer, msg_index);
2498 case 1: /* Unicode string with only 8-bit chars */
2501 ok(size == size_w, "Wrong size %d/%d, msg_index=%d\n", size, size_w, msg_index);
2502 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2503 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2505 else if (unicode_client)
2507 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n", size, size_w_to_a, msg_index);
2508 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2509 test_cmd_w_to_a, buffer, msg_index);
2513 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n",
2514 size, size_w_to_a, msg_index);
2515 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2516 test_cmd_w_to_a, buffer, msg_index);
2520 case 2: /* normal Unicode string */
2521 case 3: /* IsTextUnicode false negative */
2522 case 4: /* Chinese chars */
2525 /* double A->W mapping */
2526 /* NT uses the full size, XP+ only until the first null */
2527 DWORD nt_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, size_w, test_cmd_a_to_w,
2528 sizeof(test_cmd_a_to_w)/sizeof(WCHAR) ) * sizeof(WCHAR);
2529 DWORD xp_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, -1, NULL, 0 ) * sizeof(WCHAR);
2530 ok(size == xp_size || broken(size == nt_size) ||
2531 broken(str_index == 4 && IsDBCSLeadByte(cmd_w[0])) /* East Asian */,
2532 "Wrong size %d/%d, msg_index=%d\n", size, size_a_to_w, msg_index);
2533 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2534 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2536 else if (unicode_client)
2538 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n", size, size_w_to_a, msg_index);
2539 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2540 test_cmd_w_to_a, buffer, msg_index);
2544 ok(size == size_w, "Wrong size %d/%d, msg_index=%d\n", size, size_w, msg_index);
2545 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2546 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2551 ok( 0, "Invalid message %u\n", msg_index );
2554 return (HDDEDATA) DDE_FACK;
2556 case XTYP_DISCONNECT:
2557 return (HDDEDATA) TRUE;
2560 ok(FALSE, "Unhandled msg: %08x, msg_index=%d\n", uType, msg_index);
2566 static HDDEDATA CALLBACK client_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2567 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2568 ULONG_PTR dwData1, ULONG_PTR dwData2)
2572 case XTYP_DISCONNECT:
2573 return (HDDEDATA) TRUE;
2576 ok(FALSE, "Unhandled msg: %08x\n", uType);
2582 static void test_end_to_end_client(BOOL type_a)
2585 DWORD client_pid = 0;
2589 static char test_service[] = "TestDDEService";
2590 static WCHAR test_service_w[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2591 static char test_topic[] = "TestDDETopic";
2592 static WCHAR test_topic_w[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2594 trace("Start end to end client %s\n", type_a ? "ASCII" : "UNICODE");
2597 ret = DdeInitializeA(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2599 ret = DdeInitializeW(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2600 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2604 server = DdeCreateStringHandleA(client_pid, test_service, CP_WINANSI);
2605 topic = DdeCreateStringHandleA(client_pid, test_topic, CP_WINANSI);
2608 server = DdeCreateStringHandleW(client_pid, test_service_w, CP_WINUNICODE);
2609 topic = DdeCreateStringHandleW(client_pid, test_topic_w, CP_WINUNICODE);
2612 DdeGetLastError(client_pid);
2613 hconv = DdeConnect(client_pid, server, topic, NULL);
2614 ok(hconv != NULL, "Expected non-NULL conversation\n");
2615 ret = DdeGetLastError(client_pid);
2616 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2617 DdeFreeStringHandle(client_pid, server);
2619 /* Test both A and W data being passed to DdeClientTransaction */
2620 hdata = DdeClientTransaction((LPBYTE)test_cmd_a_to_a, sizeof(test_cmd_a_to_a),
2621 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2622 ok(hdata != NULL, "DdeClientTransaction failed\n");
2623 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2624 err = DdeGetLastError(client_pid);
2625 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2627 for (i = 0; i < sizeof(test_cmd_w_to_w)/sizeof(test_cmd_w_to_w[0]); i++)
2629 hdata = DdeClientTransaction((LPBYTE)test_cmd_w_to_w[i],
2630 (lstrlenW(test_cmd_w_to_w[i]) + 1) * sizeof(WCHAR),
2631 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2632 ok(hdata != NULL, "DdeClientTransaction failed\n");
2633 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2634 err = DdeGetLastError(client_pid);
2635 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2638 DdeFreeStringHandle(client_pid, topic);
2639 ret = DdeDisconnect(hconv);
2640 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2642 ret = DdeUninitialize(client_pid);
2643 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2647 static void test_end_to_end_server(HANDLE hproc, HANDLE hthread, BOOL type_a)
2654 static CHAR test_service[] = "TestDDEService";
2656 trace("start end to end server %s\n", type_a ? "ASCII" : "UNICODE");
2660 res = DdeInitializeA(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2662 res = DdeInitializeW(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2663 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
2665 server = DdeCreateStringHandleA(server_pid, test_service, CP_WINANSI);
2666 ok(server != NULL, "Expected non-NULL string handle\n");
2668 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
2669 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
2670 ResumeThread( hthread );
2673 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
2675 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2678 ret = DdeUninitialize(server_pid);
2679 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2680 GetExitCodeProcess( hproc, &res );
2681 ok( !res, "client failed with %u error(s)\n", res );
2688 char buffer[MAX_PATH];
2689 STARTUPINFO startup;
2690 PROCESS_INFORMATION proc;
2691 DWORD dde_inst = 0xdeadbeef;
2693 argc = winetest_get_mainargs(&argv);
2696 if (!lstrcmpA(argv[2], "ddeml"))
2697 test_ddeml_client();
2698 else if (!lstrcmpA(argv[2], "msg"))
2700 else if (!lstrcmpA(argv[2], "enda"))
2701 test_end_to_end_client(TRUE);
2702 else if (!lstrcmpA(argv[2], "endw"))
2703 test_end_to_end_client(FALSE);
2708 test_initialisation();
2710 SetLastError(0xdeadbeef);
2711 DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2712 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2714 win_skip("Skipping tests on win9x because of brokenness\n");
2718 ZeroMemory(&startup, sizeof(STARTUPINFO));
2719 sprintf(buffer, "%s dde ddeml", argv[0]);
2720 startup.cb = sizeof(startup);
2721 startup.dwFlags = STARTF_USESHOWWINDOW;
2722 startup.wShowWindow = SW_SHOWNORMAL;
2724 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2725 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2727 test_msg_server(proc.hProcess, proc.hThread);
2729 sprintf(buffer, "%s dde msg", argv[0]);
2730 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2731 0, NULL, NULL, &startup, &proc);
2733 test_ddeml_server(proc.hProcess);
2735 /* Test the combinations of A and W interfaces with A and W data
2736 end to end to ensure that data conversions are accurate */
2737 sprintf(buffer, "%s dde enda", argv[0]);
2738 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2739 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2741 test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
2743 /* Don't bother testing W interfaces on Win9x/WinMe */
2744 SetLastError(0xdeadbeef);
2745 lstrcmpW(NULL, NULL);
2746 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2748 win_skip("Skipping W-interface tests\n");
2752 sprintf(buffer, "%s dde endw", argv[0]);
2753 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2754 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2756 test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
2758 sprintf(buffer, "%s dde enda", argv[0]);
2759 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2760 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2762 test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
2764 sprintf(buffer, "%s dde endw", argv[0]);
2765 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2766 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2768 test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
2770 test_dde_aw_transaction( FALSE, TRUE );
2771 test_dde_aw_transaction( TRUE, FALSE );
2772 test_dde_aw_transaction( TRUE, TRUE );
2773 test_dde_aw_transaction( FALSE, FALSE );
2775 test_dde_aw_transaction( FALSE, TRUE );
2776 test_dde_aw_transaction( TRUE, FALSE );
2777 test_dde_aw_transaction( TRUE, TRUE );
2779 test_dde_aw_transaction( FALSE, FALSE );
2781 test_DdeCreateDataHandle();
2782 test_DdeCreateStringHandle();
2783 test_FreeDDElParam();
2784 test_PackDDElParam();
2785 test_UnpackDDElParam();