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 void flush_events(void)
46 DWORD time = GetTickCount() + diff;
50 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
51 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
52 diff = time - GetTickCount();
56 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
60 memset(&wcA, 0, sizeof(wcA));
61 wcA.lpfnWndProc = wndproc;
62 wcA.lpszClassName = name;
63 wcA.hInstance = GetModuleHandleA(0);
64 assert(RegisterClassA(&wcA));
66 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
67 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
68 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
72 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
75 char str[MAX_PATH], *ptr;
81 static int msg_index = 0;
82 static HWND client = 0;
83 static BOOL executed = FALSE;
85 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
86 return DefWindowProcA(hwnd, msg, wparam, lparam);
94 client = (HWND)wparam;
95 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
97 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
98 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
100 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
101 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
103 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
110 ok((msg_index >= 2 && msg_index <= 4) ||
111 (msg_index >= 7 && msg_index <= 8),
112 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
113 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
114 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
116 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
118 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
120 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
125 lstrcpyA(str, "command executed\r\n");
127 lstrcpyA(str, "command not executed\r\n");
130 lstrcpyA(str, "requested data\r\n");
132 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
133 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
134 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
136 data = GlobalLock(hglobal);
137 ZeroMemory(data, size);
139 /* setting fResponse to FALSE at this point destroys
140 * the internal messaging state of native dde
142 data->fResponse = TRUE;
145 data->fRelease = TRUE;
146 else if (msg_index == 3)
147 data->fAckReq = TRUE;
149 data->cfFormat = CF_TEXT;
150 lstrcpyA((LPSTR)data->Value, str);
151 GlobalUnlock(hglobal);
153 lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
154 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
161 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
162 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
164 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
166 GlobalGetAtomNameA(hi, str, MAX_PATH);
167 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
169 poke = GlobalLock((HGLOBAL)lo);
170 ok(poke != NULL, "Expected non-NULL poke\n");
171 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
174 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
176 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
177 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
180 ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
181 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
183 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
184 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
186 GlobalUnlock((HGLOBAL)lo);
188 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
189 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
196 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
197 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
199 ptr = GlobalLock((HGLOBAL)lparam);
200 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
201 GlobalUnlock((HGLOBAL)lparam);
205 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
206 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
211 case WM_DDE_TERMINATE:
213 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
214 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
215 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
217 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
223 ok(FALSE, "Unhandled msg: %08x\n", msg);
226 return DefWindowProcA(hwnd, msg, wparam, lparam);
229 static void test_msg_server(HANDLE hproc)
234 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
238 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
239 } while (WaitForSingleObject(hproc, 500) == WAIT_TIMEOUT);
244 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
245 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
246 ULONG_PTR dwData1, ULONG_PTR dwData2)
248 ok(FALSE, "Unhandled msg: %08x\n", uType);
252 static void test_ddeml_client(void)
258 HSZ server, topic, item;
263 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
264 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
266 /* FIXME: make these atoms global and check them in the server */
268 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
269 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
271 DdeGetLastError(client_pid);
272 conversation = DdeConnect(client_pid, server, topic, NULL);
273 ok(conversation != NULL, "Expected non-NULL conversation\n");
274 ret = DdeGetLastError(client_pid);
275 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
277 DdeFreeStringHandle(client_pid, server);
279 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
281 /* XTYP_REQUEST, fRelease = TRUE */
283 DdeGetLastError(client_pid);
284 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
285 ret = DdeGetLastError(client_pid);
286 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
287 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
288 ok(ret == DMLERR_DATAACKTIMEOUT, "Expected DMLERR_DATAACKTIMEOUT, got %d\n", ret);
290 /* XTYP_REQUEST, fAckReq = TRUE */
292 DdeGetLastError(client_pid);
293 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
294 ret = DdeGetLastError(client_pid);
295 ok(hdata != NULL, "Expected non-NULL hdata\n");
298 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
299 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
302 str = (LPSTR)DdeAccessData(hdata, &size);
303 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
304 ok(size == 19, "Expected 19, got %d\n", size);
306 ret = DdeUnaccessData(hdata);
307 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
309 /* XTYP_REQUEST, all params normal */
311 DdeGetLastError(client_pid);
312 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
313 ret = DdeGetLastError(client_pid);
316 ok(hdata != NULL, "Expected non-NULL hdata\n");
317 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
318 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
321 str = (LPSTR)DdeAccessData(hdata, &size);
324 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
326 ok(size == 19, "Expected 19, got %d\n", size);
328 ret = DdeUnaccessData(hdata);
329 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
331 /* XTYP_REQUEST, no item */
333 DdeGetLastError(client_pid);
334 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, 500, &res);
335 ret = DdeGetLastError(client_pid);
336 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
337 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
340 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
343 DdeFreeStringHandle(client_pid, item);
345 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
347 lstrcpyA(str, "poke data\r\n");
348 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
349 0, item, CF_TEXT, 0);
350 ok(hdata != NULL, "Expected non-NULL hdata\n");
352 /* XTYP_POKE, no item */
354 DdeGetLastError(client_pid);
355 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, 500, &res);
356 ret = DdeGetLastError(client_pid);
357 ok(op == NULL, "Expected NULL, got %p\n", op);
358 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
361 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
364 /* XTYP_POKE, no data */
366 DdeGetLastError(client_pid);
367 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, 500, &res);
368 ret = DdeGetLastError(client_pid);
369 ok(op == NULL, "Expected NULL, got %p\n", op);
370 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
373 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
376 /* XTYP_POKE, wrong size */
378 DdeGetLastError(client_pid);
379 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, 500, &res);
380 ret = DdeGetLastError(client_pid);
383 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
384 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
386 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
388 /* XTYP_POKE, correct params */
390 DdeGetLastError(client_pid);
391 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, 500, &res);
392 ret = DdeGetLastError(client_pid);
395 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
396 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
397 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
400 DdeFreeDataHandle(hdata);
402 lstrcpyA(str, "[Command(Var)]");
403 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
404 0, NULL, CF_TEXT, 0);
405 ok(hdata != NULL, "Expected non-NULL hdata\n");
407 /* XTYP_EXECUTE, correct params */
409 DdeGetLastError(client_pid);
410 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
411 ret = DdeGetLastError(client_pid);
414 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
415 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
416 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
419 /* XTYP_EXECUTE, no data */
421 DdeGetLastError(client_pid);
422 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
423 ret = DdeGetLastError(client_pid);
424 ok(op == NULL, "Expected NULL, got %p\n", op);
425 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
428 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
431 /* XTYP_EXECUTE, no data, -1 size */
433 DdeGetLastError(client_pid);
434 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
435 ret = DdeGetLastError(client_pid);
436 ok(op == NULL, "Expected NULL, got %p\n", op);
437 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
440 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
443 DdeFreeStringHandle(client_pid, topic);
444 DdeFreeDataHandle(hdata);
446 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
448 /* verify the execute */
450 DdeGetLastError(client_pid);
451 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
452 ret = DdeGetLastError(client_pid);
455 ok(hdata != NULL, "Expected non-NULL hdata\n");
456 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
457 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
460 str = (LPSTR)DdeAccessData(hdata, &size);
463 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
464 ok(size == 21, "Expected 21, got %d\n", size);
467 ret = DdeUnaccessData(hdata);
468 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
470 /* invalid transactions */
473 DdeGetLastError(client_pid);
474 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, 500, &res);
475 ret = DdeGetLastError(client_pid);
476 ok(op == NULL, "Expected NULL, got %p\n", op);
477 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
480 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
484 DdeGetLastError(client_pid);
485 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, 500, &res);
486 ret = DdeGetLastError(client_pid);
487 ok(op == NULL, "Expected NULL, got %p\n", op);
488 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
491 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
495 DdeGetLastError(client_pid);
496 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, 500, &res);
497 ret = DdeGetLastError(client_pid);
498 ok(op == NULL, "Expected NULL, got %p\n", op);
499 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
502 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
506 DdeGetLastError(client_pid);
507 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, 500, &res);
508 ret = DdeGetLastError(client_pid);
509 ok(op == NULL, "Expected NULL, got %p\n", op);
510 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
513 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
517 DdeGetLastError(client_pid);
518 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, 500, &res);
519 ret = DdeGetLastError(client_pid);
520 ok(op == NULL, "Expected NULL, got %p\n", op);
521 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
524 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
528 DdeGetLastError(client_pid);
529 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, 500, &res);
530 ret = DdeGetLastError(client_pid);
531 ok(op == NULL, "Expected NULL, got %p\n", op);
532 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
535 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
539 DdeGetLastError(client_pid);
540 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, 500, &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);
546 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, 500, &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);
557 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
561 DdeGetLastError(client_pid);
562 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, 500, &res);
563 ret = DdeGetLastError(client_pid);
564 ok(op == NULL, "Expected NULL, got %p\n", op);
565 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
568 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
572 DdeGetLastError(client_pid);
573 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, 500, &res);
574 ret = DdeGetLastError(client_pid);
575 ok(op == NULL, "Expected NULL, got %p\n", op);
576 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
579 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
582 DdeFreeStringHandle(client_pid, item);
584 ret = DdeDisconnect(conversation);
587 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
590 ret = DdeUninitialize(client_pid);
591 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
594 static DWORD server_pid;
596 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
597 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
598 ULONG_PTR dwData1, ULONG_PTR dwData2)
600 char str[MAX_PATH], *ptr;
604 static int msg_index = 0;
605 static HCONV conversation = 0;
613 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
614 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
615 ok(hconv == 0, "Expected 0, got %p\n", hconv);
616 ok(hdata == 0, "Expected 0, got %p\n", hdata);
617 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
618 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
620 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
621 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
622 ok(size == 13, "Expected 13, got %d\n", size);
624 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
625 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
626 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
627 ok(size == 25, "Expected 25, got %d\n", size);
629 return (HDDEDATA)TRUE;
634 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
635 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
636 ok(hconv == 0, "Expected 0, got %p\n", hconv);
637 ok(hdata == 0, "Expected 0, got %p\n", hdata);
638 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
639 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
641 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
642 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
643 ok(size == 12, "Expected 12, got %d\n", size);
645 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
646 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
647 ok(size == 13, "Expected 13, got %d\n", size);
649 return (HDDEDATA)TRUE;
652 case XTYP_CONNECT_CONFIRM:
654 conversation = hconv;
656 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
657 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
658 ok(hconv != NULL, "Expected non-NULL hconv\n");
659 ok(hdata == 0, "Expected 0, got %p\n", hdata);
660 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
661 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
663 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
664 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
665 ok(size == 12, "Expected 12, got %d\n", size);
667 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
668 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
669 ok(size == 13, "Expected 13, got %d\n", size);
671 return (HDDEDATA)TRUE;
676 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
677 "Expected 4, 5 or 6, got %d\n", msg_index);
678 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
679 ok(hdata == 0, "Expected 0, got %p\n", hdata);
680 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
681 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
684 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
686 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
688 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
689 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
690 ok(size == 12, "Expected 12, got %d\n", size);
692 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
698 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
699 ok(size == 1, "Expected 1, got %d\n", size);
702 else if (msg_index == 6)
704 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
705 ok(size == 7, "Expected 7, got %d\n", size);
710 lstrcpyA(str, "requested data\r\n");
711 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
712 0, hsz2, CF_TEXT, 0);
720 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
721 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
722 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
723 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
724 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
726 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
727 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
728 ok(size == 12, "Expected 12, got %d\n", size);
730 ptr = (LPSTR)DdeAccessData(hdata, &size);
731 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
734 ok(size == 14, "Expected 14, got %d\n", size);
736 DdeUnaccessData(hdata);
738 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
743 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
744 ok(size == 1, "Expected 1, got %d\n", size);
749 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
750 ok(size == 4, "Expected 4, got %d\n", size);
753 return (HDDEDATA)DDE_FACK;
758 ok(msg_index == 9 || msg_index == 10, "Expected 9 or 10, got %d\n", msg_index);
759 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
760 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
761 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
762 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
763 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
765 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
766 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
767 ok(size == 12, "Expected 12, got %d\n", size);
769 ptr = (LPSTR)DdeAccessData(hdata, &size);
773 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
774 ok(size == 15, "Expected 15, got %d\n", size);
775 ret = (HDDEDATA)DDE_FACK;
779 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
780 ok(size == 18, "Expected 18, got %d\n", size);
781 ret = (HDDEDATA)DDE_FNOTPROCESSED;
784 DdeUnaccessData(hdata);
789 case XTYP_DISCONNECT:
791 ok(msg_index == 11, "Expected 11, got %d\n", msg_index);
792 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
793 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
794 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
795 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
796 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
797 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
803 ok(FALSE, "Unhandled msg: %08x\n", uType);
809 static void test_ddeml_server(HANDLE hproc)
817 /* set up DDE server */
819 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
820 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
822 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
823 ok(server != NULL, "Expected non-NULL string handle\n");
825 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
826 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
830 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
831 } while (WaitForSingleObject(hproc, 500) == WAIT_TIMEOUT);
833 ret = DdeUninitialize(server_pid);
834 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
837 static HWND client_hwnd, server_hwnd;
838 static ATOM server, topic, item;
839 static HGLOBAL execute_hglobal;
841 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
850 static int msg_index = 0;
852 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
853 return DefWindowProcA(hwnd, msg, wparam, lparam);
859 case WM_DDE_INITIATE:
861 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
862 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
864 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
865 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
866 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
867 ok(size == 13, "Expected 13, got %d\n", size);
869 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
870 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
871 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
872 ok(size == 12, "Expected 12, got %d\n", size);
879 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 10),
880 "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index);
884 server_hwnd = (HWND)wparam;
885 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
887 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
888 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
889 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
890 ok(size == 13, "Expected 13, got %d\n", size);
892 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
893 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
894 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
895 ok(size == 12, "Expected 12, got %d\n", size);
897 else if (msg_index == 9 || msg_index == 10)
899 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
901 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
904 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
905 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
906 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
908 ok(hi == (UINT_PTR)execute_hglobal, "Execpted execute hglobal, got %08lx\n", hi);
909 ptr = GlobalLock((HGLOBAL)hi);
913 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
914 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
918 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
919 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
922 GlobalUnlock((HGLOBAL)hi);
926 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
928 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
931 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
932 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
933 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
936 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
939 if (msg_index == 6) todo_wine
940 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
943 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
946 ok(hi == item, "Expected item atom, got %08lx\n", hi);
947 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
948 ok(size == 7, "Expected 7, got %d\n", size);
950 else if (msg_index == 4 || msg_index == 7)
952 ok(hi == 0, "Expected 0, got %08lx\n", hi);
953 ok(size == 0, "Expected empty string, got %d\n", size);
957 ok(hi == item, "Expected item atom, got %08lx\n", hi);
958 if (msg_index == 6) todo_wine
960 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
961 ok(size == 4, "Expected 4, got %d\n", size);
971 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
972 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
974 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
976 data = GlobalLock((HGLOBAL)lo);
977 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
978 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
981 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
983 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
984 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
985 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
986 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
987 GlobalUnlock((HGLOBAL)lo);
989 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
990 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
991 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
992 ok(size == 7, "Expected 7, got %d\n", size);
994 GlobalFree((HGLOBAL)lo);
995 GlobalDeleteAtom(hi);
1001 ok(FALSE, "Unhandled msg: %08x\n", msg);
1004 return DefWindowProcA(hwnd, msg, wparam, lparam);
1007 static HGLOBAL create_poke()
1013 size = sizeof(DDEPOKE) + lstrlenA("poke data\r\n") + 1;
1014 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
1015 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1017 poke = GlobalLock(hglobal);
1019 poke->fRelease = TRUE;
1020 poke->fReserved = TRUE;
1021 poke->cfFormat = CF_TEXT;
1022 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
1023 GlobalUnlock(hglobal);
1028 static HGLOBAL create_execute(LPCSTR command)
1033 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1034 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1036 ptr = GlobalLock(hglobal);
1037 lstrcpyA(ptr, command);
1038 GlobalUnlock(hglobal);
1043 static void test_msg_client()
1048 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1050 server = GlobalAddAtomA("TestDDEServer");
1051 ok(server != 0, "Expected non-NULL server\n");
1053 topic = GlobalAddAtomA("TestDDETopic");
1054 ok(topic != 0, "Expected non-NULL topic\n");
1056 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1058 GlobalDeleteAtom(server);
1059 GlobalDeleteAtom(topic);
1063 item = GlobalAddAtom("request");
1064 ok(item != 0, "Expected non-NULL item\n");
1066 /* WM_DDE_REQUEST, bad clipboard format */
1067 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1068 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1073 /* WM_DDE_REQUEST, no item */
1074 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1075 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1080 /* WM_DDE_REQUEST, no client hwnd */
1081 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1082 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1087 /* WM_DDE_REQUEST, correct params */
1088 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1089 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1094 GlobalDeleteAtom(item);
1095 item = GlobalAddAtomA("poke");
1096 ok(item != 0, "Expected non-NULL item\n");
1098 hglobal = create_poke();
1100 /* WM_DDE_POKE, no ddepoke */
1101 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1102 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1107 /* WM_DDE_POKE, no item */
1108 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1109 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1114 hglobal = create_poke();
1116 /* WM_DDE_POKE, no client hwnd */
1117 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1118 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1123 /* WM_DDE_POKE, all params correct */
1124 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1125 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1130 execute_hglobal = create_execute("[Command(Var)]");
1132 /* WM_DDE_EXECUTE, no lparam */
1133 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1138 /* WM_DDE_EXECUTE, no hglobal */
1139 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1140 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1145 /* WM_DDE_EXECUTE, no client hwnd */
1146 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1147 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1152 /* WM_DDE_EXECUTE, all params correct */
1153 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1154 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1159 GlobalFree(execute_hglobal);
1160 execute_hglobal = create_execute("[BadCommand(Var)]");
1162 /* WM_DDE_EXECUTE that will get rejected */
1163 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1164 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1169 DestroyWindow(client_hwnd);
1172 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1176 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1181 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1182 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1188 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1191 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1193 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1197 case WM_DDE_INITIATE:
1199 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1201 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
1203 if (LOWORD(lparam) == aService)
1205 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
1206 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
1207 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1208 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
1211 GlobalDeleteAtom(aService);
1215 case WM_DDE_EXECUTE:
1222 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1224 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1225 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1227 ack.bAppReturnCode = 0;
1231 cmd = GlobalLock((HGLOBAL)hi);
1233 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
1235 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1236 /* We have to send a negative acknowledge even if we don't
1237 * accept the command, otherwise Windows goes mad and next time
1238 * we send an acknowledge DDEML drops the connection.
1239 * Not sure how to call it: a bug or a feature.
1245 GlobalUnlock((HGLOBAL)hi);
1247 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1249 status = *((WORD *)&ack);
1250 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1252 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1256 case WM_DDE_TERMINATE:
1261 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1263 ack.bAppReturnCode = 0;
1268 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1270 status = *((WORD *)&ack);
1271 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1273 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1281 return DefWindowProcW(hwnd, msg, wparam, lparam);
1284 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1286 return DefWindowProcA(hwnd, msg, wparam, lparam);
1289 static BOOL create_dde_windows(HWND *client, HWND *server)
1293 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1294 static const char client_class_name[] = "dde_client_window";
1296 memset(&wcW, 0, sizeof(wcW));
1297 wcW.lpfnWndProc = dde_server_wndprocW;
1298 wcW.lpszClassName = server_class_name;
1299 wcW.hInstance = GetModuleHandleA(0);
1300 if (!RegisterClassW(&wcW)) return FALSE;
1302 memset(&wcA, 0, sizeof(wcA));
1303 wcA.lpfnWndProc = dde_client_wndproc;
1304 wcA.lpszClassName = client_class_name;
1305 wcA.hInstance = GetModuleHandleA(0);
1306 assert(RegisterClassA(&wcA));
1308 *server = CreateWindowExW(0, server_class_name, NULL,
1310 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1311 GetDesktopWindow(), 0,
1312 GetModuleHandleA(0), NULL);
1315 *client = CreateWindowExA(0, client_class_name, NULL,
1317 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1318 GetDesktopWindow(), 0,
1319 GetModuleHandleA(0), NULL);
1322 trace("server hwnd %p, client hwnd %p\n", *server, *client);
1324 ok(IsWindowUnicode(*server), "server has to be a unicode window\n");
1325 ok(!IsWindowUnicode(*client), "client has to be an ANSI window\n");
1330 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1331 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1332 ULONG_PTR dwData1, ULONG_PTR dwData2)
1334 static const char * const cmd_type[15] = {
1335 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1336 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1337 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1338 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1340 const char *cmd_name;
1342 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1343 cmd_name = (type >= 0 && type <= 14) ? cmd_type[type] : "unknown";
1345 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1346 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1350 static void test_dde_aw_transaction(void)
1353 DWORD dde_inst, ret, err;
1355 HWND hwnd_client, hwnd_server;
1358 static char test_cmd[] = "test dde command";
1360 /* server: unicode, client: ansi */
1361 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
1364 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1365 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
1366 ret, DdeGetLastError(dde_inst));
1368 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1370 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1371 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1372 err = DdeGetLastError(dde_inst);
1373 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1375 info.cb = sizeof(info);
1376 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1377 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1378 /* should be CP_WINANSI since we used DdeInitializeA */
1379 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1380 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1382 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1384 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1385 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1386 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1388 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
1390 trace("sending test client transaction command\n");
1392 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1393 ok(!hdata, "DdeClientTransaction succeeded\n");
1394 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1395 err = DdeGetLastError(dde_inst);
1396 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1398 trace("sending ANSI client transaction command\n");
1400 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1401 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1402 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1404 err = DdeGetLastError(dde_inst);
1405 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1407 trace("sending unicode client transaction command\n");
1409 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1410 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1411 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1412 err = DdeGetLastError(dde_inst);
1413 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1415 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1417 info.cb = sizeof(info);
1418 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1419 ok(!ret, "DdeQueryConvInfo should fail\n");
1420 err = DdeGetLastError(dde_inst);
1422 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1425 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1427 /* This call hangs on win2k SP4 and XP SP1.
1428 DdeUninitialize(dde_inst);*/
1430 DestroyWindow(hwnd_client);
1431 DestroyWindow(hwnd_server);
1434 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1436 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1443 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1444 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1445 DdeGetLastError(dde_inst));
1447 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1448 if (codepage == CP_WINANSI)
1449 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1451 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1453 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1454 if (codepage == CP_WINANSI)
1456 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1457 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1461 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1462 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1465 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1466 if (codepage == CP_WINANSI)
1468 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1469 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1473 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1474 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1477 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1478 if (codepage == CP_WINANSI)
1480 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1481 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1485 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1486 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1489 if (codepage == CP_WINANSI)
1491 atom = FindAtomA((LPSTR)dde_string);
1492 ok(atom != 0, "Expected a valid atom\n");
1494 SetLastError(0xdeadbeef);
1495 atom = GlobalFindAtomA((LPSTR)dde_string);
1496 ok(atom == 0, "Expected 0, got %d\n", atom);
1497 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1498 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1502 atom = FindAtomW(dde_string);
1503 ok(atom != 0, "Expected a valid atom\n");
1505 SetLastError(0xdeadbeef);
1506 atom = GlobalFindAtomW(dde_string);
1507 ok(atom == 0, "Expected 0, got %d\n", atom);
1508 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1509 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1512 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1515 static void test_DdeCreateStringHandle(void)
1517 DWORD dde_inst, ret;
1519 dde_inst = 0xdeadbeef;
1520 SetLastError(0xdeadbeef);
1521 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1522 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1524 trace("Skipping the DDE test on a Win9x platform\n");
1528 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
1529 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
1532 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1533 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
1534 ret, DdeGetLastError(dde_inst));
1536 test_DdeCreateStringHandleW(dde_inst, 0);
1537 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
1538 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
1540 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
1543 static void test_FreeDDElParam(void)
1545 HGLOBAL val, hglobal;
1548 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
1549 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1551 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1552 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
1553 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1554 val = GlobalFree(hglobal);
1555 ok(val == NULL, "Expected NULL, got %p\n", val);
1557 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1558 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
1559 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1560 val = GlobalFree(hglobal);
1561 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1562 ok(GetLastError() == ERROR_INVALID_HANDLE,
1563 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1565 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1566 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
1567 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1568 val = GlobalFree(hglobal);
1569 ok(val == NULL, "Expected NULL, got %p\n", val);
1571 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1572 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
1573 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1574 val = GlobalFree(hglobal);
1575 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1576 ok(GetLastError() == ERROR_INVALID_HANDLE,
1577 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1579 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1580 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
1581 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1582 val = GlobalFree(hglobal);
1583 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1584 ok(GetLastError() == ERROR_INVALID_HANDLE,
1585 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1587 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1588 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
1589 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1590 val = GlobalFree(hglobal);
1591 ok(val == NULL, "Expected NULL, got %p\n", val);
1593 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1594 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1595 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1596 val = GlobalFree(hglobal);
1597 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1598 ok(GetLastError() == ERROR_INVALID_HANDLE,
1599 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1601 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1602 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1603 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1604 val = GlobalFree(hglobal);
1605 ok(val == NULL, "Expected NULL, got %p\n", val);
1608 static void test_PackDDElParam(void)
1610 UINT_PTR lo, hi, *ptr;
1615 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1616 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1617 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1618 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1619 ok(GetLastError() == ERROR_INVALID_HANDLE,
1620 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1623 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1624 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1625 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1626 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1628 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1629 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1631 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1632 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1633 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1634 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1635 ok(GetLastError() == ERROR_INVALID_HANDLE,
1636 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1639 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1640 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1641 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1642 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1644 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1645 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1647 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1648 ptr = GlobalLock((HGLOBAL)lparam);
1649 ok(ptr != NULL, "Expected non-NULL ptr\n");
1650 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1651 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1653 ret = GlobalUnlock((HGLOBAL)lparam);
1654 ok(ret == 1, "Expected 1, got %d\n", ret);
1657 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1658 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1659 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1660 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1662 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1663 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1665 hglobal = GlobalFree((HGLOBAL)lparam);
1666 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1667 ok(GetLastError() == ERROR_INVALID_HANDLE,
1668 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1670 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1671 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1672 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1673 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1674 ok(GetLastError() == ERROR_INVALID_HANDLE,
1675 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1678 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1679 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1680 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1681 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1683 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1684 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1686 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1687 ptr = GlobalLock((HGLOBAL)lparam);
1688 ok(ptr != NULL, "Expected non-NULL ptr\n");
1689 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1690 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1692 ret = GlobalUnlock((HGLOBAL)lparam);
1693 ok(ret == 1, "Expected 1, got %d\n", ret);
1696 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1697 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1698 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1699 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1701 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1702 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1704 hglobal = GlobalFree((HGLOBAL)lparam);
1705 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1706 ok(GetLastError() == ERROR_INVALID_HANDLE,
1707 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1709 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1710 ptr = GlobalLock((HGLOBAL)lparam);
1711 ok(ptr != NULL, "Expected non-NULL ptr\n");
1712 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1713 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1715 ret = GlobalUnlock((HGLOBAL)lparam);
1716 ok(ret == 1, "Expected 1, got %d\n", ret);
1719 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1720 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1721 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1722 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1724 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1725 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1727 hglobal = GlobalFree((HGLOBAL)lparam);
1728 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1729 ok(GetLastError() == ERROR_INVALID_HANDLE,
1730 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1732 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1733 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1734 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1735 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1736 ok(GetLastError() == ERROR_INVALID_HANDLE,
1737 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1740 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1741 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1742 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1743 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1745 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1746 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1748 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1749 ptr = GlobalLock((HGLOBAL)lparam);
1750 ok(ptr != NULL, "Expected non-NULL ptr\n");
1751 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1752 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1754 ret = GlobalUnlock((HGLOBAL)lparam);
1755 ok(ret == 1, "Expected 1, got %d\n", ret);
1758 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1759 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1760 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1761 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1763 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1764 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1766 hglobal = GlobalFree((HGLOBAL)lparam);
1767 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1768 ok(GetLastError() == ERROR_INVALID_HANDLE,
1769 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1771 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1772 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1773 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1774 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1775 ok(GetLastError() == ERROR_INVALID_HANDLE,
1776 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1779 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1780 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1781 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1782 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1784 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1785 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1788 static void test_UnpackDDElParam(void)
1790 UINT_PTR lo, hi, *ptr;
1797 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1798 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1799 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1800 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1805 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1806 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1807 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1808 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1813 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1814 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1815 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1816 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1820 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1821 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1822 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1823 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1827 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1828 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1829 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1830 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1834 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1835 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1836 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1837 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1841 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1842 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1843 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1844 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1846 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1847 ptr = GlobalLock(hglobal);
1848 ptr[0] = 0xcafebabe;
1849 ptr[1] = 0xdeadbeef;
1850 GlobalUnlock(hglobal);
1854 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
1855 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1856 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1857 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1861 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
1862 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1863 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1864 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1868 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
1869 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1870 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1871 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1875 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
1876 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1877 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1878 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1882 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
1883 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1884 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1885 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1889 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
1890 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1891 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1892 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1896 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
1897 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1898 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1899 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1903 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
1904 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1905 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1906 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1910 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
1911 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1912 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1913 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1917 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
1918 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1919 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1920 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
1927 char buffer[MAX_PATH];
1928 STARTUPINFO startup;
1929 PROCESS_INFORMATION proc;
1931 argc = winetest_get_mainargs(&argv);
1934 if (!lstrcmpA(argv[2], "ddeml"))
1935 test_ddeml_client();
1936 else if (!lstrcmpA(argv[2], "msg"))
1942 ZeroMemory(&startup, sizeof(STARTUPINFO));
1943 sprintf(buffer, "%s dde ddeml", argv[0]);
1944 startup.cb = sizeof(startup);
1945 startup.dwFlags = STARTF_USESHOWWINDOW;
1946 startup.wShowWindow = SW_SHOWNORMAL;
1948 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
1949 0, NULL, NULL, &startup, &proc);
1951 test_msg_server(proc.hProcess);
1953 sprintf(buffer, "%s dde msg", argv[0]);
1954 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
1955 0, NULL, NULL, &startup, &proc);
1957 test_ddeml_server(proc.hProcess);
1959 test_dde_aw_transaction();
1961 test_DdeCreateStringHandle();
1962 test_FreeDDElParam();
1963 test_PackDDElParam();
1964 test_UnpackDDElParam();