2 * Unit tests for DDE functions
4 * Copyright (c) 2004 Dmitry Timoshkov
5 * Copyright (c) 2007 James Hawkins
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 static const WCHAR TEST_DDE_SERVICE[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
37 static char exec_cmdA[] = "ANSI dde command";
38 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
40 static WNDPROC old_dde_client_wndproc;
42 static const DWORD default_timeout = 200;
44 static void flush_events(void)
47 int diff = default_timeout;
49 DWORD time = GetTickCount() + diff;
53 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
54 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
55 diff = time - GetTickCount();
60 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
64 memset(&wcA, 0, sizeof(wcA));
65 wcA.lpfnWndProc = wndproc;
66 wcA.lpszClassName = name;
67 wcA.hInstance = GetModuleHandleA(0);
68 assert(RegisterClassA(&wcA));
70 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
71 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
72 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
76 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
79 char str[MAX_PATH], *ptr;
85 static int msg_index = 0;
86 static HWND client = 0;
87 static BOOL executed = FALSE;
89 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
90 return DefWindowProcA(hwnd, msg, wparam, lparam);
98 client = (HWND)wparam;
99 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
101 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
102 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
104 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
105 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
107 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
114 ok((msg_index >= 2 && msg_index <= 4) ||
115 (msg_index >= 7 && msg_index <= 8),
116 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
117 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
118 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
120 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
122 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
124 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
129 lstrcpyA(str, "command executed\r\n");
131 lstrcpyA(str, "command not executed\r\n");
134 lstrcpyA(str, "requested data\r\n");
136 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
137 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
138 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
140 data = GlobalLock(hglobal);
141 ZeroMemory(data, size);
143 /* setting fResponse to FALSE at this point destroys
144 * the internal messaging state of native dde
146 data->fResponse = TRUE;
149 data->fRelease = TRUE;
150 else if (msg_index == 3)
151 data->fAckReq = TRUE;
153 data->cfFormat = CF_TEXT;
154 lstrcpyA((LPSTR)data->Value, str);
155 GlobalUnlock(hglobal);
157 lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
158 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
165 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
166 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
168 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
170 GlobalGetAtomNameA(hi, str, MAX_PATH);
171 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
173 poke = GlobalLock((HGLOBAL)lo);
174 ok(poke != NULL, "Expected non-NULL poke\n");
175 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
176 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
177 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
178 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
181 ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
182 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
184 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
185 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
187 GlobalUnlock((HGLOBAL)lo);
189 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
190 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
197 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
198 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
200 ptr = GlobalLock((HGLOBAL)lparam);
201 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
202 GlobalUnlock((HGLOBAL)lparam);
206 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
207 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
212 case WM_DDE_TERMINATE:
214 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
215 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
216 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
218 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
224 ok(FALSE, "Unhandled msg: %08x\n", msg);
227 return DefWindowProcA(hwnd, msg, wparam, lparam);
230 static void test_msg_server(HANDLE hproc, HANDLE hthread)
236 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
237 ResumeThread( hthread );
239 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
241 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
245 GetExitCodeProcess( hproc, &res );
246 ok( !res, "client failed with %u error(s)\n", res );
249 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
250 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
251 ULONG_PTR dwData1, ULONG_PTR dwData2)
253 ok(FALSE, "Unhandled msg: %08x\n", uType);
257 static void test_ddeml_client(void)
264 HSZ server, topic, item;
269 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
270 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
272 /* FIXME: make these atoms global and check them in the server */
274 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
275 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
277 DdeGetLastError(client_pid);
278 conversation = DdeConnect(client_pid, server, topic, NULL);
279 ok(conversation != NULL, "Expected non-NULL conversation\n");
280 ret = DdeGetLastError(client_pid);
281 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
283 DdeFreeStringHandle(client_pid, server);
285 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
287 /* XTYP_REQUEST, fRelease = TRUE */
289 DdeGetLastError(client_pid);
290 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
291 ret = DdeGetLastError(client_pid);
292 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
295 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", res);
298 ok(FALSE, "hdata is NULL\n");
301 str = (LPSTR)DdeAccessData(hdata, &size);
302 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
303 ok(size == 19, "Expected 19, got %d\n", size);
305 ret = DdeUnaccessData(hdata);
306 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
309 /* XTYP_REQUEST, fAckReq = TRUE */
311 DdeGetLastError(client_pid);
312 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
313 ret = DdeGetLastError(client_pid);
316 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
317 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
320 ok(FALSE, "hdata is NULL\n");
323 str = (LPSTR)DdeAccessData(hdata, &size);
324 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
325 ok(size == 19, "Expected 19, got %d\n", size);
327 ret = DdeUnaccessData(hdata);
328 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
331 /* XTYP_REQUEST, all params normal */
333 DdeGetLastError(client_pid);
334 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
335 ret = DdeGetLastError(client_pid);
336 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
339 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
342 ok(FALSE, "hdata is NULL\n");
345 str = (LPSTR)DdeAccessData(hdata, &size);
346 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
347 ok(size == 19, "Expected 19, got %d\n", size);
349 ret = DdeUnaccessData(hdata);
350 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
353 /* XTYP_REQUEST, no item */
355 DdeGetLastError(client_pid);
356 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
357 ret = DdeGetLastError(client_pid);
358 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
359 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
360 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
362 DdeFreeStringHandle(client_pid, item);
364 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
366 lstrcpyA(buffer, "poke data\r\n");
367 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
368 0, item, CF_TEXT, 0);
369 ok(hdata != NULL, "Expected non-NULL hdata\n");
371 /* XTYP_POKE, no item */
373 DdeGetLastError(client_pid);
374 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
375 ret = DdeGetLastError(client_pid);
376 ok(op == NULL, "Expected NULL, got %p\n", op);
377 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
378 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
380 /* XTYP_POKE, no data */
382 DdeGetLastError(client_pid);
383 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
384 ret = DdeGetLastError(client_pid);
385 ok(op == NULL, "Expected NULL, got %p\n", op);
386 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
387 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
389 /* XTYP_POKE, wrong size */
391 DdeGetLastError(client_pid);
392 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
393 ret = DdeGetLastError(client_pid);
394 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
395 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
396 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
398 /* XTYP_POKE, correct params */
400 DdeGetLastError(client_pid);
401 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
402 ret = DdeGetLastError(client_pid);
403 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
404 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
405 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
407 DdeFreeDataHandle(hdata);
409 lstrcpyA(buffer, "[Command(Var)]");
410 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
411 0, NULL, CF_TEXT, 0);
412 ok(hdata != NULL, "Expected non-NULL hdata\n");
414 /* XTYP_EXECUTE, correct params */
416 DdeGetLastError(client_pid);
417 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
418 ret = DdeGetLastError(client_pid);
419 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
420 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
421 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
423 /* XTYP_EXECUTE, no data */
425 DdeGetLastError(client_pid);
426 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
427 ret = DdeGetLastError(client_pid);
428 ok(op == NULL, "Expected NULL, got %p\n", op);
429 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
432 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
435 /* XTYP_EXECUTE, no data, -1 size */
437 DdeGetLastError(client_pid);
438 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
439 ret = DdeGetLastError(client_pid);
440 ok(op == NULL, "Expected NULL, got %p\n", op);
441 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
444 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
447 DdeFreeStringHandle(client_pid, topic);
448 DdeFreeDataHandle(hdata);
450 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
452 /* verify the execute */
454 DdeGetLastError(client_pid);
455 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
456 ret = DdeGetLastError(client_pid);
457 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
460 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
463 ok(FALSE, "hdata is NULL\n");
466 str = (LPSTR)DdeAccessData(hdata, &size);
467 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
468 ok(size == 21, "Expected 21, got %d\n", size);
470 ret = DdeUnaccessData(hdata);
471 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
474 /* invalid transactions */
476 DdeGetLastError(client_pid);
477 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
478 ret = DdeGetLastError(client_pid);
479 ok(op == NULL, "Expected NULL, got %p\n", op);
480 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
481 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, default_timeout, &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);
489 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_CONNECT_CONFIRM, default_timeout, &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);
497 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
500 DdeGetLastError(client_pid);
501 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, default_timeout, &res);
502 ret = DdeGetLastError(client_pid);
503 ok(op == NULL, "Expected NULL, got %p\n", op);
504 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
505 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
508 DdeGetLastError(client_pid);
509 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, default_timeout, &res);
510 ret = DdeGetLastError(client_pid);
511 ok(op == NULL, "Expected NULL, got %p\n", op);
512 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
513 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
516 DdeGetLastError(client_pid);
517 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, default_timeout, &res);
518 ret = DdeGetLastError(client_pid);
519 ok(op == NULL, "Expected NULL, got %p\n", op);
520 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
521 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
524 DdeGetLastError(client_pid);
525 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, default_timeout, &res);
526 ret = DdeGetLastError(client_pid);
527 ok(op == NULL, "Expected NULL, got %p\n", op);
528 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
529 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
532 DdeGetLastError(client_pid);
533 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, default_timeout, &res);
534 ret = DdeGetLastError(client_pid);
535 ok(op == NULL, "Expected NULL, got %p\n", op);
536 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
537 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
540 DdeGetLastError(client_pid);
541 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
542 ret = DdeGetLastError(client_pid);
543 ok(op == NULL, "Expected NULL, got %p\n", op);
544 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
545 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
548 DdeGetLastError(client_pid);
549 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
550 ret = DdeGetLastError(client_pid);
551 ok(op == NULL, "Expected NULL, got %p\n", op);
552 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
553 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
555 DdeFreeStringHandle(client_pid, item);
557 ret = DdeDisconnect(conversation);
558 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
560 ret = DdeUninitialize(client_pid);
561 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
564 static DWORD server_pid;
566 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
567 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
568 ULONG_PTR dwData1, ULONG_PTR dwData2)
570 char str[MAX_PATH], *ptr;
574 static int msg_index = 0;
575 static HCONV conversation = 0;
583 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
584 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
585 ok(hconv == 0, "Expected 0, got %p\n", hconv);
586 ok(hdata == 0, "Expected 0, got %p\n", hdata);
587 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
588 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
590 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
591 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
592 ok(size == 13, "Expected 13, got %d\n", size);
594 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
595 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
596 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
597 ok(size == 25, "Expected 25, got %d\n", size);
599 return (HDDEDATA)TRUE;
604 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
605 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
606 ok(hconv == 0, "Expected 0, got %p\n", hconv);
607 ok(hdata == 0, "Expected 0, got %p\n", hdata);
608 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
609 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
611 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
612 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
613 ok(size == 12, "Expected 12, got %d\n", size);
615 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
616 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
617 ok(size == 13, "Expected 13, got %d\n", size);
619 return (HDDEDATA)TRUE;
622 case XTYP_CONNECT_CONFIRM:
624 conversation = hconv;
626 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
627 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
628 ok(hconv != NULL, "Expected non-NULL hconv\n");
629 ok(hdata == 0, "Expected 0, got %p\n", hdata);
630 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
631 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
633 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
634 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
635 ok(size == 12, "Expected 12, got %d\n", size);
637 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
638 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
639 ok(size == 13, "Expected 13, got %d\n", size);
641 return (HDDEDATA)TRUE;
646 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
647 "Expected 4, 5 or 6, got %d\n", msg_index);
648 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
649 ok(hdata == 0, "Expected 0, got %p\n", hdata);
650 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
651 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
654 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
656 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
658 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
659 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
660 ok(size == 12, "Expected 12, got %d\n", size);
662 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
668 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
669 ok(size == 1, "Expected 1, got %d\n", size);
672 else if (msg_index == 6)
674 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
675 ok(size == 7, "Expected 7, got %d\n", size);
680 lstrcpyA(str, "requested data\r\n");
681 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
682 0, hsz2, CF_TEXT, 0);
690 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
691 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
692 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
693 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
694 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
696 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
697 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
698 ok(size == 12, "Expected 12, got %d\n", size);
700 ptr = (LPSTR)DdeAccessData(hdata, &size);
701 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
702 ok(size == 12, "Expected 12, got %d\n", size);
703 DdeUnaccessData(hdata);
705 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
710 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
711 ok(size == 1, "Expected 1, got %d\n", size);
716 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
717 ok(size == 4, "Expected 4, got %d\n", size);
720 return (HDDEDATA)DDE_FACK;
725 ok(msg_index == 9 || msg_index == 10, "Expected 9 or 10, got %d\n", msg_index);
726 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
727 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
728 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
729 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
730 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
732 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
733 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
734 ok(size == 12, "Expected 12, got %d\n", size);
736 ptr = (LPSTR)DdeAccessData(hdata, &size);
740 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
741 ok(size == 15, "Expected 15, got %d\n", size);
742 ret = (HDDEDATA)DDE_FACK;
746 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
747 ok(size == 18, "Expected 18, got %d\n", size);
748 ret = (HDDEDATA)DDE_FNOTPROCESSED;
751 DdeUnaccessData(hdata);
756 case XTYP_DISCONNECT:
758 ok(msg_index == 11, "Expected 11, 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(hsz1 == 0, "Expected 0, got %p\n", hsz2);
764 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
770 ok(FALSE, "Unhandled msg: %08x\n", uType);
776 static void test_ddeml_server(HANDLE hproc)
784 /* set up DDE server */
786 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
787 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
789 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
790 ok(server != NULL, "Expected non-NULL string handle\n");
792 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
793 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
795 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
797 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
799 ret = DdeUninitialize(server_pid);
800 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
801 GetExitCodeProcess( hproc, &res );
802 ok( !res, "client failed with %u error(s)\n", res );
805 static HWND client_hwnd, server_hwnd;
806 static ATOM server, topic, item;
807 static HGLOBAL execute_hglobal;
809 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
818 static int msg_index = 0;
820 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
821 return DefWindowProcA(hwnd, msg, wparam, lparam);
827 case WM_DDE_INITIATE:
829 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
830 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
832 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
833 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
834 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
835 ok(size == 13, "Expected 13, got %d\n", size);
837 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
838 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
839 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
840 ok(size == 12, "Expected 12, got %d\n", size);
847 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 10),
848 "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index);
852 server_hwnd = (HWND)wparam;
853 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
855 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
856 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
857 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
858 ok(size == 13, "Expected 13, got %d\n", size);
860 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
861 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
862 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
863 ok(size == 12, "Expected 12, got %d\n", size);
865 else if (msg_index == 9 || msg_index == 10)
867 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
869 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
872 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
873 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
874 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
876 ok(hi == (UINT_PTR)execute_hglobal, "Execpted execute hglobal, got %08lx\n", hi);
877 ptr = GlobalLock((HGLOBAL)hi);
881 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
882 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
886 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
887 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
890 GlobalUnlock((HGLOBAL)hi);
894 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
896 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
899 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
900 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
901 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
904 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
907 if (msg_index == 6) todo_wine
908 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
911 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
914 ok(hi == item, "Expected item atom, got %08lx\n", hi);
915 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
916 ok(size == 7, "Expected 7, got %d\n", size);
918 else if (msg_index == 4 || msg_index == 7)
920 ok(hi == 0, "Expected 0, got %08lx\n", hi);
921 ok(size == 0, "Expected empty string, got %d\n", size);
925 ok(hi == item, "Expected item atom, got %08lx\n", hi);
926 if (msg_index == 6) todo_wine
928 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
929 ok(size == 4, "Expected 4, got %d\n", size);
939 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
940 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
942 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
944 data = GlobalLock((HGLOBAL)lo);
945 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
946 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
949 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
951 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
952 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
953 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
954 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
955 GlobalUnlock((HGLOBAL)lo);
957 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
958 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
959 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
960 ok(size == 7, "Expected 7, got %d\n", size);
962 GlobalFree((HGLOBAL)lo);
963 GlobalDeleteAtom(hi);
969 ok(FALSE, "Unhandled msg: %08x\n", msg);
972 return DefWindowProcA(hwnd, msg, wparam, lparam);
975 static HGLOBAL create_poke()
981 size = FIELD_OFFSET(DDEPOKE, Value[sizeof("poke data\r\n")]);
982 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
983 ok(hglobal != 0, "Expected non-NULL hglobal\n");
985 poke = GlobalLock(hglobal);
987 poke->fRelease = TRUE;
988 poke->fReserved = TRUE;
989 poke->cfFormat = CF_TEXT;
990 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
991 GlobalUnlock(hglobal);
996 static HGLOBAL create_execute(LPCSTR command)
1001 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1002 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1004 ptr = GlobalLock(hglobal);
1005 lstrcpyA(ptr, command);
1006 GlobalUnlock(hglobal);
1011 static void test_msg_client()
1016 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1018 server = GlobalAddAtomA("TestDDEServer");
1019 ok(server != 0, "Expected non-NULL server\n");
1021 topic = GlobalAddAtomA("TestDDETopic");
1022 ok(topic != 0, "Expected non-NULL topic\n");
1024 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1026 GlobalDeleteAtom(server);
1027 GlobalDeleteAtom(topic);
1031 item = GlobalAddAtom("request");
1032 ok(item != 0, "Expected non-NULL item\n");
1034 /* WM_DDE_REQUEST, bad clipboard format */
1035 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1036 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1040 /* WM_DDE_REQUEST, no item */
1041 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1042 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1046 /* WM_DDE_REQUEST, no client hwnd */
1047 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1048 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1052 /* WM_DDE_REQUEST, correct params */
1053 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1054 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1058 GlobalDeleteAtom(item);
1059 item = GlobalAddAtomA("poke");
1060 ok(item != 0, "Expected non-NULL item\n");
1062 hglobal = create_poke();
1064 /* WM_DDE_POKE, no ddepoke */
1065 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1066 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1070 /* WM_DDE_POKE, no item */
1071 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1072 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1076 hglobal = create_poke();
1078 /* WM_DDE_POKE, no client hwnd */
1079 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1080 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1084 /* WM_DDE_POKE, all params correct */
1085 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1086 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1090 execute_hglobal = create_execute("[Command(Var)]");
1092 /* WM_DDE_EXECUTE, no lparam */
1093 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1097 /* WM_DDE_EXECUTE, no hglobal */
1098 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1099 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1103 /* WM_DDE_EXECUTE, no client hwnd */
1104 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1105 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1109 /* WM_DDE_EXECUTE, all params correct */
1110 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1111 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1115 GlobalFree(execute_hglobal);
1116 execute_hglobal = create_execute("[BadCommand(Var)]");
1118 /* WM_DDE_EXECUTE that will get rejected */
1119 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1120 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1124 DestroyWindow(client_hwnd);
1127 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1131 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1136 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1137 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1143 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1146 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1148 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1152 case WM_DDE_INITIATE:
1154 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1156 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
1158 if (LOWORD(lparam) == aService)
1160 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
1161 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
1162 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1163 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
1166 GlobalDeleteAtom(aService);
1170 case WM_DDE_EXECUTE:
1177 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1179 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1180 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1182 ack.bAppReturnCode = 0;
1186 cmd = GlobalLock((HGLOBAL)hi);
1188 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
1190 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1191 /* We have to send a negative acknowledge even if we don't
1192 * accept the command, otherwise Windows goes mad and next time
1193 * we send an acknowledge DDEML drops the connection.
1194 * Not sure how to call it: a bug or a feature.
1200 GlobalUnlock((HGLOBAL)hi);
1202 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1204 status = *((WORD *)&ack);
1205 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1207 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1211 case WM_DDE_TERMINATE:
1216 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1218 ack.bAppReturnCode = 0;
1223 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1225 status = *((WORD *)&ack);
1226 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1228 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1236 return DefWindowProcW(hwnd, msg, wparam, lparam);
1239 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1241 return DefWindowProcA(hwnd, msg, wparam, lparam);
1244 static BOOL create_dde_windows(HWND *client, HWND *server)
1248 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1249 static const char client_class_name[] = "dde_client_window";
1251 memset(&wcW, 0, sizeof(wcW));
1252 wcW.lpfnWndProc = dde_server_wndprocW;
1253 wcW.lpszClassName = server_class_name;
1254 wcW.hInstance = GetModuleHandleA(0);
1255 if (!RegisterClassW(&wcW)) return FALSE;
1257 memset(&wcA, 0, sizeof(wcA));
1258 wcA.lpfnWndProc = dde_client_wndproc;
1259 wcA.lpszClassName = client_class_name;
1260 wcA.hInstance = GetModuleHandleA(0);
1261 assert(RegisterClassA(&wcA));
1263 *server = CreateWindowExW(0, server_class_name, NULL,
1265 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1266 GetDesktopWindow(), 0,
1267 GetModuleHandleA(0), NULL);
1270 *client = CreateWindowExA(0, client_class_name, NULL,
1272 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1273 GetDesktopWindow(), 0,
1274 GetModuleHandleA(0), NULL);
1277 trace("server hwnd %p, client hwnd %p\n", *server, *client);
1279 ok(IsWindowUnicode(*server), "server has to be a unicode window\n");
1280 ok(!IsWindowUnicode(*client), "client has to be an ANSI window\n");
1285 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1286 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1287 ULONG_PTR dwData1, ULONG_PTR dwData2)
1289 static const char * const cmd_type[15] = {
1290 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1291 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1292 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1293 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1295 const char *cmd_name;
1297 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1298 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1300 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1301 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1305 static void test_dde_aw_transaction(void)
1308 DWORD dde_inst, ret, err;
1310 HWND hwnd_client, hwnd_server;
1313 static char test_cmd[] = "test dde command";
1315 /* server: unicode, client: ansi */
1316 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
1319 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1320 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
1321 ret, DdeGetLastError(dde_inst));
1323 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1325 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1326 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1327 err = DdeGetLastError(dde_inst);
1328 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1330 info.cb = sizeof(info);
1331 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1332 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1333 /* should be CP_WINANSI since we used DdeInitializeA */
1334 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1335 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1337 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1339 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1340 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1341 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1343 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
1345 trace("sending test client transaction command\n");
1347 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1348 ok(!hdata, "DdeClientTransaction succeeded\n");
1349 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1350 err = DdeGetLastError(dde_inst);
1351 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1353 trace("sending ANSI client transaction command\n");
1355 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1356 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1357 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1359 err = DdeGetLastError(dde_inst);
1360 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1362 trace("sending unicode client transaction command\n");
1364 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1365 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1366 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1367 err = DdeGetLastError(dde_inst);
1368 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1370 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1372 info.cb = sizeof(info);
1373 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1374 ok(!ret, "DdeQueryConvInfo should fail\n");
1375 err = DdeGetLastError(dde_inst);
1377 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1380 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1382 /* This call hangs on win2k SP4 and XP SP1.
1383 DdeUninitialize(dde_inst);*/
1385 DestroyWindow(hwnd_client);
1386 DestroyWindow(hwnd_server);
1389 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1391 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1398 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1399 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1400 DdeGetLastError(dde_inst));
1402 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1403 if (codepage == CP_WINANSI)
1404 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1406 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1408 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1409 if (codepage == CP_WINANSI)
1411 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1412 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1416 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1417 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1420 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1421 if (codepage == CP_WINANSI)
1423 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1424 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1428 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1429 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1432 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1433 if (codepage == CP_WINANSI)
1435 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1436 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1440 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1441 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1444 if (codepage == CP_WINANSI)
1446 atom = FindAtomA((LPSTR)dde_string);
1447 ok(atom != 0, "Expected a valid atom\n");
1449 SetLastError(0xdeadbeef);
1450 atom = GlobalFindAtomA((LPSTR)dde_string);
1451 ok(atom == 0, "Expected 0, got %d\n", atom);
1452 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1453 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1457 atom = FindAtomW(dde_string);
1458 ok(atom != 0, "Expected a valid atom\n");
1460 SetLastError(0xdeadbeef);
1461 atom = GlobalFindAtomW(dde_string);
1462 ok(atom == 0, "Expected 0, got %d\n", atom);
1463 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1464 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1467 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1470 static void test_DdeCreateDataHandle(void)
1481 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1482 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1484 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1485 ok(item != NULL, "Expected non-NULL hsz\n");
1487 /* invalid instance id */
1488 DdeGetLastError(dde_inst);
1489 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1490 err = DdeGetLastError(dde_inst);
1493 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1494 ok(err == DMLERR_INVALIDPARAMETER,
1495 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1499 DdeGetLastError(dde_inst);
1500 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1501 err = DdeGetLastError(dde_inst);
1504 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1505 ok(err == DMLERR_INVALIDPARAMETER,
1506 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1510 DdeGetLastError(dde_inst);
1511 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1512 err = DdeGetLastError(dde_inst);
1513 ok(hdata != NULL, "Expected non-NULL hdata\n");
1514 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1516 ptr = GlobalLock(hdata);
1519 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1522 ptr = DdeAccessData(hdata, &size);
1523 ok(ptr != NULL, "Expected non-NULL ptr\n");
1524 ok(size == 260, "Expected 260, got %d\n", size);
1526 ret = DdeUnaccessData(hdata);
1527 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1529 ret = DdeFreeDataHandle(hdata);
1530 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1533 DdeGetLastError(dde_inst);
1534 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1535 err = DdeGetLastError(dde_inst);
1536 ok(hdata != NULL, "Expected non-NULL hdata\n");
1537 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1539 ptr = GlobalLock(hdata);
1542 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1545 ptr = DdeAccessData(hdata, &size);
1546 ok(ptr != NULL, "Expected non-NULL ptr\n");
1547 ok(size == 0, "Expected 0, got %d\n", size);
1549 ret = DdeUnaccessData(hdata);
1550 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1552 ret = DdeFreeDataHandle(hdata);
1553 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1555 /* cbOff is non-zero */
1556 DdeGetLastError(dde_inst);
1557 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1558 err = DdeGetLastError(dde_inst);
1559 ok(hdata != NULL, "Expected non-NULL hdata\n");
1560 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1562 ptr = GlobalLock(hdata);
1565 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1568 ptr = DdeAccessData(hdata, &size);
1569 ok(ptr != NULL, "Expected non-NULL ptr\n");
1570 ok(size == 262, "Expected 262, got %d\n", size);
1573 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1576 ret = DdeUnaccessData(hdata);
1577 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1579 ret = DdeFreeDataHandle(hdata);
1580 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1583 DdeGetLastError(dde_inst);
1584 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1585 err = DdeGetLastError(dde_inst);
1586 ok(hdata != NULL, "Expected non-NULL hdata\n");
1587 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1589 ptr = GlobalLock(hdata);
1592 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1595 ptr = DdeAccessData(hdata, &size);
1596 ok(ptr != NULL, "Expected non-NULL ptr\n");
1597 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1598 ok(size == 260, "Expected 260, got %d\n", size);
1600 ret = DdeUnaccessData(hdata);
1601 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1603 ret = DdeFreeDataHandle(hdata);
1604 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1607 DdeGetLastError(dde_inst);
1608 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1609 err = DdeGetLastError(dde_inst);
1610 ok(hdata != NULL, "Expected non-NULL hdata\n");
1611 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1613 ptr = GlobalLock(hdata);
1616 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1619 ptr = DdeAccessData(hdata, &size);
1620 ok(ptr != NULL, "Expected non-NULL ptr\n");
1621 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1622 ok(size == 260, "Expected 260, got %d\n", size);
1624 ret = DdeUnaccessData(hdata);
1625 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1627 ret = DdeFreeDataHandle(hdata);
1628 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1630 /* invalid clipboard format */
1631 DdeGetLastError(dde_inst);
1632 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
1633 err = DdeGetLastError(dde_inst);
1634 ok(hdata != NULL, "Expected non-NULL hdata\n");
1635 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1637 ptr = GlobalLock(hdata);
1640 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1643 ptr = DdeAccessData(hdata, &size);
1644 ok(ptr != NULL, "Expected non-NULL ptr\n");
1645 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1646 ok(size == 260, "Expected 260, got %d\n", size);
1648 ret = DdeUnaccessData(hdata);
1649 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1651 ret = DdeFreeDataHandle(hdata);
1652 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1654 ret = DdeUninitialize(dde_inst);
1655 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1658 static void test_DdeCreateStringHandle(void)
1660 DWORD dde_inst, ret;
1662 dde_inst = 0xdeadbeef;
1663 SetLastError(0xdeadbeef);
1664 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1665 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1667 trace("Skipping the DDE test on a Win9x platform\n");
1671 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
1672 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
1675 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1676 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
1677 ret, DdeGetLastError(dde_inst));
1679 test_DdeCreateStringHandleW(dde_inst, 0);
1680 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
1681 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
1683 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
1686 static void test_FreeDDElParam(void)
1688 HGLOBAL val, hglobal;
1691 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
1692 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1694 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1695 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
1696 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1697 val = GlobalFree(hglobal);
1698 ok(val == NULL, "Expected NULL, got %p\n", val);
1700 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1701 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
1702 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1703 val = GlobalFree(hglobal);
1704 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1705 ok(GetLastError() == ERROR_INVALID_HANDLE,
1706 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1708 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1709 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
1710 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1711 val = GlobalFree(hglobal);
1712 ok(val == NULL, "Expected NULL, got %p\n", val);
1714 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1715 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
1716 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1717 val = GlobalFree(hglobal);
1718 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1719 ok(GetLastError() == ERROR_INVALID_HANDLE,
1720 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1722 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1723 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
1724 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1725 val = GlobalFree(hglobal);
1726 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1727 ok(GetLastError() == ERROR_INVALID_HANDLE,
1728 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1730 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1731 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
1732 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1733 val = GlobalFree(hglobal);
1734 ok(val == NULL, "Expected NULL, got %p\n", val);
1736 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1737 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1738 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1739 val = GlobalFree(hglobal);
1740 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1741 ok(GetLastError() == ERROR_INVALID_HANDLE,
1742 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1744 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1745 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1746 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1747 val = GlobalFree(hglobal);
1748 ok(val == NULL, "Expected NULL, got %p\n", val);
1751 static void test_PackDDElParam(void)
1753 UINT_PTR lo, hi, *ptr;
1758 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1759 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1760 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1761 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1762 ok(GetLastError() == ERROR_INVALID_HANDLE,
1763 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1766 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1767 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1768 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1769 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1771 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1772 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1774 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1775 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1776 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1777 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1778 ok(GetLastError() == ERROR_INVALID_HANDLE,
1779 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1782 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1783 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1784 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1785 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1787 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1788 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1790 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1791 ptr = GlobalLock((HGLOBAL)lparam);
1792 ok(ptr != NULL, "Expected non-NULL ptr\n");
1793 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1794 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1796 ret = GlobalUnlock((HGLOBAL)lparam);
1797 ok(ret == 1, "Expected 1, got %d\n", ret);
1800 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1801 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1802 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1803 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1805 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1806 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1808 hglobal = GlobalFree((HGLOBAL)lparam);
1809 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1810 ok(GetLastError() == ERROR_INVALID_HANDLE,
1811 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1813 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1814 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1815 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1816 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1817 ok(GetLastError() == ERROR_INVALID_HANDLE,
1818 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1821 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1822 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1823 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1824 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1826 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1827 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1829 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1830 ptr = GlobalLock((HGLOBAL)lparam);
1831 ok(ptr != NULL, "Expected non-NULL ptr\n");
1832 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1833 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1835 ret = GlobalUnlock((HGLOBAL)lparam);
1836 ok(ret == 1, "Expected 1, got %d\n", ret);
1839 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1840 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1841 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1842 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1844 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1845 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1847 hglobal = GlobalFree((HGLOBAL)lparam);
1848 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1849 ok(GetLastError() == ERROR_INVALID_HANDLE,
1850 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1852 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1853 ptr = GlobalLock((HGLOBAL)lparam);
1854 ok(ptr != NULL, "Expected non-NULL ptr\n");
1855 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1856 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1858 ret = GlobalUnlock((HGLOBAL)lparam);
1859 ok(ret == 1, "Expected 1, got %d\n", ret);
1862 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1863 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1864 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1865 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1867 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1868 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1870 hglobal = GlobalFree((HGLOBAL)lparam);
1871 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1872 ok(GetLastError() == ERROR_INVALID_HANDLE,
1873 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1875 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1876 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1877 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1878 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1879 ok(GetLastError() == ERROR_INVALID_HANDLE,
1880 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1883 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1884 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1885 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1886 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1888 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1889 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1891 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1892 ptr = GlobalLock((HGLOBAL)lparam);
1893 ok(ptr != NULL, "Expected non-NULL ptr\n");
1894 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1895 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1897 ret = GlobalUnlock((HGLOBAL)lparam);
1898 ok(ret == 1, "Expected 1, got %d\n", ret);
1901 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1902 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1903 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1904 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1906 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1907 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1909 hglobal = GlobalFree((HGLOBAL)lparam);
1910 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1911 ok(GetLastError() == ERROR_INVALID_HANDLE,
1912 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1914 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1915 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1916 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1917 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1918 ok(GetLastError() == ERROR_INVALID_HANDLE,
1919 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1922 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1923 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1924 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1925 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1927 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1928 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1931 static void test_UnpackDDElParam(void)
1933 UINT_PTR lo, hi, *ptr;
1940 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1941 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1942 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1943 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1948 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1949 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1950 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1951 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1956 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1957 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1958 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1959 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1963 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1964 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1965 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1966 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1970 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1971 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1972 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1973 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1977 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1978 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1980 broken(lo == 0xdead), /* win2k */
1981 "Expected 0, got %08lx\n", lo);
1983 broken(hi == 0xbeef), /* win2k */
1984 "Expected 0, got %08lx\n", hi);
1988 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1989 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1991 broken(lo == 0xdead), /* win2k */
1992 "Expected 0, got %08lx\n", lo);
1994 broken(hi == 0xbeef), /* win2k */
1995 "Expected 0, got %08lx\n", hi);
1997 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1998 ptr = GlobalLock(hglobal);
1999 ptr[0] = 0xcafebabe;
2000 ptr[1] = 0xdeadbeef;
2001 GlobalUnlock(hglobal);
2005 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2006 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2007 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2008 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2012 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2013 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2014 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2015 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2019 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
2020 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2022 broken(lo == 0xdead), /* win2k */
2023 "Expected 0, got %08lx\n", lo);
2025 broken(hi == 0xbeef), /* win2k */
2026 "Expected 0, got %08lx\n", hi);
2030 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2031 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2032 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2033 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2037 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
2038 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2040 broken(lo == 0xdead), /* win2k */
2041 "Expected 0, got %08lx\n", lo);
2043 broken(hi == 0xbeef), /* win2k */
2044 "Expected 0, got %08lx\n", hi);
2048 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2049 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2050 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2051 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2055 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2056 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2057 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2058 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2062 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
2063 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2065 broken(lo == 0xdead), /* win2k */
2066 "Expected 0, got %08lx\n", lo);
2068 broken(hi == 0xbeef), /* win2k */
2069 "Expected 0, got %08lx\n", hi);
2073 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2074 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2075 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2076 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2080 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2081 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2082 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2083 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2090 char buffer[MAX_PATH];
2091 STARTUPINFO startup;
2092 PROCESS_INFORMATION proc;
2094 argc = winetest_get_mainargs(&argv);
2097 if (!lstrcmpA(argv[2], "ddeml"))
2098 test_ddeml_client();
2099 else if (!lstrcmpA(argv[2], "msg"))
2105 ZeroMemory(&startup, sizeof(STARTUPINFO));
2106 sprintf(buffer, "%s dde ddeml", argv[0]);
2107 startup.cb = sizeof(startup);
2108 startup.dwFlags = STARTF_USESHOWWINDOW;
2109 startup.wShowWindow = SW_SHOWNORMAL;
2111 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2112 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2114 test_msg_server(proc.hProcess, proc.hThread);
2116 sprintf(buffer, "%s dde msg", argv[0]);
2117 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2118 0, NULL, NULL, &startup, &proc);
2120 test_ddeml_server(proc.hProcess);
2122 test_dde_aw_transaction();
2124 test_DdeCreateDataHandle();
2125 test_DdeCreateStringHandle();
2126 test_FreeDDElParam();
2127 test_PackDDElParam();
2128 test_UnpackDDElParam();