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
34 #include "wine/test.h"
36 static const WCHAR TEST_DDE_SERVICE[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
38 static char exec_cmdA[] = "ANSI dde command";
39 static WCHAR exec_cmdAW[] = {'A','N','S','I',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
40 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
41 static char exec_cmdWA[] = "unicode dde command";
43 static WNDPROC old_dde_client_wndproc;
45 static const DWORD default_timeout = 200;
47 static void flush_events(void)
50 int diff = default_timeout;
52 DWORD time = GetTickCount() + diff;
56 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
57 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
58 diff = time - GetTickCount();
63 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 assert(RegisterClassA(&wcA));
73 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
74 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
75 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
79 static void destroy_dde_window(HWND *hwnd, LPCSTR name)
82 UnregisterClass(name, GetModuleHandleA(0));
85 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
88 char str[MAX_PATH], *ptr;
94 static int msg_index = 0;
95 static HWND client = 0;
96 static BOOL executed = FALSE;
98 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
99 return DefWindowProcA(hwnd, msg, wparam, lparam);
105 case WM_DDE_INITIATE:
107 client = (HWND)wparam;
108 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
110 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
111 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
113 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
114 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
116 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
123 ok((msg_index >= 2 && msg_index <= 4) ||
124 (msg_index >= 7 && msg_index <= 8),
125 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
126 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
127 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
129 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
131 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
133 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
138 lstrcpyA(str, "command executed\r\n");
140 lstrcpyA(str, "command not executed\r\n");
143 lstrcpyA(str, "requested data\r\n");
145 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
146 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
147 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
149 data = GlobalLock(hglobal);
150 ZeroMemory(data, size);
152 /* setting fResponse to FALSE at this point destroys
153 * the internal messaging state of native dde
155 data->fResponse = TRUE;
158 data->fRelease = TRUE;
159 else if (msg_index == 3)
160 data->fAckReq = TRUE;
162 data->cfFormat = CF_TEXT;
163 lstrcpyA((LPSTR)data->Value, str);
164 GlobalUnlock(hglobal);
166 lparam = PackDDElParam(WM_DDE_DATA, (UINT_PTR)hglobal, HIWORD(lparam));
167 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
174 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
175 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
177 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
179 GlobalGetAtomNameA(hi, str, MAX_PATH);
180 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
182 poke = GlobalLock((HGLOBAL)lo);
183 ok(poke != NULL, "Expected non-NULL poke\n");
184 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
185 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
186 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
187 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
191 size = GlobalSize((HGLOBAL)lo);
192 ok(size == 4 || broken(size == 32), /* sizes are rounded up on win9x */ "got %d\n", size);
195 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
196 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
198 GlobalUnlock((HGLOBAL)lo);
200 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
201 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
208 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
209 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
211 ptr = GlobalLock((HGLOBAL)lparam);
212 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
213 GlobalUnlock((HGLOBAL)lparam);
217 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, lparam);
218 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
223 case WM_DDE_TERMINATE:
225 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
226 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
227 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
229 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
234 case WM_DDE_ACK: /* happens on win9x when fAckReq is TRUE, ignore it */
235 ok(msg_index == 4, "Expected 4, got %d\n", msg_index);
240 ok(FALSE, "Unhandled msg: %08x\n", msg);
243 return DefWindowProcA(hwnd, msg, wparam, lparam);
246 static void test_msg_server(HANDLE hproc, HANDLE hthread)
252 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
253 ResumeThread( hthread );
255 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
257 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
260 destroy_dde_window(&hwnd, "dde_server");
261 GetExitCodeProcess( hproc, &res );
262 ok( !res, "client failed with %u error(s)\n", res );
265 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
266 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
267 ULONG_PTR dwData1, ULONG_PTR dwData2)
269 ok(FALSE, "Unhandled msg: %08x\n", uType);
273 static void test_ddeml_client(void)
280 HSZ server, topic, item;
285 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
286 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
288 /* FIXME: make these atoms global and check them in the server */
290 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
291 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
293 DdeGetLastError(client_pid);
294 conversation = DdeConnect(client_pid, server, topic, NULL);
295 ok(conversation != NULL, "Expected non-NULL conversation\n");
296 ret = DdeGetLastError(client_pid);
297 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
299 DdeFreeStringHandle(client_pid, server);
301 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
303 /* XTYP_REQUEST, fRelease = TRUE */
305 DdeGetLastError(client_pid);
306 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
307 ret = DdeGetLastError(client_pid);
308 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
309 ok(res == DDE_FNOTPROCESSED || broken(res == 0xdeadbeef), /* win9x */
310 "Expected DDE_FNOTPROCESSED, got %08x\n", res);
311 ok( hdata != NULL, "hdata is NULL\n" );
314 str = (LPSTR)DdeAccessData(hdata, &size);
315 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
316 ok(size == 19 || broken(size == 28), /* sizes are rounded up on win9x */
317 "Expected 19, 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 == 19 || broken(size == 28), /* sizes are rounded up on win9x */
339 "Expected 19, got %d\n", size);
341 ret = DdeUnaccessData(hdata);
342 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
345 /* XTYP_REQUEST, all params normal */
347 DdeGetLastError(client_pid);
348 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
349 ret = DdeGetLastError(client_pid);
350 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
351 ok(res == DDE_FNOTPROCESSED || broken(res == 0xdeadbeef), /* win9x */
352 "Expected DDE_FNOTPROCESSED, got %x\n", res);
354 ok(FALSE, "hdata is NULL\n");
357 str = (LPSTR)DdeAccessData(hdata, &size);
358 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
359 ok(size == 19 || broken(size == 28), /* sizes are rounded up on win9x */
360 "Expected 19, got %d\n", size);
362 ret = DdeUnaccessData(hdata);
363 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
366 /* XTYP_REQUEST, no item */
368 DdeGetLastError(client_pid);
369 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
370 ret = DdeGetLastError(client_pid);
371 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
372 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
373 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
375 DdeFreeStringHandle(client_pid, item);
377 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
379 lstrcpyA(buffer, "poke data\r\n");
380 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
381 0, item, CF_TEXT, 0);
382 ok(hdata != NULL, "Expected non-NULL hdata\n");
384 /* XTYP_POKE, no item */
386 DdeGetLastError(client_pid);
387 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
388 ret = DdeGetLastError(client_pid);
389 ok(op == NULL, "Expected NULL, got %p\n", op);
390 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
391 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
393 /* XTYP_POKE, no data */
395 DdeGetLastError(client_pid);
396 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
397 ret = DdeGetLastError(client_pid);
398 ok(op == NULL, "Expected NULL, got %p\n", op);
399 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
400 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
402 /* XTYP_POKE, wrong size */
404 DdeGetLastError(client_pid);
405 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
406 ret = DdeGetLastError(client_pid);
407 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
408 ok(res == DDE_FACK || broken(res == (0xdead0000 | DDE_FACK)), /* win9x */
409 "Expected DDE_FACK, got %x\n", res);
410 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
412 /* XTYP_POKE, correct params */
414 DdeGetLastError(client_pid);
415 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
416 ret = DdeGetLastError(client_pid);
417 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
418 ok(res == DDE_FACK || broken(res == (0xdead0000 | DDE_FACK)), /* win9x */
419 "Expected DDE_FACK, got %x\n", res);
420 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
422 DdeFreeDataHandle(hdata);
424 lstrcpyA(buffer, "[Command(Var)]");
425 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
426 0, NULL, CF_TEXT, 0);
427 ok(hdata != NULL, "Expected non-NULL hdata\n");
429 /* XTYP_EXECUTE, correct params */
431 DdeGetLastError(client_pid);
432 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
433 ret = DdeGetLastError(client_pid);
434 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
435 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
436 ok(res == DDE_FACK || broken(res == (0xdead0000 | DDE_FACK)), /* win9x */
437 "Expected DDE_FACK, got %x\n", res);
439 /* XTYP_EXECUTE, no data */
441 DdeGetLastError(client_pid);
442 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
443 ret = DdeGetLastError(client_pid);
444 ok(op == NULL || broken(op == (HDDEDATA)TRUE), /* win9x */ "Expected NULL, got %p\n", op);
447 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
448 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
452 ok(res == (0xdead0000 | DDE_FACK), "Expected DDE_FACK, got %x\n", res);
453 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
456 /* XTYP_EXECUTE, no data, -1 size */
458 DdeGetLastError(client_pid);
459 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
460 ret = DdeGetLastError(client_pid);
461 ok(op == NULL, "Expected NULL, got %p\n", op);
462 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
463 ok(ret == DMLERR_INVALIDPARAMETER || broken(ret == DMLERR_NO_ERROR), /* win9x */
464 "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
466 DdeFreeStringHandle(client_pid, topic);
467 DdeFreeDataHandle(hdata);
469 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
471 /* verify the execute */
473 DdeGetLastError(client_pid);
474 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
475 ret = DdeGetLastError(client_pid);
476 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
477 ok(res == DDE_FNOTPROCESSED || broken(res == (0xdead0000 | DDE_FNOTPROCESSED)), /* win9x */
478 "Expected DDE_FNOTPROCESSED, got %d\n", res);
480 ok(FALSE, "hdata is NULL\n");
483 str = (LPSTR)DdeAccessData(hdata, &size);
484 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
485 ok(size == 21 || broken(size == 28), /* sizes are rounded up on win9x */
486 "Expected 21, got %d\n", size);
488 ret = DdeUnaccessData(hdata);
489 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
492 /* invalid transactions */
494 DdeGetLastError(client_pid);
495 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
496 ret = DdeGetLastError(client_pid);
497 ok(op == NULL, "Expected NULL, got %p\n", op);
498 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
499 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
502 DdeGetLastError(client_pid);
503 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, default_timeout, &res);
504 ret = DdeGetLastError(client_pid);
505 ok(op == NULL, "Expected NULL, got %p\n", op);
506 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
507 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
510 DdeGetLastError(client_pid);
511 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, default_timeout, &res);
512 ret = DdeGetLastError(client_pid);
513 ok(op == NULL, "Expected NULL, got %p\n", op);
514 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
515 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
518 DdeGetLastError(client_pid);
519 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, default_timeout, &res);
520 ret = DdeGetLastError(client_pid);
521 ok(op == NULL, "Expected NULL, got %p\n", op);
522 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
523 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
526 DdeGetLastError(client_pid);
527 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, default_timeout, &res);
528 ret = DdeGetLastError(client_pid);
529 ok(op == NULL, "Expected NULL, got %p\n", op);
530 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
531 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
534 DdeGetLastError(client_pid);
535 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, default_timeout, &res);
536 ret = DdeGetLastError(client_pid);
537 ok(op == NULL, "Expected NULL, got %p\n", op);
538 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
539 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
542 DdeGetLastError(client_pid);
543 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, default_timeout, &res);
544 ret = DdeGetLastError(client_pid);
545 ok(op == NULL, "Expected NULL, got %p\n", op);
546 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
547 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
550 DdeGetLastError(client_pid);
551 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, default_timeout, &res);
552 ret = DdeGetLastError(client_pid);
553 ok(op == NULL, "Expected NULL, got %p\n", op);
554 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
555 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
558 DdeGetLastError(client_pid);
559 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
560 ret = DdeGetLastError(client_pid);
561 ok(op == NULL, "Expected NULL, got %p\n", op);
562 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
563 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
566 DdeGetLastError(client_pid);
567 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
568 ret = DdeGetLastError(client_pid);
569 ok(op == NULL, "Expected NULL, got %p\n", op);
570 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
571 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
573 DdeFreeStringHandle(client_pid, item);
575 ret = DdeDisconnect(conversation);
576 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
578 ret = DdeUninitialize(client_pid);
579 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
582 static DWORD server_pid;
584 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
585 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
586 ULONG_PTR dwData1, ULONG_PTR dwData2)
588 char str[MAX_PATH], *ptr;
592 static int msg_index = 0;
593 static HCONV conversation = 0;
601 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
602 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
603 ok(hconv == 0, "Expected 0, got %p\n", hconv);
604 ok(hdata == 0, "Expected 0, got %p\n", hdata);
605 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
606 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
608 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
609 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
610 ok(size == 13, "Expected 13, got %d\n", size);
612 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
613 if (!strncmp( str, "TestDDEServer:(", 15 )) /* win9x style */
615 ok(size == 16 + 2*sizeof(WORD), "Got size %d for %s\n", size, str);
619 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
620 ok(size == 17 + 2*sizeof(ULONG_PTR), "Got size %d for %s\n", size, str);
622 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
624 return (HDDEDATA)TRUE;
629 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
630 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
631 ok(hconv == 0, "Expected 0, got %p\n", hconv);
632 ok(hdata == 0, "Expected 0, got %p\n", hdata);
633 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
634 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
636 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
637 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
638 ok(size == 12, "Expected 12, got %d\n", size);
640 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
641 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
642 ok(size == 13, "Expected 13, got %d\n", size);
644 return (HDDEDATA)TRUE;
647 case XTYP_CONNECT_CONFIRM:
649 conversation = hconv;
651 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
652 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
653 ok(hconv != NULL, "Expected non-NULL hconv\n");
654 ok(hdata == 0, "Expected 0, got %p\n", hdata);
655 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
656 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
658 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
659 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
660 ok(size == 12, "Expected 12, got %d\n", size);
662 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
663 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
664 ok(size == 13, "Expected 13, got %d\n", size);
666 return (HDDEDATA)TRUE;
671 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
672 "Expected 4, 5 or 6, got %d\n", msg_index);
673 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
674 ok(hdata == 0, "Expected 0, got %p\n", hdata);
675 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
676 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
679 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
681 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
683 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
684 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
685 ok(size == 12, "Expected 12, got %d\n", size);
687 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
692 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
693 ok(size == 1, "Expected 1, got %d\n", size);
696 else if (msg_index == 6)
698 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
699 ok(size == 7, "Expected 7, got %d\n", size);
704 lstrcpyA(str, "requested data\r\n");
705 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
706 0, hsz2, CF_TEXT, 0);
714 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
715 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
716 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
717 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
718 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
720 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
721 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
722 ok(size == 12, "Expected 12, got %d\n", size);
724 ptr = (LPSTR)DdeAccessData(hdata, &size);
725 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
726 ok(size == 12 || broken(size == 28), /* sizes are rounded up on win9x */
727 "Expected 12, got %d\n", size);
728 DdeUnaccessData(hdata);
730 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
734 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
735 ok(size == 1, "Expected 1, got %d\n", size);
740 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
741 ok(size == 4, "Expected 4, got %d\n", size);
744 return (HDDEDATA)DDE_FACK;
749 ok(msg_index >= 9 && msg_index <= 11, "Expected 9 or 11, got %d\n", msg_index);
750 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
751 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
752 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
753 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
754 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
756 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
757 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
758 ok(size == 12, "Expected 12, got %d\n", size);
760 if (msg_index == 9 || msg_index == 11)
762 ptr = (LPSTR)DdeAccessData(hdata, &size);
766 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
767 ok(size == 15, "Expected 15, got %d\n", size);
768 ret = (HDDEDATA)DDE_FACK;
772 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
773 ok(size == 18, "Expected 18, got %d\n", size);
774 ret = DDE_FNOTPROCESSED;
777 DdeUnaccessData(hdata);
779 else if (msg_index == 10)
784 size = DdeGetData(hdata, NULL, 0, 0);
785 ok(size == 17, "DdeGetData should have returned 17 not %d\n", size);
786 ptr = HeapAlloc(GetProcessHeap(), 0, size);
787 ok(ptr != NULL,"HeapAlloc should have returned ptr not NULL\n");
788 rsize = DdeGetData(hdata, (LPBYTE)ptr, size, 0);
789 ok(rsize == size, "DdeGetData did not return %d bytes but %d\n", size, rsize);
791 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr);
792 ok(size == 17, "Expected 17, got %d\n", size);
793 ret = (HDDEDATA)DDE_FACK;
795 HeapFree(GetProcessHeap(), 0, ptr);
801 case XTYP_DISCONNECT:
803 ok(msg_index == 12, "Expected 12, got %d\n", msg_index);
804 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
805 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
806 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
807 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
808 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
809 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
815 ok(FALSE, "Unhandled msg: %08x\n", uType);
821 static void test_ddeml_server(HANDLE hproc)
829 /* set up DDE server */
831 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
832 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
834 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
835 ok(server != NULL, "Expected non-NULL string handle\n");
837 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
838 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
840 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
842 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
844 ret = DdeUninitialize(server_pid);
845 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
846 GetExitCodeProcess( hproc, &res );
847 ok( !res, "client failed with %u error(s)\n", res );
850 static HWND client_hwnd, server_hwnd;
851 static ATOM server, topic, item;
852 static HGLOBAL execute_hglobal;
854 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
863 static int msg_index = 0;
865 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
866 return DefWindowProcA(hwnd, msg, wparam, lparam);
872 case WM_DDE_INITIATE:
874 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
875 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
877 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
878 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
879 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
880 ok(size == 13, "Expected 13, got %d\n", size);
882 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
883 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
884 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
885 ok(size == 12, "Expected 12, got %d\n", size);
892 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 11),
893 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index);
897 server_hwnd = (HWND)wparam;
898 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
900 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
901 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
902 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
903 ok(size == 13, "Expected 13, got %d\n", size);
905 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
906 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
907 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
908 ok(size == 12, "Expected 12, got %d\n", size);
910 else if (msg_index >= 9 && msg_index <= 11)
912 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
914 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
917 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
918 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
919 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
921 ok(hi == (UINT_PTR)execute_hglobal, "Expected execute hglobal, got %08lx\n", hi);
922 ptr = GlobalLock((HGLOBAL)hi);
926 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
927 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
928 } else if (msg_index == 10)
930 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
931 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr);
935 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
936 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
939 GlobalUnlock((HGLOBAL)hi);
943 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
945 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
948 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
949 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
950 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
953 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
956 if (msg_index == 6) todo_wine
957 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
960 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
963 ok(hi == item, "Expected item atom, got %08lx\n", hi);
964 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
965 ok(size == 7, "Expected 7, got %d\n", size);
967 else if (msg_index == 4 || msg_index == 7)
969 ok(hi == 0, "Expected 0, got %08lx\n", hi);
970 ok(size == 0, "Expected empty string, got %d\n", size);
974 ok(hi == item, "Expected item atom, got %08lx\n", hi);
975 if (msg_index == 6) todo_wine
977 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
978 ok(size == 4, "Expected 4, got %d\n", size);
988 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
989 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
991 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
993 data = GlobalLock((HGLOBAL)lo);
994 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
995 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
998 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
1000 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
1001 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
1002 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
1003 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
1004 GlobalUnlock((HGLOBAL)lo);
1006 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
1007 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
1008 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
1009 ok(size == 7, "Expected 7, got %d\n", size);
1011 GlobalFree((HGLOBAL)lo);
1012 GlobalDeleteAtom(hi);
1018 ok(FALSE, "Unhandled msg: %08x\n", msg);
1021 return DefWindowProcA(hwnd, msg, wparam, lparam);
1024 static HGLOBAL create_poke(void)
1030 size = FIELD_OFFSET(DDEPOKE, Value[sizeof("poke data\r\n")]);
1031 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
1032 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1034 poke = GlobalLock(hglobal);
1036 poke->fRelease = TRUE;
1037 poke->fReserved = TRUE;
1038 poke->cfFormat = CF_TEXT;
1039 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
1040 GlobalUnlock(hglobal);
1045 static HGLOBAL create_execute(LPCSTR command)
1050 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1051 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1053 ptr = GlobalLock(hglobal);
1054 lstrcpyA(ptr, command);
1055 GlobalUnlock(hglobal);
1060 static void test_msg_client(void)
1065 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1067 server = GlobalAddAtomA("TestDDEServer");
1068 ok(server != 0, "Expected non-NULL server\n");
1070 topic = GlobalAddAtomA("TestDDETopic");
1071 ok(topic != 0, "Expected non-NULL topic\n");
1073 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1075 GlobalDeleteAtom(server);
1076 GlobalDeleteAtom(topic);
1080 item = GlobalAddAtom("request");
1081 ok(item != 0, "Expected non-NULL item\n");
1083 /* WM_DDE_REQUEST, bad clipboard format */
1084 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1085 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1089 /* WM_DDE_REQUEST, no item */
1090 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1091 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1095 /* WM_DDE_REQUEST, no client hwnd */
1096 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1097 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1101 /* WM_DDE_REQUEST, correct params */
1102 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1103 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1107 GlobalDeleteAtom(item);
1108 item = GlobalAddAtomA("poke");
1109 ok(item != 0, "Expected non-NULL item\n");
1111 hglobal = create_poke();
1113 /* WM_DDE_POKE, no ddepoke */
1114 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1115 /* win9x returns 0 here and crashes in PostMessageA */
1117 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1121 win_skip("no lparam for WM_DDE_POKE\n");
1124 /* WM_DDE_POKE, no item */
1125 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1126 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1130 hglobal = create_poke();
1132 /* WM_DDE_POKE, no client hwnd */
1133 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1134 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1138 /* WM_DDE_POKE, all params correct */
1139 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1140 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1144 execute_hglobal = create_execute("[Command(Var)]");
1146 /* WM_DDE_EXECUTE, no lparam */
1147 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1151 /* WM_DDE_EXECUTE, no hglobal */
1152 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1153 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1157 /* WM_DDE_EXECUTE, no client hwnd */
1158 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1159 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1163 /* WM_DDE_EXECUTE, all params correct */
1164 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1165 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1169 GlobalFree(execute_hglobal);
1170 execute_hglobal = create_execute("[Command-2(Var)]");
1172 /* WM_DDE_EXECUTE, all params correct */
1173 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1174 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1178 GlobalFree(execute_hglobal);
1179 execute_hglobal = create_execute("[BadCommand(Var)]");
1181 /* WM_DDE_EXECUTE that will get rejected */
1182 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1183 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1187 destroy_dde_window(&client_hwnd, "dde_client");
1190 static LRESULT WINAPI hook_dde_client_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1194 trace("hook_dde_client_wndprocA: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1199 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1200 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1206 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1209 static LRESULT WINAPI hook_dde_client_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1213 trace("hook_dde_client_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1218 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1219 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1225 return CallWindowProcW(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1228 static LRESULT WINAPI dde_server_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1230 static BOOL client_unicode, conv_unicode;
1235 case WM_DDE_INITIATE:
1237 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1239 trace("server A: got WM_DDE_INITIATE from %p (%s) with %08lx\n",
1240 (HWND)wparam, client_unicode ? "Unicode" : "ANSI", lparam);
1242 if (LOWORD(lparam) == aService)
1244 client_unicode = IsWindowUnicode((HWND)wparam);
1245 conv_unicode = client_unicode;
1246 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1249 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1250 (ULONG_PTR)hook_dde_client_wndprocW);
1252 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1253 (ULONG_PTR)hook_dde_client_wndprocA);
1254 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1255 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1258 GlobalDeleteAtom(aService);
1262 case WM_DDE_EXECUTE:
1269 trace("server A: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1271 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1272 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1274 ack.bAppReturnCode = 0;
1277 /* We have to send a negative acknowledge even if we don't
1278 * accept the command, otherwise Windows goes mad and next time
1279 * we send an acknowledge DDEML drops the connection.
1280 * Not sure how to call it: a bug or a feature.
1284 if ((cmd = GlobalLock((HGLOBAL)hi)))
1286 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1290 case 0: /* bad command */
1291 trace( "server A got unhandled command\n" );
1294 case 1: /* ANSI command */
1296 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1297 else /* we get garbage as the A command was mapped W->A */
1298 ok( cmd[0] != exec_cmdA[0], "server A got wrong command '%s'\n", cmd );
1301 case 2: /* ANSI command in Unicode format */
1303 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1305 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server A got wrong command '%s'\n", cmd );
1308 case 3: /* Unicode command */
1310 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server A got wrong command '%s'\n", cmd );
1311 else /* correctly mapped W->A */
1312 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1315 case 4: /* Unicode command in ANSI format */
1317 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1318 else /* we get garbage as the A command was mapped W->A */
1319 ok( cmd[0] != exec_cmdWA[0], "server A got wrong command '%s'\n", cmd );
1322 GlobalUnlock((HGLOBAL)hi);
1324 else ok( 0, "bad command data %lx\n", hi );
1327 trace("server A: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1329 status = *((WORD *)&ack);
1330 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1332 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1336 case WM_DDE_TERMINATE:
1341 trace("server A: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1343 ack.bAppReturnCode = 0;
1348 trace("server A: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1350 status = *((WORD *)&ack);
1351 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1353 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1361 return DefWindowProcA(hwnd, msg, wparam, lparam);
1364 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1366 static BOOL client_unicode, conv_unicode;
1371 case WM_DDE_INITIATE:
1373 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1375 if (LOWORD(lparam) == aService)
1377 client_unicode = IsWindowUnicode((HWND)wparam);
1378 conv_unicode = client_unicode;
1379 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1382 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1383 (ULONG_PTR)hook_dde_client_wndprocW);
1385 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1386 (ULONG_PTR)hook_dde_client_wndprocA);
1387 trace("server W: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1388 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1391 GlobalDeleteAtom(aService);
1393 trace("server W: got WM_DDE_INITIATE from %p with %08lx (client %s conv %s)\n", (HWND)wparam,
1394 lparam, client_unicode ? "Unicode" : "ANSI", conv_unicode ? "Unicode" : "ANSI" );
1399 case WM_DDE_EXECUTE:
1406 trace("server W: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1408 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1409 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1411 ack.bAppReturnCode = 0;
1414 /* We have to send a negative acknowledge even if we don't
1415 * accept the command, otherwise Windows goes mad and next time
1416 * we send an acknowledge DDEML drops the connection.
1417 * Not sure how to call it: a bug or a feature.
1421 if ((cmd = GlobalLock((HGLOBAL)hi)))
1423 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1427 case 0: /* bad command */
1428 trace( "server W got unhandled command\n" );
1431 case 1: /* ANSI command */
1432 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1433 ok( cmd[0] != exec_cmdA[0], "server W got wrong command '%s'\n", cmd );
1434 else if (!conv_unicode && client_unicode) /* A->W mapping */
1435 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1437 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1440 case 2: /* ANSI command in Unicode format */
1441 if (conv_unicode && !client_unicode) /* W->A mapping */
1442 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1443 else if (!conv_unicode && client_unicode) /* A->W mapping */
1444 ok( *(WCHAR *)cmd == exec_cmdAW[0], "server W got wrong command '%s'\n", cmd );
1446 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1449 case 3: /* Unicode command */
1450 if (conv_unicode && !client_unicode) /* W->A mapping */
1451 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1452 else if (!conv_unicode && client_unicode) /* A->W mapping */
1453 ok( *(WCHAR *)cmd == exec_cmdW[0], "server W got wrong command '%s'\n", cmd );
1455 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1458 case 4: /* Unicode command in ANSI format */
1459 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1460 ok( cmd[0] != exec_cmdWA[0], "server W got wrong command '%s'\n", cmd );
1461 else if (!conv_unicode && client_unicode) /* A->W mapping */
1462 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1464 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1467 GlobalUnlock((HGLOBAL)hi);
1469 else ok( 0, "bad command data %lx\n", hi );
1472 trace("server W: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1474 status = *((WORD *)&ack);
1475 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1477 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1481 case WM_DDE_TERMINATE:
1486 trace("server W: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1488 ack.bAppReturnCode = 0;
1493 trace("server W: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1495 status = *((WORD *)&ack);
1496 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1498 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1506 return DefWindowProcW(hwnd, msg, wparam, lparam);
1509 static HWND create_dde_server( BOOL unicode )
1514 static const char server_class_nameA[] = "dde_server_windowA";
1515 static const WCHAR server_class_nameW[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w','W',0};
1519 memset(&wcW, 0, sizeof(wcW));
1520 wcW.lpfnWndProc = dde_server_wndprocW;
1521 wcW.lpszClassName = server_class_nameW;
1522 wcW.hInstance = GetModuleHandleA(0);
1523 RegisterClassW(&wcW);
1525 server = CreateWindowExW(0, server_class_nameW, NULL, WS_POPUP,
1526 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1527 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1531 memset(&wcA, 0, sizeof(wcA));
1532 wcA.lpfnWndProc = dde_server_wndprocA;
1533 wcA.lpszClassName = server_class_nameA;
1534 wcA.hInstance = GetModuleHandleA(0);
1535 RegisterClassA(&wcA);
1537 server = CreateWindowExA(0, server_class_nameA, NULL, WS_POPUP,
1538 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1539 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1541 ok(!IsWindowUnicode(server) == !unicode, "wrong unicode type\n");
1545 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1546 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1547 ULONG_PTR dwData1, ULONG_PTR dwData2)
1549 static const char * const cmd_type[15] = {
1550 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1551 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1552 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1553 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1555 const char *cmd_name;
1557 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1558 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1560 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1561 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1565 static void test_dde_aw_transaction( BOOL client_unicode, BOOL server_unicode )
1568 DWORD dde_inst, ret, err;
1573 BOOL conv_unicode = client_unicode;
1575 static char test_cmd[] = "test dde command";
1577 if (!(hwnd_server = create_dde_server( server_unicode ))) return;
1581 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1583 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1584 ok(ret == DMLERR_NO_ERROR, "DdeInitializeA failed with error %04x (%x)\n",
1585 ret, DdeGetLastError(dde_inst));
1587 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1589 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1590 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1591 err = DdeGetLastError(dde_inst);
1592 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1594 info.cb = sizeof(info);
1595 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1596 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1597 ok(info.ConvCtxt.iCodePage == client_unicode ? CP_WINUNICODE : CP_WINANSI,
1598 "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1599 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1601 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1603 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1604 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1605 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1607 client_unicode = IsWindowUnicode( info.hwnd );
1608 trace("hwnd %p, hwndPartner %p, unicode %u\n", info.hwnd, info.hwndPartner, client_unicode);
1610 trace("sending test client transaction command\n");
1612 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1613 ok(!hdata, "DdeClientTransaction succeeded\n");
1614 ok(ret == DDE_FNOTPROCESSED || broken(ret == (0xdead0000 | DDE_FNOTPROCESSED)), /* win9x */
1615 "wrong status code %04x\n", ret);
1616 err = DdeGetLastError(dde_inst);
1617 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1619 trace("sending ANSI client transaction command\n");
1621 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1622 err = DdeGetLastError(dde_inst);
1623 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1625 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1626 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1627 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1629 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> wrong cmd */
1631 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1632 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1633 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1635 else /* no mapping */
1637 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1638 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1639 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1642 trace("sending ANSI-as-Unicode client transaction command\n");
1644 hdata = DdeClientTransaction((LPBYTE)exec_cmdAW, (lstrlenW(exec_cmdAW) + 1) * sizeof(WCHAR),
1645 hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1646 err = DdeGetLastError(dde_inst);
1647 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping */
1649 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1650 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1651 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1653 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1655 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1656 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1657 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1659 else /* no mapping */
1661 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1662 ok(ret == DDE_FNOTPROCESSED || broken(ret == (0xdead0000 | DDE_FNOTPROCESSED)), /* win9x */
1663 "wrong status code %04x\n", ret);
1664 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1667 trace("sending unicode client transaction command\n");
1669 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1670 err = DdeGetLastError(dde_inst);
1671 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> wrong cmd */
1673 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1674 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1675 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1677 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1679 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1680 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1681 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1683 else /* no mapping */
1685 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1686 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1687 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1690 trace("sending Unicode-as-ANSI client transaction command\n");
1692 hdata = DdeClientTransaction((LPBYTE)exec_cmdWA, lstrlenA(exec_cmdWA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1693 err = DdeGetLastError(dde_inst);
1694 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1696 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1697 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1698 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1700 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping */
1702 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1703 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1704 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1706 else /* no mapping */
1708 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1709 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1710 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1713 got = DdeDisconnect(hconv);
1714 ok(got, "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1716 info.cb = sizeof(info);
1717 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1718 ok(!ret, "DdeQueryConvInfo should fail\n");
1719 err = DdeGetLastError(dde_inst);
1721 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1724 got = DdeFreeStringHandle(dde_inst, hsz_server);
1725 ok(got, "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1727 /* This call hangs on win2k SP4 and XP SP1.
1728 DdeUninitialize(dde_inst);*/
1730 DestroyWindow(hwnd_server);
1733 static void test_initialisation(void)
1738 HSZ server, topic, item;
1742 /* Initialise without a valid server window. */
1744 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1745 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
1748 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
1749 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
1751 DdeGetLastError(client_pid);
1753 /* There is no server window so no conversation can be extracted */
1754 conversation = DdeConnect(client_pid, server, topic, NULL);
1755 ok(conversation == NULL, "Expected NULL conversation, %p\n", conversation);
1756 ret = DdeGetLastError(client_pid);
1757 ok(ret == DMLERR_NO_CONV_ESTABLISHED, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret);
1759 DdeFreeStringHandle(client_pid, server);
1761 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
1763 /* There is no converstation so an invalild parameter results */
1765 DdeGetLastError(client_pid);
1766 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
1767 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1768 ret = DdeGetLastError(client_pid);
1770 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
1771 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
1773 DdeFreeStringHandle(client_pid, server);
1774 ret = DdeDisconnect(conversation);
1775 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1777 ret = DdeUninitialize(client_pid);
1778 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1781 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1783 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1790 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1791 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1792 DdeGetLastError(dde_inst));
1794 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1795 if (codepage == CP_WINANSI)
1796 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1798 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1800 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1801 if (codepage == CP_WINANSI)
1803 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1804 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1808 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1809 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1812 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1813 if (codepage == CP_WINANSI)
1815 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1816 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1820 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1821 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1824 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1825 if (codepage == CP_WINANSI)
1827 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1828 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1832 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1833 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1836 if (codepage == CP_WINANSI)
1838 atom = FindAtomA((LPSTR)dde_string);
1839 ok(atom != 0, "Expected a valid atom\n");
1841 SetLastError(0xdeadbeef);
1842 atom = GlobalFindAtomA((LPSTR)dde_string);
1843 ok(atom == 0, "Expected 0, got %d\n", atom);
1844 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1845 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1849 atom = FindAtomW(dde_string);
1850 ok(atom != 0, "Expected a valid atom\n");
1852 SetLastError(0xdeadbeef);
1853 atom = GlobalFindAtomW(dde_string);
1854 ok(atom == 0, "Expected 0, got %d\n", atom);
1855 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1856 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1859 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1862 static void test_DdeCreateDataHandle(void)
1865 DWORD dde_inst, dde_inst2;
1871 WCHAR item_str[] = {'i','t','e','m',0};
1875 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1876 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1878 res = DdeInitializeA(&dde_inst2, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1879 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1882 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1883 * is invalid then the lastError of all instances is set to the error. There are two instances
1884 * created, lastError is cleared, an error is generated and then both instances are checked to
1885 * ensure that they both have the same error set
1887 item = DdeCreateStringHandleA(0, "item", CP_WINANSI);
1888 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1889 err = DdeGetLastError(dde_inst);
1890 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1891 err = DdeGetLastError(dde_inst2);
1892 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1893 item = DdeCreateStringHandleW(0, item_str, CP_WINUNICODE);
1894 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1895 err = DdeGetLastError(dde_inst);
1896 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1897 err = DdeGetLastError(dde_inst2);
1898 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1900 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1901 ok(item != NULL, "Expected non-NULL hsz\n");
1902 item = DdeCreateStringHandleA(dde_inst2, "item", CP_WINANSI);
1903 ok(item != NULL, "Expected non-NULL hsz\n");
1906 /* do not test with an invalid instance id: that crashes on win9x */
1907 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1911 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1912 * is invalid then the lastError of all instances is set to the error. There are two instances
1913 * created, lastError is cleared, an error is generated and then both instances are checked to
1914 * ensure that they both have the same error set
1916 DdeGetLastError(dde_inst);
1917 DdeGetLastError(dde_inst2);
1918 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1919 err = DdeGetLastError(dde_inst);
1920 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1921 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1922 err = DdeGetLastError(dde_inst2);
1923 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1925 ret = DdeUninitialize(dde_inst2);
1926 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1930 DdeGetLastError(dde_inst);
1931 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1932 err = DdeGetLastError(dde_inst);
1933 ok(hdata != NULL, "Expected non-NULL hdata\n");
1934 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1936 ptr = DdeAccessData(hdata, &size);
1937 ok(ptr != NULL, "Expected non-NULL ptr\n");
1938 ok(size == 260, "Expected 260, got %d\n", size);
1940 ret = DdeUnaccessData(hdata);
1941 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1943 ret = DdeFreeDataHandle(hdata);
1944 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1947 DdeGetLastError(dde_inst);
1948 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1949 err = DdeGetLastError(dde_inst);
1950 ok(hdata != NULL, "Expected non-NULL hdata\n");
1951 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1953 ptr = DdeAccessData(hdata, &size);
1954 ok(ptr != NULL, "Expected non-NULL ptr\n");
1955 ok(size == 0, "Expected 0, got %d\n", size);
1957 ret = DdeUnaccessData(hdata);
1958 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1960 ret = DdeFreeDataHandle(hdata);
1961 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1963 /* cbOff is non-zero */
1964 DdeGetLastError(dde_inst);
1965 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1966 err = DdeGetLastError(dde_inst);
1967 ok(hdata != NULL, "Expected non-NULL hdata\n");
1968 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1970 ptr = DdeAccessData(hdata, &size);
1971 ok(ptr != NULL, "Expected non-NULL ptr\n");
1972 ok(size == 262, "Expected 262, got %d\n", size);
1975 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1978 ret = DdeUnaccessData(hdata);
1979 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1981 ret = DdeFreeDataHandle(hdata);
1982 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1985 DdeGetLastError(dde_inst);
1986 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1987 err = DdeGetLastError(dde_inst);
1988 ok(hdata != NULL, "Expected non-NULL hdata\n");
1989 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1991 ptr = DdeAccessData(hdata, &size);
1992 ok(ptr != NULL, "Expected non-NULL ptr\n");
1993 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1994 ok(size == 260, "Expected 260, got %d\n", size);
1996 ret = DdeUnaccessData(hdata);
1997 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1999 ret = DdeFreeDataHandle(hdata);
2000 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2003 DdeGetLastError(dde_inst);
2004 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
2005 err = DdeGetLastError(dde_inst);
2006 ok(hdata != NULL, "Expected non-NULL hdata\n");
2007 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
2009 ptr = DdeAccessData(hdata, &size);
2010 ok(ptr != NULL, "Expected non-NULL ptr\n");
2011 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
2012 ok(size == 260, "Expected 260, got %d\n", size);
2014 ret = DdeUnaccessData(hdata);
2015 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2017 ret = DdeFreeDataHandle(hdata);
2018 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2020 /* invalid clipboard format */
2021 DdeGetLastError(dde_inst);
2022 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
2023 err = DdeGetLastError(dde_inst);
2024 ok(hdata != NULL, "Expected non-NULL hdata\n");
2025 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
2027 ptr = DdeAccessData(hdata, &size);
2028 ok(ptr != NULL, "Expected non-NULL ptr\n");
2029 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
2030 ok(size == 260, "Expected 260, got %d\n", size);
2032 ret = DdeUnaccessData(hdata);
2033 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2035 ret = DdeFreeDataHandle(hdata);
2036 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2038 ret = DdeUninitialize(dde_inst);
2039 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
2042 static void test_DdeCreateStringHandle(void)
2044 DWORD dde_inst, ret;
2046 dde_inst = 0xdeadbeef;
2047 SetLastError(0xdeadbeef);
2048 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2049 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
2050 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
2053 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2054 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
2055 ret, DdeGetLastError(dde_inst));
2057 test_DdeCreateStringHandleW(dde_inst, 0);
2058 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
2059 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
2061 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
2064 static void test_FreeDDElParam(void)
2066 HGLOBAL val, hglobal;
2069 ret = FreeDDElParam(WM_DDE_INITIATE, 0);
2070 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2072 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2073 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
2074 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2075 val = GlobalFree(hglobal);
2076 ok(val == NULL, "Expected NULL, got %p\n", val);
2078 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2079 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
2080 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2082 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2083 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
2084 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2085 val = GlobalFree(hglobal);
2086 ok(val == NULL, "Expected NULL, got %p\n", val);
2088 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2089 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
2090 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2092 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2093 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
2094 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2096 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2097 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
2098 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2099 val = GlobalFree(hglobal);
2100 ok(val == NULL, "Expected NULL, got %p\n", val);
2102 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2103 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
2104 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2106 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2107 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
2108 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2109 val = GlobalFree(hglobal);
2110 ok(val == NULL, "Expected NULL, got %p\n", val);
2113 static void test_PackDDElParam(void)
2115 UINT_PTR lo, hi, *ptr;
2119 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
2120 /* value gets sign-extended despite being an LPARAM */
2121 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2124 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
2125 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2126 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2127 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2129 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
2130 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2132 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
2133 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2136 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
2137 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2138 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2139 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2141 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
2142 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2144 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
2145 /* win9x returns 0 here */
2147 ptr = GlobalLock((HGLOBAL)lparam);
2148 ok(ptr != NULL, "Expected non-NULL ptr\n");
2149 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2150 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2152 ret = GlobalUnlock((HGLOBAL)lparam);
2153 ok(ret == 1, "Expected 1, got %d\n", ret);
2156 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
2157 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2158 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2159 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2162 win_skip("no lparam for WM_DDE_ADVISE\n");
2164 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
2165 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2167 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
2168 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2171 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
2172 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2173 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2174 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2176 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
2177 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2179 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
2180 /* win9x returns the input (0xbeef<<16 | 0xcafe) here */
2181 if (lparam != (int)0xbeefcafe) {
2182 ptr = GlobalLock((HGLOBAL)lparam);
2183 ok(ptr != NULL, "Expected non-NULL ptr\n");
2184 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2185 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2187 ret = GlobalUnlock((HGLOBAL)lparam);
2188 ok(ret == 1, "Expected 1, got %d\n", ret);
2191 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
2192 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2193 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2194 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2196 ret = FreeDDElParam(WM_DDE_ACK, lparam);
2197 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2200 win_skip("got lparam 0x%lx for WM_DDE_ACK\n", lparam);
2202 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
2203 /* win9x returns 0 here */
2205 ptr = GlobalLock((HGLOBAL)lparam);
2206 ok(ptr != NULL, "Expected non-NULL ptr\n");
2207 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2208 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2210 ret = GlobalUnlock((HGLOBAL)lparam);
2211 ok(ret == 1, "Expected 1, got %d\n", ret);
2214 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
2215 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2216 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2217 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2220 win_skip("no lparam for WM_DDE_DATA\n");
2222 ret = FreeDDElParam(WM_DDE_DATA, lparam);
2223 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2225 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
2226 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2229 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
2230 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2231 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2232 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2234 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
2235 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2237 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
2238 /* win9x returns 0 here */
2240 ptr = GlobalLock((HGLOBAL)lparam);
2241 ok(ptr != NULL, "Expected non-NULL ptr\n");
2242 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2243 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2245 ret = GlobalUnlock((HGLOBAL)lparam);
2246 ok(ret == 1, "Expected 1, got %d\n", ret);
2249 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
2250 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2251 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2252 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2255 win_skip("no lparam for WM_DDE_POKE\n");
2257 ret = FreeDDElParam(WM_DDE_POKE, lparam);
2258 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2260 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
2261 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
2264 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
2265 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2266 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2267 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2269 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
2270 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2273 static void test_UnpackDDElParam(void)
2275 UINT_PTR lo, hi, *ptr;
2282 ret = UnpackDDElParam(WM_DDE_INITIATE, 0, &lo, &hi);
2283 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2284 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2285 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2290 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
2291 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2292 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
2293 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2298 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
2299 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2300 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2301 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2305 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
2306 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2307 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2308 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2312 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
2313 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2314 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2315 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2319 ret = UnpackDDElParam(WM_DDE_ADVISE, 0, &lo, &hi);
2320 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2322 broken(lo == 0xdead), /* win2k */
2323 "Expected 0, got %08lx\n", lo);
2325 broken(hi == 0xbeef), /* win2k */
2326 "Expected 0, got %08lx\n", hi);
2328 hglobal = GlobalAlloc(GMEM_DDESHARE, 2 * sizeof(*ptr));
2329 ptr = GlobalLock(hglobal);
2330 ptr[0] = 0xcafebabe;
2331 ptr[1] = 0xdeadbeef;
2332 GlobalUnlock(hglobal);
2336 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2337 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2338 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2339 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2343 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2344 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2345 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2346 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2350 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2351 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2352 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2353 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2357 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2358 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2359 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2360 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2364 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2365 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2366 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2367 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2371 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2372 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2373 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2374 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2378 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2379 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2380 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2381 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2383 GlobalFree(hglobal);
2386 static char test_cmd_a_to_a[] = "Test dde command";
2387 static WCHAR test_cmd_w_to_w[][32] = {
2388 {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0},
2389 { 0x2018, 0x2019, 0x0161, 0x0041, 0x02dc, 0 }, /* some chars that should map properly to CP1252 */
2390 { 0x2026, 0x2020, 0x2021, 0x0d0a, 0 }, /* false negative for IsTextUnicode */
2391 { 0x4efa, 0x4efc, 0x0061, 0x4efe, 0 }, /* some Chinese chars */
2393 static const int nb_callbacks = 5 + sizeof(test_cmd_w_to_w)/sizeof(test_cmd_w_to_w[0]);
2395 static HDDEDATA CALLBACK server_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2396 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2397 ULONG_PTR dwData1, ULONG_PTR dwData2)
2401 static int msg_index = 0;
2402 static HCONV conversation = 0;
2403 static char test_service [] = "TestDDEService";
2404 static char test_topic [] = "TestDDETopic";
2412 ok(msg_index % nb_callbacks == 1, "Expected 1 modulo %u, got %d\n", nb_callbacks, msg_index);
2413 return (HDDEDATA)TRUE;
2418 ok(msg_index % nb_callbacks == 2, "Expected 2 modulo %u, got %d\n", nb_callbacks, msg_index);
2419 ok(uFmt == 0, "Expected 0, got %d, msg_index=%d\n", uFmt, msg_index);
2420 ok(hconv == 0, "Expected 0, got %p, msg_index=%d\n", hconv, msg_index);
2421 ok(hdata == 0, "Expected 0, got %p, msg_index=%d\n", hdata, msg_index);
2422 ok(dwData1 != 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2423 ok(dwData2 == FALSE, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2, msg_index);
2425 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2426 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2427 test_topic, str, msg_index);
2428 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2430 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
2431 ok(!lstrcmpA(str, test_service), "Expected %s, got %s, msg_index=%d\n",
2432 test_service, str, msg_index);
2433 ok(size == 14, "Expected 14, got %d, msg_index=%d\n", size, msg_index);
2435 return (HDDEDATA) TRUE;
2437 case XTYP_CONNECT_CONFIRM:
2439 ok(msg_index % nb_callbacks == 3, "Expected 3 modulo %u, got %d\n", nb_callbacks, msg_index);
2440 conversation = hconv;
2441 return (HDDEDATA) TRUE;
2445 BYTE *buffer = NULL;
2447 char test_cmd_w_to_a[64];
2448 WCHAR test_cmd_a_to_w[64];
2449 DWORD size_a, size_w, size_w_to_a, size_a_to_w;
2450 BOOL unicode_server, unicode_client, str_index;
2452 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
2453 ok(hconv == conversation, "Expected conversation handle, got %p, msg_index=%d\n",
2455 ok(dwData1 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2456 ok(dwData2 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2, msg_index);
2457 ok(hsz2 == 0, "Expected 0, got %p, msg_index=%d\n", hsz2, msg_index);
2458 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2459 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2460 test_topic, str, msg_index);
2461 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2462 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2464 size = DdeGetData(hdata, NULL, 0, 0);
2465 ok((buffer = HeapAlloc(GetProcessHeap(), 0, size)) != NULL, "should not be null\n");
2466 rsize = DdeGetData(hdata, buffer, size, 0);
2467 ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2468 size, rsize, msg_index);
2469 trace("msg %u strA \"%s\" strW %s\n", msg_index, buffer, wine_dbgstr_w((WCHAR*)buffer));
2471 unicode_server = (msg_index / nb_callbacks == 1 || msg_index / nb_callbacks == 2);
2472 unicode_client = (msg_index / nb_callbacks == 1 || msg_index / nb_callbacks == 3);
2473 str_index = msg_index % nb_callbacks - 4;
2474 cmd_w = test_cmd_w_to_w[str_index - 1];
2475 size_a = strlen(test_cmd_a_to_a) + 1;
2476 size_w = (lstrlenW(cmd_w) + 1) * sizeof(WCHAR);
2477 size_a_to_w = MultiByteToWideChar( CP_ACP, 0, test_cmd_a_to_a, -1, test_cmd_a_to_w,
2478 sizeof(test_cmd_a_to_w)/sizeof(WCHAR) ) * sizeof(WCHAR);
2479 size_w_to_a = WideCharToMultiByte( CP_ACP, 0, cmd_w, -1,
2480 test_cmd_w_to_a, sizeof(test_cmd_w_to_a), NULL, NULL );
2483 case 0: /* ASCII string */
2486 ok(size == size_a_to_w, "Wrong size %d/%d, msg_index=%d\n", size, size_a_to_w, msg_index);
2487 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2488 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2490 else if (unicode_client)
2492 /* ASCII string mapped W->A -> garbage */
2496 ok(size == size_a, "Wrong size %d/%d, msg_index=%d\n", size, size_a, msg_index);
2497 ok(!lstrcmpA((CHAR*)buffer, test_cmd_a_to_a), "Expected %s, got %s, msg_index=%d\n",
2498 test_cmd_a_to_a, buffer, msg_index);
2502 case 1: /* Unicode string with only 8-bit chars */
2505 ok(size == size_w, "Wrong size %d/%d, msg_index=%d\n", size, size_w, msg_index);
2506 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2507 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2509 else if (unicode_client)
2511 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n", size, size_w_to_a, msg_index);
2512 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2513 test_cmd_w_to_a, buffer, msg_index);
2517 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n",
2518 size, size_w_to_a, msg_index);
2519 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2520 test_cmd_w_to_a, buffer, msg_index);
2524 case 2: /* normal Unicode string */
2525 case 3: /* IsTextUnicode false negative */
2526 case 4: /* Chinese chars */
2529 /* double A->W mapping */
2530 /* NT uses the full size, XP+ only until the first null */
2531 DWORD nt_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, size_w, test_cmd_a_to_w,
2532 sizeof(test_cmd_a_to_w)/sizeof(WCHAR) ) * sizeof(WCHAR);
2533 DWORD xp_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, -1, NULL, 0 ) * sizeof(WCHAR);
2534 ok(size == xp_size || broken(size == nt_size) ||
2535 broken(str_index == 4 && IsDBCSLeadByte(cmd_w[0])) /* East Asian */,
2536 "Wrong size %d/%d, msg_index=%d\n", size, size_a_to_w, msg_index);
2537 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2538 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2540 else if (unicode_client)
2542 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n", size, size_w_to_a, msg_index);
2543 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2544 test_cmd_w_to_a, buffer, msg_index);
2548 ok(size == size_w, "Wrong size %d/%d, msg_index=%d\n", size, size_w, msg_index);
2549 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2550 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2555 ok( 0, "Invalid message %u\n", msg_index );
2558 return (HDDEDATA) DDE_FACK;
2560 case XTYP_DISCONNECT:
2561 return (HDDEDATA) TRUE;
2564 ok(FALSE, "Unhandled msg: %08x, msg_index=%d\n", uType, msg_index);
2570 static HDDEDATA CALLBACK client_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2571 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2572 ULONG_PTR dwData1, ULONG_PTR dwData2)
2576 case XTYP_DISCONNECT:
2577 return (HDDEDATA) TRUE;
2580 ok(FALSE, "Unhandled msg: %08x\n", uType);
2586 static void test_end_to_end_client(BOOL type_a)
2589 DWORD client_pid = 0;
2593 static char test_service[] = "TestDDEService";
2594 static WCHAR test_service_w[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2595 static char test_topic[] = "TestDDETopic";
2596 static WCHAR test_topic_w[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2598 trace("Start end to end client %s\n", type_a ? "ASCII" : "UNICODE");
2601 ret = DdeInitializeA(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2603 ret = DdeInitializeW(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2604 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2608 server = DdeCreateStringHandleA(client_pid, test_service, CP_WINANSI);
2609 topic = DdeCreateStringHandleA(client_pid, test_topic, CP_WINANSI);
2612 server = DdeCreateStringHandleW(client_pid, test_service_w, CP_WINUNICODE);
2613 topic = DdeCreateStringHandleW(client_pid, test_topic_w, CP_WINUNICODE);
2616 DdeGetLastError(client_pid);
2617 hconv = DdeConnect(client_pid, server, topic, NULL);
2618 ok(hconv != NULL, "Expected non-NULL conversation\n");
2619 ret = DdeGetLastError(client_pid);
2620 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2621 DdeFreeStringHandle(client_pid, server);
2623 /* Test both A and W data being passed to DdeClientTransaction */
2624 hdata = DdeClientTransaction((LPBYTE)test_cmd_a_to_a, sizeof(test_cmd_a_to_a),
2625 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2626 ok(hdata != NULL, "DdeClientTransaction failed\n");
2627 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2628 err = DdeGetLastError(client_pid);
2629 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2631 for (i = 0; i < sizeof(test_cmd_w_to_w)/sizeof(test_cmd_w_to_w[0]); i++)
2633 hdata = DdeClientTransaction((LPBYTE)test_cmd_w_to_w[i],
2634 (lstrlenW(test_cmd_w_to_w[i]) + 1) * sizeof(WCHAR),
2635 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2636 ok(hdata != NULL, "DdeClientTransaction failed\n");
2637 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2638 err = DdeGetLastError(client_pid);
2639 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2642 DdeFreeStringHandle(client_pid, topic);
2643 ret = DdeDisconnect(hconv);
2644 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2646 ret = DdeUninitialize(client_pid);
2647 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2651 static void test_end_to_end_server(HANDLE hproc, HANDLE hthread, BOOL type_a)
2658 static CHAR test_service[] = "TestDDEService";
2660 trace("start end to end server %s\n", type_a ? "ASCII" : "UNICODE");
2664 res = DdeInitializeA(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2666 res = DdeInitializeW(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2667 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
2669 server = DdeCreateStringHandleA(server_pid, test_service, CP_WINANSI);
2670 ok(server != NULL, "Expected non-NULL string handle\n");
2672 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
2673 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
2674 ResumeThread( hthread );
2677 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
2679 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2682 ret = DdeUninitialize(server_pid);
2683 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2684 GetExitCodeProcess( hproc, &res );
2685 ok( !res, "client failed with %u error(s)\n", res );
2692 char buffer[MAX_PATH];
2693 STARTUPINFO startup;
2694 PROCESS_INFORMATION proc;
2695 DWORD dde_inst = 0xdeadbeef;
2697 argc = winetest_get_mainargs(&argv);
2700 if (!lstrcmpA(argv[2], "ddeml"))
2701 test_ddeml_client();
2702 else if (!lstrcmpA(argv[2], "msg"))
2704 else if (!lstrcmpA(argv[2], "enda"))
2705 test_end_to_end_client(TRUE);
2706 else if (!lstrcmpA(argv[2], "endw"))
2707 test_end_to_end_client(FALSE);
2712 test_initialisation();
2714 SetLastError(0xdeadbeef);
2715 DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2716 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2718 win_skip("Skipping tests on win9x because of brokenness\n");
2722 ZeroMemory(&startup, sizeof(STARTUPINFO));
2723 sprintf(buffer, "%s dde ddeml", argv[0]);
2724 startup.cb = sizeof(startup);
2725 startup.dwFlags = STARTF_USESHOWWINDOW;
2726 startup.wShowWindow = SW_SHOWNORMAL;
2728 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2729 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2731 test_msg_server(proc.hProcess, proc.hThread);
2733 sprintf(buffer, "%s dde msg", argv[0]);
2734 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2735 0, NULL, NULL, &startup, &proc);
2737 test_ddeml_server(proc.hProcess);
2739 /* Test the combinations of A and W interfaces with A and W data
2740 end to end to ensure that data conversions are accurate */
2741 sprintf(buffer, "%s dde enda", argv[0]);
2742 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2743 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2745 test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
2747 /* Don't bother testing W interfaces on Win9x/WinMe */
2748 SetLastError(0xdeadbeef);
2749 lstrcmpW(NULL, NULL);
2750 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2752 win_skip("Skipping W-interface tests\n");
2756 sprintf(buffer, "%s dde endw", argv[0]);
2757 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2758 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2760 test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
2762 sprintf(buffer, "%s dde enda", argv[0]);
2763 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2764 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2766 test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
2768 sprintf(buffer, "%s dde endw", argv[0]);
2769 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2770 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2772 test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
2774 test_dde_aw_transaction( FALSE, TRUE );
2775 test_dde_aw_transaction( TRUE, FALSE );
2776 test_dde_aw_transaction( TRUE, TRUE );
2777 test_dde_aw_transaction( FALSE, FALSE );
2779 test_dde_aw_transaction( FALSE, TRUE );
2780 test_dde_aw_transaction( TRUE, FALSE );
2781 test_dde_aw_transaction( TRUE, TRUE );
2783 test_dde_aw_transaction( FALSE, FALSE );
2785 test_DdeCreateDataHandle();
2786 test_DdeCreateStringHandle();
2787 test_FreeDDElParam();
2788 test_PackDDElParam();
2789 test_UnpackDDElParam();