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 create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
46 memset(&wcA, 0, sizeof(wcA));
47 wcA.lpfnWndProc = wndproc;
48 wcA.lpszClassName = name;
49 wcA.hInstance = GetModuleHandleA(0);
50 assert(RegisterClassA(&wcA));
52 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
53 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
54 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
58 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
61 char str[MAX_PATH], *ptr;
67 static int msg_index = 0;
68 static HWND client = 0;
69 static BOOL executed = FALSE;
71 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
72 return DefWindowProcA(hwnd, msg, wparam, lparam);
80 client = (HWND)wparam;
81 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
83 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
84 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
86 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
87 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
89 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
96 ok((msg_index >= 2 && msg_index <= 4) ||
97 (msg_index >= 7 && msg_index <= 8),
98 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
99 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
100 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
102 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
104 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
106 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
111 lstrcpyA(str, "command executed\r\n");
113 lstrcpyA(str, "command not executed\r\n");
116 lstrcpyA(str, "requested data\r\n");
118 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
119 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
120 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
122 data = GlobalLock(hglobal);
123 ZeroMemory(data, size);
125 /* setting fResponse to FALSE at this point destroys
126 * the internal messaging state of native dde
128 data->fResponse = TRUE;
131 data->fRelease = TRUE;
132 else if (msg_index == 3)
133 data->fAckReq = TRUE;
135 data->cfFormat = CF_TEXT;
136 lstrcpyA((LPSTR)data->Value, str);
137 GlobalUnlock(hglobal);
139 lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
140 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
147 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
148 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
150 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
152 GlobalGetAtomNameA(hi, str, MAX_PATH);
153 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
155 poke = GlobalLock((HGLOBAL)lo);
156 ok(poke != NULL, "Expected non-NULL poke\n");
157 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
160 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
162 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
163 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
166 ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
167 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
169 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
170 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
172 GlobalUnlock((HGLOBAL)lo);
174 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
175 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
182 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
183 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
185 ptr = GlobalLock((HGLOBAL)lparam);
186 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
187 GlobalUnlock((HGLOBAL)lparam);
191 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
192 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
197 case WM_DDE_TERMINATE:
199 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
200 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
201 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
203 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
209 ok(FALSE, "Unhandled msg: %08x\n", msg);
212 return DefWindowProcA(hwnd, msg, wparam, lparam);
215 static void test_msg_server(HANDLE hproc)
220 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
224 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
225 } while (WaitForSingleObject(hproc, 500) == WAIT_TIMEOUT);
230 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
231 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
232 ULONG_PTR dwData1, ULONG_PTR dwData2)
234 ok(FALSE, "Unhandled msg: %08x\n", uType);
238 static void test_ddeml_client(void)
244 HSZ server, topic, item;
249 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
250 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
252 /* FIXME: make these atoms global and check them in the server */
254 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
255 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
257 DdeGetLastError(client_pid);
258 conversation = DdeConnect(client_pid, server, topic, NULL);
259 ok(conversation != NULL, "Expected non-NULL conversation\n");
260 ret = DdeGetLastError(client_pid);
261 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
263 DdeFreeStringHandle(client_pid, server);
265 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
267 /* XTYP_REQUEST, fRelease = TRUE */
269 DdeGetLastError(client_pid);
270 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
271 ret = DdeGetLastError(client_pid);
272 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
273 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
274 ok(ret == DMLERR_DATAACKTIMEOUT, "Expected DMLERR_DATAACKTIMEOUT, got %d\n", ret);
276 /* XTYP_REQUEST, fAckReq = TRUE */
278 DdeGetLastError(client_pid);
279 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
280 ret = DdeGetLastError(client_pid);
281 ok(hdata != NULL, "Expected non-NULL hdata\n");
284 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
285 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
288 str = (LPSTR)DdeAccessData(hdata, &size);
289 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
290 ok(size == 19, "Expected 19, got %d\n", size);
292 ret = DdeUnaccessData(hdata);
293 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
295 /* XTYP_REQUEST, all params normal */
297 DdeGetLastError(client_pid);
298 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
299 ret = DdeGetLastError(client_pid);
302 ok(hdata != NULL, "Expected non-NULL hdata\n");
303 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
304 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
307 str = (LPSTR)DdeAccessData(hdata, &size);
310 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
312 ok(size == 19, "Expected 19, got %d\n", size);
314 ret = DdeUnaccessData(hdata);
315 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
317 /* XTYP_REQUEST, no item */
319 DdeGetLastError(client_pid);
320 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, 500, &res);
321 ret = DdeGetLastError(client_pid);
322 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
323 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
326 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
329 DdeFreeStringHandle(client_pid, item);
331 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
333 lstrcpyA(str, "poke data\r\n");
334 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
335 0, item, CF_TEXT, 0);
336 ok(hdata != NULL, "Expected non-NULL hdata\n");
338 /* XTYP_POKE, no item */
340 DdeGetLastError(client_pid);
341 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, 500, &res);
342 ret = DdeGetLastError(client_pid);
343 ok(op == NULL, "Expected NULL, got %p\n", op);
344 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
347 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
350 /* XTYP_POKE, no data */
352 DdeGetLastError(client_pid);
353 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, 500, &res);
354 ret = DdeGetLastError(client_pid);
355 ok(op == NULL, "Expected NULL, got %p\n", op);
356 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
359 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
362 /* XTYP_POKE, wrong size */
364 DdeGetLastError(client_pid);
365 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, 500, &res);
366 ret = DdeGetLastError(client_pid);
369 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
370 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
372 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
374 /* XTYP_POKE, correct params */
376 DdeGetLastError(client_pid);
377 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, 500, &res);
378 ret = DdeGetLastError(client_pid);
381 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
382 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
383 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
386 DdeFreeDataHandle(hdata);
388 lstrcpyA(str, "[Command(Var)]");
389 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
390 0, NULL, CF_TEXT, 0);
391 ok(hdata != NULL, "Expected non-NULL hdata\n");
393 /* XTYP_EXECUTE, correct params */
395 DdeGetLastError(client_pid);
396 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
397 ret = DdeGetLastError(client_pid);
400 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
401 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
402 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
405 /* XTYP_EXECUTE, no data */
407 DdeGetLastError(client_pid);
408 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
409 ret = DdeGetLastError(client_pid);
410 ok(op == NULL, "Expected NULL, got %p\n", op);
411 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
414 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
417 /* XTYP_EXECUTE, no data, -1 size */
419 DdeGetLastError(client_pid);
420 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
421 ret = DdeGetLastError(client_pid);
422 ok(op == NULL, "Expected NULL, got %p\n", op);
423 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
426 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
429 DdeFreeStringHandle(client_pid, topic);
430 DdeFreeDataHandle(hdata);
432 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
434 /* verify the execute */
436 DdeGetLastError(client_pid);
437 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
438 ret = DdeGetLastError(client_pid);
441 ok(hdata != NULL, "Expected non-NULL hdata\n");
442 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
443 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
446 str = (LPSTR)DdeAccessData(hdata, &size);
449 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
450 ok(size == 21, "Expected 21, got %d\n", size);
453 ret = DdeUnaccessData(hdata);
454 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
456 /* invalid transactions */
459 DdeGetLastError(client_pid);
460 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, 500, &res);
461 ret = DdeGetLastError(client_pid);
462 ok(op == NULL, "Expected NULL, got %p\n", op);
463 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
466 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
470 DdeGetLastError(client_pid);
471 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, 500, &res);
472 ret = DdeGetLastError(client_pid);
473 ok(op == NULL, "Expected NULL, got %p\n", op);
474 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
477 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
481 DdeGetLastError(client_pid);
482 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, 500, &res);
483 ret = DdeGetLastError(client_pid);
484 ok(op == NULL, "Expected NULL, got %p\n", op);
485 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
488 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
492 DdeGetLastError(client_pid);
493 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, 500, &res);
494 ret = DdeGetLastError(client_pid);
495 ok(op == NULL, "Expected NULL, got %p\n", op);
496 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
499 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
503 DdeGetLastError(client_pid);
504 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, 500, &res);
505 ret = DdeGetLastError(client_pid);
506 ok(op == NULL, "Expected NULL, got %p\n", op);
507 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
510 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
514 DdeGetLastError(client_pid);
515 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, 500, &res);
516 ret = DdeGetLastError(client_pid);
517 ok(op == NULL, "Expected NULL, got %p\n", op);
518 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
521 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
525 DdeGetLastError(client_pid);
526 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, 500, &res);
527 ret = DdeGetLastError(client_pid);
528 ok(op == NULL, "Expected NULL, got %p\n", op);
529 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
532 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
536 DdeGetLastError(client_pid);
537 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, 500, &res);
538 ret = DdeGetLastError(client_pid);
539 ok(op == NULL, "Expected NULL, got %p\n", op);
540 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
543 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_WILDCONNECT, 500, &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);
554 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
558 DdeGetLastError(client_pid);
559 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, 500, &res);
560 ret = DdeGetLastError(client_pid);
561 ok(op == NULL, "Expected NULL, got %p\n", op);
562 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
565 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
568 DdeFreeStringHandle(client_pid, item);
570 ret = DdeDisconnect(conversation);
573 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
576 ret = DdeUninitialize(client_pid);
577 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
580 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
584 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
589 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
590 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
596 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
599 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
601 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
605 case WM_DDE_INITIATE:
607 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
609 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
611 if (LOWORD(lparam) == aService)
613 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
614 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
615 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
616 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
619 GlobalDeleteAtom(aService);
630 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
632 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
633 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
635 ack.bAppReturnCode = 0;
639 cmd = GlobalLock((HGLOBAL)hi);
641 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
643 trace("ignoring unknown WM_DDE_EXECUTE command\n");
644 /* We have to send a negative acknowledge even if we don't
645 * accept the command, otherwise Windows goes mad and next time
646 * we send an acknowledge DDEML drops the connection.
647 * Not sure how to call it: a bug or a feature.
653 GlobalUnlock((HGLOBAL)hi);
655 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
657 status = *((WORD *)&ack);
658 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
660 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
664 case WM_DDE_TERMINATE:
669 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
671 ack.bAppReturnCode = 0;
676 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
678 status = *((WORD *)&ack);
679 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
681 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
689 return DefWindowProcW(hwnd, msg, wparam, lparam);
692 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
694 return DefWindowProcA(hwnd, msg, wparam, lparam);
697 static BOOL create_dde_windows(HWND *hwnd_client, HWND *hwnd_server)
701 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
702 static const char client_class_name[] = "dde_client_window";
704 memset(&wcW, 0, sizeof(wcW));
705 wcW.lpfnWndProc = dde_server_wndprocW;
706 wcW.lpszClassName = server_class_name;
707 wcW.hInstance = GetModuleHandleA(0);
708 if (!RegisterClassW(&wcW)) return FALSE;
710 memset(&wcA, 0, sizeof(wcA));
711 wcA.lpfnWndProc = dde_client_wndproc;
712 wcA.lpszClassName = client_class_name;
713 wcA.hInstance = GetModuleHandleA(0);
714 assert(RegisterClassA(&wcA));
716 *hwnd_server = CreateWindowExW(0, server_class_name, NULL,
718 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
719 GetDesktopWindow(), 0,
720 GetModuleHandleA(0), NULL);
721 assert(*hwnd_server);
723 *hwnd_client = CreateWindowExA(0, client_class_name, NULL,
725 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
726 GetDesktopWindow(), 0,
727 GetModuleHandleA(0), NULL);
728 assert(*hwnd_client);
730 trace("server hwnd %p, client hwnd %p\n", *hwnd_server, *hwnd_client);
732 ok(IsWindowUnicode(*hwnd_server), "server has to be a unicode window\n");
733 ok(!IsWindowUnicode(*hwnd_client), "client has to be an ANSI window\n");
738 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
739 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
740 ULONG_PTR dwData1, ULONG_PTR dwData2)
742 static const char * const cmd_type[15] = {
743 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
744 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
745 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
746 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
748 const char *cmd_name;
750 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
751 cmd_name = (type >= 0 && type <= 14) ? cmd_type[type] : "unknown";
753 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
754 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
758 static void test_dde_aw_transaction(void)
761 DWORD dde_inst, ret, err;
763 HWND hwnd_client, hwnd_server;
766 static char test_cmd[] = "test dde command";
768 /* server: unicode, client: ansi */
769 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
772 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
773 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
774 ret, DdeGetLastError(dde_inst));
776 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
778 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
779 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
780 err = DdeGetLastError(dde_inst);
781 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
783 info.cb = sizeof(info);
784 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
785 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
786 /* should be CP_WINANSI since we used DdeInitializeA */
787 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
788 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
790 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
792 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
793 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
794 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
796 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
798 trace("sending test client transaction command\n");
800 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
801 ok(!hdata, "DdeClientTransaction succeeded\n");
802 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
803 err = DdeGetLastError(dde_inst);
804 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
806 trace("sending ANSI client transaction command\n");
808 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
809 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
810 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
812 err = DdeGetLastError(dde_inst);
813 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
815 trace("sending unicode client transaction command\n");
817 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
818 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
819 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
820 err = DdeGetLastError(dde_inst);
821 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
823 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
825 info.cb = sizeof(info);
826 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
827 ok(!ret, "DdeQueryConvInfo should fail\n");
828 err = DdeGetLastError(dde_inst);
830 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
833 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
835 /* This call hangs on win2k SP4 and XP SP1.
836 DdeUninitialize(dde_inst);*/
838 DestroyWindow(hwnd_client);
839 DestroyWindow(hwnd_server);
842 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
844 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
851 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
852 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
853 DdeGetLastError(dde_inst));
855 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
856 if (codepage == CP_WINANSI)
857 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
859 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
861 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
862 if (codepage == CP_WINANSI)
864 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
865 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
869 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
870 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
873 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
874 if (codepage == CP_WINANSI)
876 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
877 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
881 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
882 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
885 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
886 if (codepage == CP_WINANSI)
888 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
889 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
893 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
894 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
897 if (codepage == CP_WINANSI)
899 atom = FindAtomA((LPSTR)dde_string);
900 ok(atom != 0, "Expected a valid atom\n");
902 SetLastError(0xdeadbeef);
903 atom = GlobalFindAtomA((LPSTR)dde_string);
904 ok(atom == 0, "Expected 0, got %d\n", atom);
905 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
906 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
910 atom = FindAtomW(dde_string);
911 ok(atom != 0, "Expected a valid atom\n");
913 SetLastError(0xdeadbeef);
914 atom = GlobalFindAtomW(dde_string);
915 ok(atom == 0, "Expected 0, got %d\n", atom);
916 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
917 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
920 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
923 static void test_DdeCreateStringHandle(void)
927 dde_inst = 0xdeadbeef;
928 SetLastError(0xdeadbeef);
929 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
930 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
932 trace("Skipping the DDE test on a Win9x platform\n");
936 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
937 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
940 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
941 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
942 ret, DdeGetLastError(dde_inst));
944 test_DdeCreateStringHandleW(dde_inst, 0);
945 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
946 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
948 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
951 static void test_FreeDDElParam(void)
953 HGLOBAL val, hglobal;
956 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
957 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
959 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
960 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
961 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
962 val = GlobalFree(hglobal);
963 ok(val == NULL, "Expected NULL, got %p\n", val);
965 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
966 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
967 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
968 val = GlobalFree(hglobal);
969 ok(val == hglobal, "Expected hglobal, got %p\n", val);
970 ok(GetLastError() == ERROR_INVALID_HANDLE,
971 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
973 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
974 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
975 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
976 val = GlobalFree(hglobal);
977 ok(val == NULL, "Expected NULL, got %p\n", val);
979 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
980 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
981 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
982 val = GlobalFree(hglobal);
983 ok(val == hglobal, "Expected hglobal, got %p\n", val);
984 ok(GetLastError() == ERROR_INVALID_HANDLE,
985 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
987 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
988 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
989 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
990 val = GlobalFree(hglobal);
991 ok(val == hglobal, "Expected hglobal, got %p\n", val);
992 ok(GetLastError() == ERROR_INVALID_HANDLE,
993 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
995 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
996 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
997 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
998 val = GlobalFree(hglobal);
999 ok(val == NULL, "Expected NULL, got %p\n", val);
1001 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1002 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1003 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1004 val = GlobalFree(hglobal);
1005 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1006 ok(GetLastError() == ERROR_INVALID_HANDLE,
1007 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1009 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1010 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1011 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1012 val = GlobalFree(hglobal);
1013 ok(val == NULL, "Expected NULL, got %p\n", val);
1016 static void test_PackDDElParam(void)
1018 UINT_PTR lo, hi, *ptr;
1023 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1024 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1025 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1026 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1027 ok(GetLastError() == ERROR_INVALID_HANDLE,
1028 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1031 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1032 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1033 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1034 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1036 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1037 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1039 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1040 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1041 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1042 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1043 ok(GetLastError() == ERROR_INVALID_HANDLE,
1044 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1047 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1048 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1049 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1050 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1052 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1053 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1055 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1056 ptr = GlobalLock((HGLOBAL)lparam);
1057 ok(ptr != NULL, "Expected non-NULL ptr\n");
1058 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1059 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1061 ret = GlobalUnlock((HGLOBAL)lparam);
1062 ok(ret == 1, "Expected 1, got %d\n", ret);
1065 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1066 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1067 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1068 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1070 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1071 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1073 hglobal = GlobalFree((HGLOBAL)lparam);
1074 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1075 ok(GetLastError() == ERROR_INVALID_HANDLE,
1076 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1078 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1079 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1080 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1081 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1082 ok(GetLastError() == ERROR_INVALID_HANDLE,
1083 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1086 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1087 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1088 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1089 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1091 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1092 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1094 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1095 ptr = GlobalLock((HGLOBAL)lparam);
1096 ok(ptr != NULL, "Expected non-NULL ptr\n");
1097 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1098 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1100 ret = GlobalUnlock((HGLOBAL)lparam);
1101 ok(ret == 1, "Expected 1, got %d\n", ret);
1104 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1105 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1106 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1107 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1109 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1110 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1112 hglobal = GlobalFree((HGLOBAL)lparam);
1113 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1114 ok(GetLastError() == ERROR_INVALID_HANDLE,
1115 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1117 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1118 ptr = GlobalLock((HGLOBAL)lparam);
1119 ok(ptr != NULL, "Expected non-NULL ptr\n");
1120 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1121 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1123 ret = GlobalUnlock((HGLOBAL)lparam);
1124 ok(ret == 1, "Expected 1, got %d\n", ret);
1127 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1128 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1129 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1130 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1132 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1133 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1135 hglobal = GlobalFree((HGLOBAL)lparam);
1136 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1137 ok(GetLastError() == ERROR_INVALID_HANDLE,
1138 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1140 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1141 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1142 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1143 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1144 ok(GetLastError() == ERROR_INVALID_HANDLE,
1145 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1148 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1149 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1150 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1151 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1153 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1154 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1156 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1157 ptr = GlobalLock((HGLOBAL)lparam);
1158 ok(ptr != NULL, "Expected non-NULL ptr\n");
1159 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1160 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1162 ret = GlobalUnlock((HGLOBAL)lparam);
1163 ok(ret == 1, "Expected 1, got %d\n", ret);
1166 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1167 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1168 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1169 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1171 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1172 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1174 hglobal = GlobalFree((HGLOBAL)lparam);
1175 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1176 ok(GetLastError() == ERROR_INVALID_HANDLE,
1177 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1179 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1180 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1181 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1182 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1183 ok(GetLastError() == ERROR_INVALID_HANDLE,
1184 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1187 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1188 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1189 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1190 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1192 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1193 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1196 static void test_UnpackDDElParam(void)
1198 UINT_PTR lo, hi, *ptr;
1205 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1206 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1207 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1208 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1213 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1214 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1215 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1216 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1221 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1222 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1223 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1224 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1228 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1229 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1230 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1231 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1235 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1236 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1237 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1238 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1242 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1243 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1244 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1245 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1249 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1250 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1251 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1252 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1254 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1255 ptr = GlobalLock(hglobal);
1256 ptr[0] = 0xcafebabe;
1257 ptr[1] = 0xdeadbeef;
1258 GlobalUnlock(hglobal);
1262 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
1263 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1264 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1265 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1269 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
1270 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1271 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1272 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1276 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
1277 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1278 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1279 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1283 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
1284 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1285 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1286 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1290 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
1291 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1292 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1293 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1297 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
1298 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1299 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1300 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1304 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
1305 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1306 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1307 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1311 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
1312 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1313 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1314 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1318 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
1319 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1320 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1321 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1325 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
1326 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1327 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1328 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
1335 char buffer[MAX_PATH];
1336 STARTUPINFO startup;
1337 PROCESS_INFORMATION proc;
1339 argc = winetest_get_mainargs(&argv);
1342 if (!lstrcmpA(argv[2], "ddeml"))
1343 test_ddeml_client();
1348 ZeroMemory(&startup, sizeof(STARTUPINFO));
1349 sprintf(buffer, "%s dde ddeml", argv[0]);
1350 startup.cb = sizeof(startup);
1351 startup.dwFlags = STARTF_USESHOWWINDOW;
1352 startup.wShowWindow = SW_SHOWNORMAL;
1354 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
1355 0, NULL, NULL, &startup, &proc);
1357 test_msg_server(proc.hProcess);
1359 test_dde_aw_transaction();
1361 test_DdeCreateStringHandle();
1362 test_FreeDDElParam();
1363 test_PackDDElParam();
1364 test_UnpackDDElParam();