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_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
40 static WNDPROC old_dde_client_wndproc;
42 static const DWORD default_timeout = 200;
44 static void flush_events(void)
47 int diff = default_timeout;
49 DWORD time = GetTickCount() + diff;
53 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
54 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
55 diff = time - GetTickCount();
60 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
64 memset(&wcA, 0, sizeof(wcA));
65 wcA.lpfnWndProc = wndproc;
66 wcA.lpszClassName = name;
67 wcA.hInstance = GetModuleHandleA(0);
68 assert(RegisterClassA(&wcA));
70 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
71 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
72 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
76 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
79 char str[MAX_PATH], *ptr;
85 static int msg_index = 0;
86 static HWND client = 0;
87 static BOOL executed = FALSE;
89 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
90 return DefWindowProcA(hwnd, msg, wparam, lparam);
98 client = (HWND)wparam;
99 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
101 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
102 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
104 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
105 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
107 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
114 ok((msg_index >= 2 && msg_index <= 4) ||
115 (msg_index >= 7 && msg_index <= 8),
116 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
117 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
118 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
120 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
122 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
124 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
129 lstrcpyA(str, "command executed\r\n");
131 lstrcpyA(str, "command not executed\r\n");
134 lstrcpyA(str, "requested data\r\n");
136 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
137 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
138 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
140 data = GlobalLock(hglobal);
141 ZeroMemory(data, size);
143 /* setting fResponse to FALSE at this point destroys
144 * the internal messaging state of native dde
146 data->fResponse = TRUE;
149 data->fRelease = TRUE;
150 else if (msg_index == 3)
151 data->fAckReq = TRUE;
153 data->cfFormat = CF_TEXT;
154 lstrcpyA((LPSTR)data->Value, str);
155 GlobalUnlock(hglobal);
157 lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
158 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
165 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
166 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
168 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
170 GlobalGetAtomNameA(hi, str, MAX_PATH);
171 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
173 poke = GlobalLock((HGLOBAL)lo);
174 ok(poke != NULL, "Expected non-NULL poke\n");
175 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
176 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
177 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
178 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
181 ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
182 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
184 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
185 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
187 GlobalUnlock((HGLOBAL)lo);
189 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
190 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
197 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
198 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
200 ptr = GlobalLock((HGLOBAL)lparam);
201 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
202 GlobalUnlock((HGLOBAL)lparam);
206 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
207 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
212 case WM_DDE_TERMINATE:
214 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
215 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
216 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
218 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
224 ok(FALSE, "Unhandled msg: %08x\n", msg);
227 return DefWindowProcA(hwnd, msg, wparam, lparam);
230 static void test_msg_server(HANDLE hproc)
236 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
238 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
240 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
244 GetExitCodeProcess( hproc, &res );
245 ok( !res, "client failed with %u error(s)\n", res );
248 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
249 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
250 ULONG_PTR dwData1, ULONG_PTR dwData2)
252 ok(FALSE, "Unhandled msg: %08x\n", uType);
256 static void test_ddeml_client(void)
263 HSZ server, topic, item;
268 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
269 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
271 /* FIXME: make these atoms global and check them in the server */
273 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
274 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
276 DdeGetLastError(client_pid);
277 conversation = DdeConnect(client_pid, server, topic, NULL);
278 ok(conversation != NULL, "Expected non-NULL conversation\n");
279 ret = DdeGetLastError(client_pid);
280 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
282 DdeFreeStringHandle(client_pid, server);
284 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
286 /* XTYP_REQUEST, fRelease = TRUE */
288 DdeGetLastError(client_pid);
289 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
290 ret = DdeGetLastError(client_pid);
291 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
294 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", res);
297 ok(FALSE, "hdata is NULL\n");
300 str = (LPSTR)DdeAccessData(hdata, &size);
301 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
302 ok(size == 19, "Expected 19, got %d\n", size);
304 ret = DdeUnaccessData(hdata);
305 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
308 /* XTYP_REQUEST, fAckReq = TRUE */
310 DdeGetLastError(client_pid);
311 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
312 ret = DdeGetLastError(client_pid);
315 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
316 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
319 ok(FALSE, "hdata is NULL\n");
322 str = (LPSTR)DdeAccessData(hdata, &size);
323 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
324 ok(size == 19, "Expected 19, got %d\n", size);
326 ret = DdeUnaccessData(hdata);
327 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
330 /* XTYP_REQUEST, all params normal */
332 DdeGetLastError(client_pid);
333 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
334 ret = DdeGetLastError(client_pid);
335 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
338 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
341 ok(FALSE, "hdata is NULL\n");
344 str = (LPSTR)DdeAccessData(hdata, &size);
345 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
346 ok(size == 19, "Expected 19, got %d\n", size);
348 ret = DdeUnaccessData(hdata);
349 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
352 /* XTYP_REQUEST, no item */
354 DdeGetLastError(client_pid);
355 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
356 ret = DdeGetLastError(client_pid);
357 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
358 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
359 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
361 DdeFreeStringHandle(client_pid, item);
363 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
365 lstrcpyA(buffer, "poke data\r\n");
366 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
367 0, item, CF_TEXT, 0);
368 ok(hdata != NULL, "Expected non-NULL hdata\n");
370 /* XTYP_POKE, no item */
372 DdeGetLastError(client_pid);
373 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
374 ret = DdeGetLastError(client_pid);
375 ok(op == NULL, "Expected NULL, got %p\n", op);
376 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
377 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
379 /* XTYP_POKE, no data */
381 DdeGetLastError(client_pid);
382 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
383 ret = DdeGetLastError(client_pid);
384 ok(op == NULL, "Expected NULL, got %p\n", op);
385 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
386 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
388 /* XTYP_POKE, wrong size */
390 DdeGetLastError(client_pid);
391 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
392 ret = DdeGetLastError(client_pid);
393 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
394 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
395 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
397 /* XTYP_POKE, correct params */
399 DdeGetLastError(client_pid);
400 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
401 ret = DdeGetLastError(client_pid);
402 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
403 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
404 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
406 DdeFreeDataHandle(hdata);
408 lstrcpyA(buffer, "[Command(Var)]");
409 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
410 0, NULL, CF_TEXT, 0);
411 ok(hdata != NULL, "Expected non-NULL hdata\n");
413 /* XTYP_EXECUTE, correct params */
415 DdeGetLastError(client_pid);
416 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
417 ret = DdeGetLastError(client_pid);
418 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
419 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
420 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
422 /* XTYP_EXECUTE, no data */
424 DdeGetLastError(client_pid);
425 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
426 ret = DdeGetLastError(client_pid);
427 ok(op == NULL, "Expected NULL, got %p\n", op);
428 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
431 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
434 /* XTYP_EXECUTE, no data, -1 size */
436 DdeGetLastError(client_pid);
437 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
438 ret = DdeGetLastError(client_pid);
439 ok(op == NULL, "Expected NULL, got %p\n", op);
440 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
443 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
446 DdeFreeStringHandle(client_pid, topic);
447 DdeFreeDataHandle(hdata);
449 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
451 /* verify the execute */
453 DdeGetLastError(client_pid);
454 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
455 ret = DdeGetLastError(client_pid);
456 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
459 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
462 ok(FALSE, "hdata is NULL\n");
465 str = (LPSTR)DdeAccessData(hdata, &size);
466 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
467 ok(size == 21, "Expected 21, got %d\n", size);
469 ret = DdeUnaccessData(hdata);
470 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
473 /* invalid transactions */
475 DdeGetLastError(client_pid);
476 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
477 ret = DdeGetLastError(client_pid);
478 ok(op == NULL, "Expected NULL, got %p\n", op);
479 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
480 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
483 DdeGetLastError(client_pid);
484 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, default_timeout, &res);
485 ret = DdeGetLastError(client_pid);
486 ok(op == NULL, "Expected NULL, got %p\n", op);
487 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
488 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
491 DdeGetLastError(client_pid);
492 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, default_timeout, &res);
493 ret = DdeGetLastError(client_pid);
494 ok(op == NULL, "Expected NULL, got %p\n", op);
495 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
496 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
499 DdeGetLastError(client_pid);
500 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, default_timeout, &res);
501 ret = DdeGetLastError(client_pid);
502 ok(op == NULL, "Expected NULL, got %p\n", op);
503 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
504 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
507 DdeGetLastError(client_pid);
508 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, default_timeout, &res);
509 ret = DdeGetLastError(client_pid);
510 ok(op == NULL, "Expected NULL, got %p\n", op);
511 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
512 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
515 DdeGetLastError(client_pid);
516 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, default_timeout, &res);
517 ret = DdeGetLastError(client_pid);
518 ok(op == NULL, "Expected NULL, got %p\n", op);
519 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
520 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
523 DdeGetLastError(client_pid);
524 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, default_timeout, &res);
525 ret = DdeGetLastError(client_pid);
526 ok(op == NULL, "Expected NULL, got %p\n", op);
527 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
528 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
531 DdeGetLastError(client_pid);
532 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, default_timeout, &res);
533 ret = DdeGetLastError(client_pid);
534 ok(op == NULL, "Expected NULL, got %p\n", op);
535 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
536 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
539 DdeGetLastError(client_pid);
540 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
541 ret = DdeGetLastError(client_pid);
542 ok(op == NULL, "Expected NULL, got %p\n", op);
543 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
544 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
547 DdeGetLastError(client_pid);
548 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
549 ret = DdeGetLastError(client_pid);
550 ok(op == NULL, "Expected NULL, got %p\n", op);
551 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
552 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
554 DdeFreeStringHandle(client_pid, item);
556 ret = DdeDisconnect(conversation);
557 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
559 ret = DdeUninitialize(client_pid);
560 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
563 static DWORD server_pid;
565 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
566 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
567 ULONG_PTR dwData1, ULONG_PTR dwData2)
569 char str[MAX_PATH], *ptr;
573 static int msg_index = 0;
574 static HCONV conversation = 0;
582 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
583 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
584 ok(hconv == 0, "Expected 0, got %p\n", hconv);
585 ok(hdata == 0, "Expected 0, got %p\n", hdata);
586 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
587 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
589 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
590 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
591 ok(size == 13, "Expected 13, got %d\n", size);
593 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
594 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
595 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
596 ok(size == 25, "Expected 25, got %d\n", size);
598 return (HDDEDATA)TRUE;
603 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
604 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
605 ok(hconv == 0, "Expected 0, got %p\n", hconv);
606 ok(hdata == 0, "Expected 0, got %p\n", hdata);
607 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
608 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
610 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
611 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
612 ok(size == 12, "Expected 12, got %d\n", size);
614 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
615 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
616 ok(size == 13, "Expected 13, got %d\n", size);
618 return (HDDEDATA)TRUE;
621 case XTYP_CONNECT_CONFIRM:
623 conversation = hconv;
625 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
626 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
627 ok(hconv != NULL, "Expected non-NULL hconv\n");
628 ok(hdata == 0, "Expected 0, got %p\n", hdata);
629 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
630 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
632 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
633 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
634 ok(size == 12, "Expected 12, got %d\n", size);
636 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
637 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
638 ok(size == 13, "Expected 13, got %d\n", size);
640 return (HDDEDATA)TRUE;
645 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
646 "Expected 4, 5 or 6, got %d\n", msg_index);
647 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
648 ok(hdata == 0, "Expected 0, got %p\n", hdata);
649 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
650 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
653 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
655 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
657 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
658 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
659 ok(size == 12, "Expected 12, got %d\n", size);
661 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
667 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
668 ok(size == 1, "Expected 1, got %d\n", size);
671 else if (msg_index == 6)
673 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
674 ok(size == 7, "Expected 7, got %d\n", size);
679 lstrcpyA(str, "requested data\r\n");
680 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
681 0, hsz2, CF_TEXT, 0);
689 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
690 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
691 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
692 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
693 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
695 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
696 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
697 ok(size == 12, "Expected 12, got %d\n", size);
699 ptr = (LPSTR)DdeAccessData(hdata, &size);
700 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
703 ok(size == 14, "Expected 14, got %d\n", size);
705 DdeUnaccessData(hdata);
707 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
712 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
713 ok(size == 1, "Expected 1, got %d\n", size);
718 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
719 ok(size == 4, "Expected 4, got %d\n", size);
722 return (HDDEDATA)DDE_FACK;
727 ok(msg_index == 9 || msg_index == 10, "Expected 9 or 10, got %d\n", msg_index);
728 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
729 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
730 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
731 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
732 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
734 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
735 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
736 ok(size == 12, "Expected 12, got %d\n", size);
738 ptr = (LPSTR)DdeAccessData(hdata, &size);
742 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
743 ok(size == 15, "Expected 15, got %d\n", size);
744 ret = (HDDEDATA)DDE_FACK;
748 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
749 ok(size == 18, "Expected 18, got %d\n", size);
750 ret = (HDDEDATA)DDE_FNOTPROCESSED;
753 DdeUnaccessData(hdata);
758 case XTYP_DISCONNECT:
760 ok(msg_index == 11, "Expected 11, got %d\n", msg_index);
761 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
762 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
763 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
764 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
765 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
766 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
772 ok(FALSE, "Unhandled msg: %08x\n", uType);
778 static void test_ddeml_server(HANDLE hproc)
786 /* set up DDE server */
788 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
789 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
791 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
792 ok(server != NULL, "Expected non-NULL string handle\n");
794 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
795 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
797 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
799 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
801 ret = DdeUninitialize(server_pid);
802 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
803 GetExitCodeProcess( hproc, &res );
804 ok( !res, "client failed with %u error(s)\n", res );
807 static HWND client_hwnd, server_hwnd;
808 static ATOM server, topic, item;
809 static HGLOBAL execute_hglobal;
811 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
820 static int msg_index = 0;
822 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
823 return DefWindowProcA(hwnd, msg, wparam, lparam);
829 case WM_DDE_INITIATE:
831 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
832 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
834 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
835 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
836 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
837 ok(size == 13, "Expected 13, got %d\n", size);
839 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
840 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
841 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
842 ok(size == 12, "Expected 12, got %d\n", size);
849 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 10),
850 "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index);
854 server_hwnd = (HWND)wparam;
855 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
857 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
858 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
859 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
860 ok(size == 13, "Expected 13, got %d\n", size);
862 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
863 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
864 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
865 ok(size == 12, "Expected 12, got %d\n", size);
867 else if (msg_index == 9 || msg_index == 10)
869 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
871 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
874 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
875 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
876 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
878 ok(hi == (UINT_PTR)execute_hglobal, "Execpted execute hglobal, got %08lx\n", hi);
879 ptr = GlobalLock((HGLOBAL)hi);
883 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
884 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
888 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
889 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
892 GlobalUnlock((HGLOBAL)hi);
896 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
898 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
901 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
902 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
903 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
906 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
909 if (msg_index == 6) todo_wine
910 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
913 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
916 ok(hi == item, "Expected item atom, got %08lx\n", hi);
917 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
918 ok(size == 7, "Expected 7, got %d\n", size);
920 else if (msg_index == 4 || msg_index == 7)
922 ok(hi == 0, "Expected 0, got %08lx\n", hi);
923 ok(size == 0, "Expected empty string, got %d\n", size);
927 ok(hi == item, "Expected item atom, got %08lx\n", hi);
928 if (msg_index == 6) todo_wine
930 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
931 ok(size == 4, "Expected 4, got %d\n", size);
941 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
942 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
944 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
946 data = GlobalLock((HGLOBAL)lo);
947 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
948 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
951 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
953 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
954 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
955 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
956 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
957 GlobalUnlock((HGLOBAL)lo);
959 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
960 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
961 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
962 ok(size == 7, "Expected 7, got %d\n", size);
964 GlobalFree((HGLOBAL)lo);
965 GlobalDeleteAtom(hi);
971 ok(FALSE, "Unhandled msg: %08x\n", msg);
974 return DefWindowProcA(hwnd, msg, wparam, lparam);
977 static HGLOBAL create_poke()
983 size = sizeof(DDEPOKE) + lstrlenA("poke data\r\n") + 1;
984 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
985 ok(hglobal != 0, "Expected non-NULL hglobal\n");
987 poke = GlobalLock(hglobal);
989 poke->fRelease = TRUE;
990 poke->fReserved = TRUE;
991 poke->cfFormat = CF_TEXT;
992 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
993 GlobalUnlock(hglobal);
998 static HGLOBAL create_execute(LPCSTR command)
1003 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1004 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1006 ptr = GlobalLock(hglobal);
1007 lstrcpyA(ptr, command);
1008 GlobalUnlock(hglobal);
1013 static void test_msg_client()
1018 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1020 server = GlobalAddAtomA("TestDDEServer");
1021 ok(server != 0, "Expected non-NULL server\n");
1023 topic = GlobalAddAtomA("TestDDETopic");
1024 ok(topic != 0, "Expected non-NULL topic\n");
1026 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1028 GlobalDeleteAtom(server);
1029 GlobalDeleteAtom(topic);
1033 item = GlobalAddAtom("request");
1034 ok(item != 0, "Expected non-NULL item\n");
1036 /* WM_DDE_REQUEST, bad clipboard format */
1037 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1038 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1042 /* WM_DDE_REQUEST, no item */
1043 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1044 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1048 /* WM_DDE_REQUEST, no client hwnd */
1049 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1050 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1054 /* WM_DDE_REQUEST, correct params */
1055 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1056 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1060 GlobalDeleteAtom(item);
1061 item = GlobalAddAtomA("poke");
1062 ok(item != 0, "Expected non-NULL item\n");
1064 hglobal = create_poke();
1066 /* WM_DDE_POKE, no ddepoke */
1067 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1068 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1072 /* WM_DDE_POKE, no item */
1073 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1074 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1078 hglobal = create_poke();
1080 /* WM_DDE_POKE, no client hwnd */
1081 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1082 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1086 /* WM_DDE_POKE, all params correct */
1087 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1088 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1092 execute_hglobal = create_execute("[Command(Var)]");
1094 /* WM_DDE_EXECUTE, no lparam */
1095 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1099 /* WM_DDE_EXECUTE, no hglobal */
1100 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1101 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1105 /* WM_DDE_EXECUTE, no client hwnd */
1106 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1107 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1111 /* WM_DDE_EXECUTE, all params correct */
1112 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1113 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1117 GlobalFree(execute_hglobal);
1118 execute_hglobal = create_execute("[BadCommand(Var)]");
1120 /* WM_DDE_EXECUTE that will get rejected */
1121 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1122 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1126 DestroyWindow(client_hwnd);
1129 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1133 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1138 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1139 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1145 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1148 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1150 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1154 case WM_DDE_INITIATE:
1156 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1158 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
1160 if (LOWORD(lparam) == aService)
1162 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
1163 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
1164 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1165 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
1168 GlobalDeleteAtom(aService);
1172 case WM_DDE_EXECUTE:
1179 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1181 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1182 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1184 ack.bAppReturnCode = 0;
1188 cmd = GlobalLock((HGLOBAL)hi);
1190 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
1192 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1193 /* We have to send a negative acknowledge even if we don't
1194 * accept the command, otherwise Windows goes mad and next time
1195 * we send an acknowledge DDEML drops the connection.
1196 * Not sure how to call it: a bug or a feature.
1202 GlobalUnlock((HGLOBAL)hi);
1204 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1206 status = *((WORD *)&ack);
1207 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1209 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1213 case WM_DDE_TERMINATE:
1218 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1220 ack.bAppReturnCode = 0;
1225 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1227 status = *((WORD *)&ack);
1228 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1230 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1238 return DefWindowProcW(hwnd, msg, wparam, lparam);
1241 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1243 return DefWindowProcA(hwnd, msg, wparam, lparam);
1246 static BOOL create_dde_windows(HWND *client, HWND *server)
1250 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1251 static const char client_class_name[] = "dde_client_window";
1253 memset(&wcW, 0, sizeof(wcW));
1254 wcW.lpfnWndProc = dde_server_wndprocW;
1255 wcW.lpszClassName = server_class_name;
1256 wcW.hInstance = GetModuleHandleA(0);
1257 if (!RegisterClassW(&wcW)) return FALSE;
1259 memset(&wcA, 0, sizeof(wcA));
1260 wcA.lpfnWndProc = dde_client_wndproc;
1261 wcA.lpszClassName = client_class_name;
1262 wcA.hInstance = GetModuleHandleA(0);
1263 assert(RegisterClassA(&wcA));
1265 *server = CreateWindowExW(0, server_class_name, NULL,
1267 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1268 GetDesktopWindow(), 0,
1269 GetModuleHandleA(0), NULL);
1272 *client = CreateWindowExA(0, client_class_name, NULL,
1274 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1275 GetDesktopWindow(), 0,
1276 GetModuleHandleA(0), NULL);
1279 trace("server hwnd %p, client hwnd %p\n", *server, *client);
1281 ok(IsWindowUnicode(*server), "server has to be a unicode window\n");
1282 ok(!IsWindowUnicode(*client), "client has to be an ANSI window\n");
1287 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1288 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1289 ULONG_PTR dwData1, ULONG_PTR dwData2)
1291 static const char * const cmd_type[15] = {
1292 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1293 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1294 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1295 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1297 const char *cmd_name;
1299 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1300 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1302 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1303 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1307 static void test_dde_aw_transaction(void)
1310 DWORD dde_inst, ret, err;
1312 HWND hwnd_client, hwnd_server;
1315 static char test_cmd[] = "test dde command";
1317 /* server: unicode, client: ansi */
1318 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
1321 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1322 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
1323 ret, DdeGetLastError(dde_inst));
1325 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1327 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1328 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1329 err = DdeGetLastError(dde_inst);
1330 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1332 info.cb = sizeof(info);
1333 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1334 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1335 /* should be CP_WINANSI since we used DdeInitializeA */
1336 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1337 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1339 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1341 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1342 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1343 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1345 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
1347 trace("sending test client transaction command\n");
1349 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1350 ok(!hdata, "DdeClientTransaction succeeded\n");
1351 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1352 err = DdeGetLastError(dde_inst);
1353 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1355 trace("sending ANSI client transaction command\n");
1357 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1358 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1359 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1361 err = DdeGetLastError(dde_inst);
1362 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1364 trace("sending unicode client transaction command\n");
1366 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1367 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1368 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1369 err = DdeGetLastError(dde_inst);
1370 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1372 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1374 info.cb = sizeof(info);
1375 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1376 ok(!ret, "DdeQueryConvInfo should fail\n");
1377 err = DdeGetLastError(dde_inst);
1379 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1382 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1384 /* This call hangs on win2k SP4 and XP SP1.
1385 DdeUninitialize(dde_inst);*/
1387 DestroyWindow(hwnd_client);
1388 DestroyWindow(hwnd_server);
1391 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1393 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1400 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1401 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1402 DdeGetLastError(dde_inst));
1404 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1405 if (codepage == CP_WINANSI)
1406 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1408 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1410 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1411 if (codepage == CP_WINANSI)
1413 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1414 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1418 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1419 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1422 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1423 if (codepage == CP_WINANSI)
1425 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1426 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1430 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1431 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1434 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1435 if (codepage == CP_WINANSI)
1437 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1438 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1442 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1443 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1446 if (codepage == CP_WINANSI)
1448 atom = FindAtomA((LPSTR)dde_string);
1449 ok(atom != 0, "Expected a valid atom\n");
1451 SetLastError(0xdeadbeef);
1452 atom = GlobalFindAtomA((LPSTR)dde_string);
1453 ok(atom == 0, "Expected 0, got %d\n", atom);
1454 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1455 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1459 atom = FindAtomW(dde_string);
1460 ok(atom != 0, "Expected a valid atom\n");
1462 SetLastError(0xdeadbeef);
1463 atom = GlobalFindAtomW(dde_string);
1464 ok(atom == 0, "Expected 0, got %d\n", atom);
1465 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1466 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1469 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1472 static void test_DdeCreateDataHandle(void)
1483 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1484 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1486 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1487 ok(item != NULL, "Expected non-NULL hsz\n");
1489 /* invalid instance id */
1490 DdeGetLastError(dde_inst);
1491 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1492 err = DdeGetLastError(dde_inst);
1495 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1496 ok(err == DMLERR_INVALIDPARAMETER,
1497 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1501 DdeGetLastError(dde_inst);
1502 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1503 err = DdeGetLastError(dde_inst);
1506 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1507 ok(err == DMLERR_INVALIDPARAMETER,
1508 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1512 DdeGetLastError(dde_inst);
1513 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1514 err = DdeGetLastError(dde_inst);
1515 ok(hdata != NULL, "Expected non-NULL hdata\n");
1516 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1518 ptr = GlobalLock(hdata);
1521 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1524 ptr = DdeAccessData(hdata, &size);
1525 ok(ptr != NULL, "Expected non-NULL ptr\n");
1526 ok(size == 260, "Expected 260, got %d\n", size);
1528 ret = DdeUnaccessData(hdata);
1529 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1531 ret = DdeFreeDataHandle(hdata);
1532 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1535 DdeGetLastError(dde_inst);
1536 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1537 err = DdeGetLastError(dde_inst);
1538 ok(hdata != NULL, "Expected non-NULL hdata\n");
1539 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1541 ptr = GlobalLock(hdata);
1544 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1547 ptr = DdeAccessData(hdata, &size);
1548 ok(ptr != NULL, "Expected non-NULL ptr\n");
1549 ok(size == 0, "Expected 0, got %d\n", size);
1551 ret = DdeUnaccessData(hdata);
1552 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1554 ret = DdeFreeDataHandle(hdata);
1555 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1557 /* cbOff is non-zero */
1558 DdeGetLastError(dde_inst);
1559 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1560 err = DdeGetLastError(dde_inst);
1561 ok(hdata != NULL, "Expected non-NULL hdata\n");
1562 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1564 ptr = GlobalLock(hdata);
1567 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1570 ptr = DdeAccessData(hdata, &size);
1571 ok(ptr != NULL, "Expected non-NULL ptr\n");
1572 ok(size == 262, "Expected 262, got %d\n", size);
1575 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1578 ret = DdeUnaccessData(hdata);
1579 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1581 ret = DdeFreeDataHandle(hdata);
1582 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1585 DdeGetLastError(dde_inst);
1586 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1587 err = DdeGetLastError(dde_inst);
1588 ok(hdata != NULL, "Expected non-NULL hdata\n");
1589 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1591 ptr = GlobalLock(hdata);
1594 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1597 ptr = DdeAccessData(hdata, &size);
1598 ok(ptr != NULL, "Expected non-NULL ptr\n");
1599 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1600 ok(size == 260, "Expected 260, got %d\n", size);
1602 ret = DdeUnaccessData(hdata);
1603 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1605 ret = DdeFreeDataHandle(hdata);
1606 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1609 DdeGetLastError(dde_inst);
1610 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1611 err = DdeGetLastError(dde_inst);
1612 ok(hdata != NULL, "Expected non-NULL hdata\n");
1613 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1615 ptr = GlobalLock(hdata);
1618 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1621 ptr = DdeAccessData(hdata, &size);
1622 ok(ptr != NULL, "Expected non-NULL ptr\n");
1623 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1624 ok(size == 260, "Expected 260, got %d\n", size);
1626 ret = DdeUnaccessData(hdata);
1627 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1629 ret = DdeFreeDataHandle(hdata);
1630 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1632 /* invalid clipboard format */
1633 DdeGetLastError(dde_inst);
1634 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
1635 err = DdeGetLastError(dde_inst);
1636 ok(hdata != NULL, "Expected non-NULL hdata\n");
1637 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1639 ptr = GlobalLock(hdata);
1642 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1645 ptr = DdeAccessData(hdata, &size);
1646 ok(ptr != NULL, "Expected non-NULL ptr\n");
1647 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1648 ok(size == 260, "Expected 260, got %d\n", size);
1650 ret = DdeUnaccessData(hdata);
1651 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1653 ret = DdeFreeDataHandle(hdata);
1654 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1656 ret = DdeUninitialize(dde_inst);
1657 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1660 static void test_DdeCreateStringHandle(void)
1662 DWORD dde_inst, ret;
1664 dde_inst = 0xdeadbeef;
1665 SetLastError(0xdeadbeef);
1666 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1667 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1669 trace("Skipping the DDE test on a Win9x platform\n");
1673 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
1674 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
1677 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1678 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
1679 ret, DdeGetLastError(dde_inst));
1681 test_DdeCreateStringHandleW(dde_inst, 0);
1682 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
1683 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
1685 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
1688 static void test_FreeDDElParam(void)
1690 HGLOBAL val, hglobal;
1693 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
1694 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1696 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1697 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
1698 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1699 val = GlobalFree(hglobal);
1700 ok(val == NULL, "Expected NULL, got %p\n", val);
1702 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1703 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
1704 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1705 val = GlobalFree(hglobal);
1706 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1707 ok(GetLastError() == ERROR_INVALID_HANDLE,
1708 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1710 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1711 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
1712 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1713 val = GlobalFree(hglobal);
1714 ok(val == NULL, "Expected NULL, got %p\n", val);
1716 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1717 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
1718 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1719 val = GlobalFree(hglobal);
1720 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1721 ok(GetLastError() == ERROR_INVALID_HANDLE,
1722 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1724 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1725 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
1726 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1727 val = GlobalFree(hglobal);
1728 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1729 ok(GetLastError() == ERROR_INVALID_HANDLE,
1730 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1732 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1733 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
1734 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1735 val = GlobalFree(hglobal);
1736 ok(val == NULL, "Expected NULL, got %p\n", val);
1738 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1739 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1740 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1741 val = GlobalFree(hglobal);
1742 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1743 ok(GetLastError() == ERROR_INVALID_HANDLE,
1744 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1746 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1747 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1748 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1749 val = GlobalFree(hglobal);
1750 ok(val == NULL, "Expected NULL, got %p\n", val);
1753 static void test_PackDDElParam(void)
1755 UINT_PTR lo, hi, *ptr;
1760 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1761 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1762 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1763 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1764 ok(GetLastError() == ERROR_INVALID_HANDLE,
1765 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1768 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1769 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1770 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1771 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1773 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1774 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1776 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1777 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1778 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1779 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1780 ok(GetLastError() == ERROR_INVALID_HANDLE,
1781 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1784 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1785 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1786 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1787 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1789 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1790 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1792 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1793 ptr = GlobalLock((HGLOBAL)lparam);
1794 ok(ptr != NULL, "Expected non-NULL ptr\n");
1795 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1796 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1798 ret = GlobalUnlock((HGLOBAL)lparam);
1799 ok(ret == 1, "Expected 1, got %d\n", ret);
1802 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1803 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1804 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1805 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1807 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1808 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1810 hglobal = GlobalFree((HGLOBAL)lparam);
1811 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1812 ok(GetLastError() == ERROR_INVALID_HANDLE,
1813 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1815 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1816 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1817 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1818 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1819 ok(GetLastError() == ERROR_INVALID_HANDLE,
1820 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1823 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1824 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1825 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1826 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1828 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1829 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1831 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1832 ptr = GlobalLock((HGLOBAL)lparam);
1833 ok(ptr != NULL, "Expected non-NULL ptr\n");
1834 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1835 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1837 ret = GlobalUnlock((HGLOBAL)lparam);
1838 ok(ret == 1, "Expected 1, got %d\n", ret);
1841 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1842 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1843 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1844 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1846 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1847 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1849 hglobal = GlobalFree((HGLOBAL)lparam);
1850 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1851 ok(GetLastError() == ERROR_INVALID_HANDLE,
1852 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1854 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1855 ptr = GlobalLock((HGLOBAL)lparam);
1856 ok(ptr != NULL, "Expected non-NULL ptr\n");
1857 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1858 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1860 ret = GlobalUnlock((HGLOBAL)lparam);
1861 ok(ret == 1, "Expected 1, got %d\n", ret);
1864 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1865 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1866 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1867 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1869 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1870 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1872 hglobal = GlobalFree((HGLOBAL)lparam);
1873 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1874 ok(GetLastError() == ERROR_INVALID_HANDLE,
1875 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1877 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1878 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1879 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1880 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1881 ok(GetLastError() == ERROR_INVALID_HANDLE,
1882 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1885 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1886 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1887 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1888 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1890 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1891 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1893 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1894 ptr = GlobalLock((HGLOBAL)lparam);
1895 ok(ptr != NULL, "Expected non-NULL ptr\n");
1896 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1897 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1899 ret = GlobalUnlock((HGLOBAL)lparam);
1900 ok(ret == 1, "Expected 1, got %d\n", ret);
1903 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1904 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1905 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1906 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1908 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1909 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1911 hglobal = GlobalFree((HGLOBAL)lparam);
1912 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1913 ok(GetLastError() == ERROR_INVALID_HANDLE,
1914 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1916 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1917 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1918 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1919 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1920 ok(GetLastError() == ERROR_INVALID_HANDLE,
1921 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1924 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1925 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1926 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1927 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1929 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1930 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1933 static void test_UnpackDDElParam(void)
1935 UINT_PTR lo, hi, *ptr;
1942 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1943 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1944 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1945 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1950 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1951 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1952 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1953 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1958 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1959 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1960 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1961 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1965 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1966 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1967 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1968 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1972 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1973 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1974 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1975 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1979 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1980 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1981 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1982 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1986 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1987 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1988 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1989 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1991 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1992 ptr = GlobalLock(hglobal);
1993 ptr[0] = 0xcafebabe;
1994 ptr[1] = 0xdeadbeef;
1995 GlobalUnlock(hglobal);
1999 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2000 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2001 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2002 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2006 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2007 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2008 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2009 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2013 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
2014 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2015 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2016 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2020 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2021 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2022 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2023 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2027 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
2028 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2029 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2030 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2034 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2035 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2036 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2037 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2041 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2042 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2043 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2044 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2048 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
2049 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2050 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2051 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2055 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2056 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2057 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2058 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2062 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2063 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2064 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2065 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2072 char buffer[MAX_PATH];
2073 STARTUPINFO startup;
2074 PROCESS_INFORMATION proc;
2076 argc = winetest_get_mainargs(&argv);
2079 if (!lstrcmpA(argv[2], "ddeml"))
2080 test_ddeml_client();
2081 else if (!lstrcmpA(argv[2], "msg"))
2087 ZeroMemory(&startup, sizeof(STARTUPINFO));
2088 sprintf(buffer, "%s dde ddeml", argv[0]);
2089 startup.cb = sizeof(startup);
2090 startup.dwFlags = STARTF_USESHOWWINDOW;
2091 startup.wShowWindow = SW_SHOWNORMAL;
2093 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2094 0, NULL, NULL, &startup, &proc);
2096 test_msg_server(proc.hProcess);
2098 sprintf(buffer, "%s dde msg", argv[0]);
2099 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2100 0, NULL, NULL, &startup, &proc);
2102 test_ddeml_server(proc.hProcess);
2104 test_dde_aw_transaction();
2106 test_DdeCreateDataHandle();
2107 test_DdeCreateStringHandle();
2108 test_FreeDDElParam();
2109 test_PackDDElParam();
2110 test_UnpackDDElParam();