mf/evr: Post sink marker events.
[wine.git] / dlls / user32 / tests / dde.c
blob96cf210d5421e57eca1539fdedb64eaa2d276e04
1 /*
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
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "dde.h"
30 #include "ddeml.h"
31 #include "winerror.h"
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_cmdAW[] = {'A','N','S','I',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
39 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
40 static char exec_cmdWA[] = "unicode dde command";
42 static WNDPROC old_dde_client_wndproc;
44 static const DWORD default_timeout = 200;
46 static HANDLE create_process(const char *arg)
48 STARTUPINFOA si = {.cb = sizeof(si)};
49 PROCESS_INFORMATION pi;
50 char cmdline[200];
51 char **argv;
52 BOOL ret;
54 winetest_get_mainargs(&argv);
55 sprintf(cmdline, "\"%s\" %s %s", argv[0], argv[1], arg);
56 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
57 ok(ret, "CreateProcess failed: %u\n", GetLastError());
58 CloseHandle(pi.hThread);
59 return pi.hProcess;
62 static BOOL is_cjk(void)
64 int lang_id = PRIMARYLANGID(GetUserDefaultLangID());
66 if (lang_id == LANG_CHINESE || lang_id == LANG_JAPANESE || lang_id == LANG_KOREAN)
67 return TRUE;
68 return FALSE;
71 static void flush_events(void)
73 MSG msg;
74 int diff = default_timeout;
75 int min_timeout = 50;
76 DWORD time = GetTickCount() + diff;
78 while (diff > 0)
80 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
81 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
82 diff = time - GetTickCount();
83 min_timeout = 10;
87 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
89 WNDCLASSA wcA;
90 ATOM aclass;
92 memset(&wcA, 0, sizeof(wcA));
93 wcA.lpfnWndProc = wndproc;
94 wcA.lpszClassName = name;
95 wcA.hInstance = GetModuleHandleA(0);
96 aclass = RegisterClassA(&wcA);
97 ok (aclass, "RegisterClass failed\n");
99 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
100 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
101 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
102 ok(*hwnd != NULL, "CreateWindowExA failed\n");
105 static void destroy_dde_window(HWND *hwnd, LPCSTR name)
107 DestroyWindow(*hwnd);
108 UnregisterClassA(name, GetModuleHandleA(NULL));
111 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
113 UINT_PTR lo, hi;
114 char str[MAX_PATH], *ptr;
115 HGLOBAL hglobal;
116 DDEDATA *data;
117 DDEPOKE *poke;
118 DWORD size;
120 static int msg_index = 0;
121 static HWND client = 0;
122 static BOOL executed = FALSE;
124 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
125 return DefWindowProcA(hwnd, msg, wparam, lparam);
127 msg_index++;
129 switch (msg)
131 case WM_DDE_INITIATE:
133 client = (HWND)wparam;
134 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
136 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
137 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
139 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
140 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
142 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
144 break;
147 case WM_DDE_REQUEST:
149 ok((msg_index >= 2 && msg_index <= 4) ||
150 (msg_index >= 7 && msg_index <= 8),
151 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
152 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
153 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
155 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
156 if (msg_index < 8)
157 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
158 else
159 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
161 if (msg_index == 8)
163 if (executed)
164 lstrcpyA(str, "command executed\r\n");
165 else
166 lstrcpyA(str, "command not executed\r\n");
168 else
169 lstrcpyA(str, "requested data\r\n");
171 size = FIELD_OFFSET(DDEDATA, Value[lstrlenA(str) + 1]);
172 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
173 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
175 data = GlobalLock(hglobal);
176 ZeroMemory(data, size);
178 /* setting fResponse to FALSE at this point destroys
179 * the internal messaging state of native dde
181 data->fResponse = TRUE;
183 if (msg_index == 2)
184 data->fRelease = TRUE;
185 else if (msg_index == 3)
186 data->fAckReq = TRUE;
188 data->cfFormat = CF_TEXT;
189 lstrcpyA((LPSTR)data->Value, str);
190 GlobalUnlock(hglobal);
192 lparam = PackDDElParam(WM_DDE_DATA, (UINT_PTR)hglobal, HIWORD(lparam));
193 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
195 break;
198 case WM_DDE_POKE:
200 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
201 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
203 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
205 GlobalGetAtomNameA(hi, str, MAX_PATH);
206 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
208 poke = GlobalLock((HGLOBAL)lo);
209 ok(poke != NULL, "Expected non-NULL poke\n");
210 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
211 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
212 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
213 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
215 if (msg_index == 5)
217 size = GlobalSize((HGLOBAL)lo);
218 ok(size == 4, "got %d\n", size);
220 else
221 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
222 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
224 GlobalUnlock((HGLOBAL)lo);
226 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
227 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
229 break;
232 case WM_DDE_EXECUTE:
234 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
235 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
237 ptr = GlobalLock((HGLOBAL)lparam);
238 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
239 GlobalUnlock((HGLOBAL)lparam);
241 executed = TRUE;
243 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, lparam);
244 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
246 break;
249 case WM_DDE_TERMINATE:
251 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
252 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
253 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
255 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
257 break;
260 default:
261 ok(FALSE, "Unhandled msg: %08x\n", msg);
264 return DefWindowProcA(hwnd, msg, wparam, lparam);
267 static void test_msg_server(void)
269 HANDLE client;
270 MSG msg;
271 HWND hwnd;
272 DWORD res;
274 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
275 client = create_process("ddeml");
277 while (MsgWaitForMultipleObjects(1, &client, FALSE, INFINITE, QS_ALLINPUT) != 0)
279 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
282 destroy_dde_window(&hwnd, "dde_server");
283 GetExitCodeProcess(client, &res);
284 ok( !res, "client failed with %u error(s)\n", res );
285 CloseHandle(client);
288 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
289 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
290 ULONG_PTR dwData1, ULONG_PTR dwData2)
292 ok(FALSE, "Unhandled msg: %08x\n", uType);
293 return 0;
296 static void test_ddeml_client(void)
298 UINT ret;
299 char buffer[32];
300 LPSTR str;
301 DWORD size, res;
302 HDDEDATA hdata, op;
303 HSZ server, topic, item;
304 DWORD client_pid;
305 HCONV conversation;
307 client_pid = 0;
308 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
309 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
311 /* FIXME: make these atoms global and check them in the server */
313 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
314 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
316 DdeGetLastError(client_pid);
317 conversation = DdeConnect(client_pid, server, topic, NULL);
318 if (broken(!conversation)) /* Windows 10 version 1607 */
320 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(client_pid));
321 DdeUninitialize(client_pid);
322 return;
324 ret = DdeGetLastError(client_pid);
325 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
327 DdeFreeStringHandle(client_pid, server);
329 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
331 /* XTYP_REQUEST, fRelease = TRUE */
332 res = 0xdeadbeef;
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);
337 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %08x\n", res);
338 ok( hdata != NULL, "hdata is NULL\n" );
339 if (hdata)
341 str = (LPSTR)DdeAccessData(hdata, &size);
342 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
343 ok(size == 17, "Expected 17, got %d\n", size);
345 ret = DdeUnaccessData(hdata);
346 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
349 /* XTYP_REQUEST, fAckReq = TRUE */
350 res = 0xdeadbeef;
351 DdeGetLastError(client_pid);
352 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
353 ret = DdeGetLastError(client_pid);
354 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %x\n", res);
355 todo_wine
356 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
357 ok( hdata != NULL, "hdata is NULL\n" );
358 if (hdata)
360 str = (LPSTR)DdeAccessData(hdata, &size);
361 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
362 ok(size == 17, "Expected 17, got %d\n", size);
364 ret = DdeUnaccessData(hdata);
365 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
368 /* XTYP_REQUEST, all params normal */
369 res = 0xdeadbeef;
370 DdeGetLastError(client_pid);
371 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
372 ret = DdeGetLastError(client_pid);
373 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
374 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %x\n", res);
375 if (hdata == NULL)
376 ok(FALSE, "hdata is NULL\n");
377 else
379 str = (LPSTR)DdeAccessData(hdata, &size);
380 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
381 ok(size == 17, "Expected 17, got %d\n", size);
383 ret = DdeUnaccessData(hdata);
384 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
387 /* XTYP_REQUEST, no item */
388 res = 0xdeadbeef;
389 DdeGetLastError(client_pid);
390 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
391 ret = DdeGetLastError(client_pid);
392 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
393 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
394 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
396 DdeFreeStringHandle(client_pid, item);
398 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
400 lstrcpyA(buffer, "poke data\r\n");
401 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
402 0, item, CF_TEXT, 0);
403 ok(hdata != NULL, "Expected non-NULL hdata\n");
405 /* XTYP_POKE, no item */
406 res = 0xdeadbeef;
407 DdeGetLastError(client_pid);
408 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &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);
412 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
414 /* XTYP_POKE, no data */
415 res = 0xdeadbeef;
416 DdeGetLastError(client_pid);
417 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
418 ret = DdeGetLastError(client_pid);
419 ok(op == NULL, "Expected NULL, got %p\n", op);
420 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
421 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
423 /* XTYP_POKE, wrong size */
424 res = 0xdeadbeef;
425 DdeGetLastError(client_pid);
426 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
427 ret = DdeGetLastError(client_pid);
428 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
429 ok(res == DDE_FACK, "Expected DDE_FACK, got %x\n", res);
430 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
432 /* XTYP_POKE, correct params */
433 res = 0xdeadbeef;
434 DdeGetLastError(client_pid);
435 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
436 ret = DdeGetLastError(client_pid);
437 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
438 ok(res == DDE_FACK, "Expected DDE_FACK, got %x\n", res);
439 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
441 DdeFreeDataHandle(hdata);
443 lstrcpyA(buffer, "[Command(Var)]");
444 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
445 0, NULL, CF_TEXT, 0);
446 ok(hdata != NULL, "Expected non-NULL hdata\n");
448 /* XTYP_EXECUTE, correct params */
449 res = 0xdeadbeef;
450 DdeGetLastError(client_pid);
451 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
452 ret = DdeGetLastError(client_pid);
453 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
454 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
455 ok(res == DDE_FACK, "Expected DDE_FACK, got %x\n", res);
457 /* XTYP_EXECUTE, no data */
458 res = 0xdeadbeef;
459 DdeGetLastError(client_pid);
460 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &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);
464 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
466 /* XTYP_EXECUTE, no data, -1 size */
467 res = 0xdeadbeef;
468 DdeGetLastError(client_pid);
469 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
470 ret = DdeGetLastError(client_pid);
471 ok(op == NULL, "Expected NULL, got %p\n", op);
472 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
473 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
475 DdeFreeStringHandle(client_pid, topic);
476 DdeFreeDataHandle(hdata);
478 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
480 /* verify the execute */
481 res = 0xdeadbeef;
482 DdeGetLastError(client_pid);
483 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
484 ret = DdeGetLastError(client_pid);
485 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
486 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
487 str = (LPSTR)DdeAccessData(hdata, &size);
488 ok(!strcmp(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
489 ok(size == 19, "Expected 19, got %d\n", size);
491 ret = DdeUnaccessData(hdata);
492 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
494 /* invalid transactions */
495 res = 0xdeadbeef;
496 DdeGetLastError(client_pid);
497 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
498 ret = DdeGetLastError(client_pid);
499 ok(op == NULL, "Expected NULL, got %p\n", op);
500 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
501 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
503 res = 0xdeadbeef;
504 DdeGetLastError(client_pid);
505 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, default_timeout, &res);
506 ret = DdeGetLastError(client_pid);
507 ok(op == NULL, "Expected NULL, got %p\n", op);
508 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
509 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
511 res = 0xdeadbeef;
512 DdeGetLastError(client_pid);
513 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, default_timeout, &res);
514 ret = DdeGetLastError(client_pid);
515 ok(op == NULL, "Expected NULL, got %p\n", op);
516 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
517 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
519 res = 0xdeadbeef;
520 DdeGetLastError(client_pid);
521 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, default_timeout, &res);
522 ret = DdeGetLastError(client_pid);
523 ok(op == NULL, "Expected NULL, got %p\n", op);
524 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
525 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
527 res = 0xdeadbeef;
528 DdeGetLastError(client_pid);
529 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, default_timeout, &res);
530 ret = DdeGetLastError(client_pid);
531 ok(op == NULL, "Expected NULL, got %p\n", op);
532 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
533 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
535 res = 0xdeadbeef;
536 DdeGetLastError(client_pid);
537 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, default_timeout, &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);
541 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
543 res = 0xdeadbeef;
544 DdeGetLastError(client_pid);
545 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, default_timeout, &res);
546 ret = DdeGetLastError(client_pid);
547 ok(op == NULL, "Expected NULL, got %p\n", op);
548 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
549 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
551 res = 0xdeadbeef;
552 DdeGetLastError(client_pid);
553 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, default_timeout, &res);
554 ret = DdeGetLastError(client_pid);
555 ok(op == NULL, "Expected NULL, got %p\n", op);
556 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
557 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
559 res = 0xdeadbeef;
560 DdeGetLastError(client_pid);
561 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
562 ret = DdeGetLastError(client_pid);
563 ok(op == NULL, "Expected NULL, got %p\n", op);
564 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
565 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
567 res = 0xdeadbeef;
568 DdeGetLastError(client_pid);
569 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
570 ret = DdeGetLastError(client_pid);
571 ok(op == NULL, "Expected NULL, got %p\n", op);
572 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
573 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
575 DdeFreeStringHandle(client_pid, item);
577 ret = DdeDisconnect(conversation);
578 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
580 ret = DdeUninitialize(client_pid);
581 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
584 static DWORD server_pid;
586 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
587 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
588 ULONG_PTR dwData1, ULONG_PTR dwData2)
590 char str[MAX_PATH], *ptr;
591 HDDEDATA ret = NULL;
592 DWORD size;
594 static int msg_index = 0;
595 static HCONV conversation = 0;
597 msg_index++;
599 switch (uType)
601 case XTYP_REGISTER:
603 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
604 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
605 ok(hconv == 0, "Expected 0, got %p\n", hconv);
606 ok(hdata == 0, "Expected 0, got %p\n", hdata);
607 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
608 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
610 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
611 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
612 ok(size == 13, "Expected 13, got %d\n", size);
614 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
615 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
616 ok(size == 17 + 2*sizeof(ULONG_PTR), "Got size %d for %s\n", size, str);
617 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
619 return (HDDEDATA)TRUE;
622 case XTYP_CONNECT:
624 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
625 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
626 ok(hconv == 0, "Expected 0, got %p\n", hconv);
627 ok(hdata == 0, "Expected 0, got %p\n", hdata);
628 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
629 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
631 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
632 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
633 ok(size == 12, "Expected 12, got %d\n", size);
635 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
636 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
637 ok(size == 13, "Expected 13, got %d\n", size);
639 return (HDDEDATA)TRUE;
642 case XTYP_CONNECT_CONFIRM:
644 conversation = hconv;
646 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
647 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
648 ok(hconv != NULL, "Expected non-NULL hconv\n");
649 ok(hdata == 0, "Expected 0, got %p\n", hdata);
650 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
651 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
653 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
654 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
655 ok(size == 12, "Expected 12, got %d\n", size);
657 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
658 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
659 ok(size == 13, "Expected 13, got %d\n", size);
661 return (HDDEDATA)TRUE;
664 case XTYP_REQUEST:
666 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
667 "Expected 4, 5 or 6, got %d\n", msg_index);
668 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
669 ok(hdata == 0, "Expected 0, got %p\n", hdata);
670 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
671 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
673 if (msg_index == 4)
674 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
675 else
676 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
678 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
679 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
680 ok(size == 12, "Expected 12, got %d\n", size);
682 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
684 if (msg_index == 5)
687 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
688 ok(size == 1, "Expected 1, got %d\n", size);
691 else if (msg_index == 6)
693 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
694 ok(size == 7, "Expected 7, got %d\n", size);
697 if (msg_index == 6)
699 lstrcpyA(str, "requested data\r\n");
700 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
701 0, hsz2, CF_TEXT, 0);
704 return NULL;
707 case XTYP_POKE:
709 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
710 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
711 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
712 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
713 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
715 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
716 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
717 ok(size == 12, "Expected 12, got %d\n", size);
719 ptr = (LPSTR)DdeAccessData(hdata, &size);
720 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
721 ok(size == 12, "Expected 12, got %d\n", size);
722 DdeUnaccessData(hdata);
724 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
725 if (msg_index == 7)
728 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
729 ok(size == 1, "Expected 1, got %d\n", size);
732 else
734 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
735 ok(size == 4, "Expected 4, got %d\n", size);
738 return (HDDEDATA)DDE_FACK;
741 case XTYP_EXECUTE:
743 ok(msg_index >= 9 && msg_index <= 11, "Expected 9 or 11, got %d\n", msg_index);
744 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
745 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
746 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
747 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
748 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
750 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
751 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
752 ok(size == 12, "Expected 12, got %d\n", size);
754 if (msg_index == 9 || msg_index == 11)
756 ptr = (LPSTR)DdeAccessData(hdata, &size);
758 if (msg_index == 9)
760 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
761 ok(size == 15, "Expected 15, got %d\n", size);
762 ret = (HDDEDATA)DDE_FACK;
764 else
766 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
767 ok(size == 18, "Expected 18, got %d\n", size);
768 ret = DDE_FNOTPROCESSED;
771 DdeUnaccessData(hdata);
773 else if (msg_index == 10)
775 DWORD rsize = 0;
777 size = DdeGetData(hdata, NULL, 0, 0);
778 ok(size == 17, "DdeGetData should have returned 17 not %d\n", size);
779 ptr = HeapAlloc(GetProcessHeap(), 0, size);
780 ok(ptr != NULL,"HeapAlloc should have returned ptr not NULL\n");
781 rsize = DdeGetData(hdata, (LPBYTE)ptr, size, 0);
782 ok(rsize == size, "DdeGetData did not return %d bytes but %d\n", size, rsize);
784 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr);
785 ok(size == 17, "Expected 17, got %d\n", size);
786 ret = (HDDEDATA)DDE_FACK;
788 HeapFree(GetProcessHeap(), 0, ptr);
791 return ret;
794 case XTYP_DISCONNECT:
796 ok(msg_index == 12, "Expected 12, got %d\n", msg_index);
797 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
798 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
799 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
800 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
801 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
802 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
804 return 0;
807 default:
808 ok(FALSE, "Unhandled msg: %08x\n", uType);
811 return 0;
814 static void test_ddeml_server(void)
816 HANDLE client;
817 MSG msg;
818 UINT res;
819 BOOL ret;
820 HSZ server;
821 HDDEDATA hdata;
823 client = create_process("msg");
825 /* set up DDE server */
826 server_pid = 0;
827 res = DdeInitializeA(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
828 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
830 server = DdeCreateStringHandleA(server_pid, "TestDDEServer", CP_WINANSI);
831 ok(server != NULL, "Expected non-NULL string handle\n");
833 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
834 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
836 while (MsgWaitForMultipleObjects(1, &client, FALSE, INFINITE, QS_ALLINPUT) != 0)
838 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
840 ret = DdeUninitialize(server_pid);
841 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
842 GetExitCodeProcess(client, &res);
843 ok( !res, "client failed with %u error(s)\n", res );
844 CloseHandle(client);
847 static HWND client_hwnd, server_hwnd;
848 static ATOM server, topic, item;
849 static HGLOBAL execute_hglobal;
851 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
853 char str[MAX_PATH];
854 UINT_PTR lo, hi;
855 DDEDATA *data;
856 DDEACK *ack;
857 DWORD size;
858 LPSTR ptr;
860 static int msg_index = 0;
862 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
863 return DefWindowProcA(hwnd, msg, wparam, lparam);
865 msg_index++;
867 switch (msg)
869 case WM_DDE_INITIATE:
871 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
872 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
874 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
875 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
876 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
877 ok(size == 13, "Expected 13, got %d\n", size);
879 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
880 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
881 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
882 ok(size == 12, "Expected 12, got %d\n", size);
884 break;
887 case WM_DDE_ACK:
889 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 11),
890 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index);
892 if (msg_index == 2)
894 server_hwnd = (HWND)wparam;
895 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
897 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
898 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
899 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
900 ok(size == 13, "Expected 13, got %d\n", size);
902 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
903 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
904 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
905 ok(size == 12, "Expected 12, got %d\n", size);
907 else if (msg_index >= 9 && msg_index <= 11)
909 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
911 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
913 ack = (DDEACK *)&lo;
914 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
915 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
916 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
918 ok(hi == (UINT_PTR)execute_hglobal, "Expected execute hglobal, got %08lx\n", hi);
919 ptr = GlobalLock((HGLOBAL)hi);
921 if (msg_index == 9)
923 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
924 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
925 } else if (msg_index == 10)
927 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
928 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr);
930 else
932 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
933 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
936 GlobalUnlock((HGLOBAL)hi);
938 else
940 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
942 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
944 ack = (DDEACK *)&lo;
945 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
946 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
947 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
949 if (msg_index >= 7)
950 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
951 else
953 if (msg_index == 6) todo_wine
954 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
957 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
958 if (msg_index == 3)
960 ok(hi == item, "Expected item atom, got %08lx\n", hi);
961 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
962 ok(size == 7, "Expected 7, got %d\n", size);
964 else if (msg_index == 4 || msg_index == 7)
966 ok(hi == 0, "Expected 0, got %08lx\n", hi);
967 ok(size == 0, "Expected empty string, got %d\n", size);
969 else
971 ok(hi == item, "Expected item atom, got %08lx\n", hi);
972 if (msg_index == 6) todo_wine
974 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
975 ok(size == 4, "Expected 4, got %d\n", size);
980 break;
983 case WM_DDE_DATA:
985 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
986 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
988 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
990 data = GlobalLock((HGLOBAL)lo);
991 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
992 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
993 todo_wine
995 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
997 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
998 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
999 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
1000 "Expected 'requested data\\r\\n', got %s\n", data->Value);
1001 GlobalUnlock((HGLOBAL)lo);
1003 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
1004 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
1005 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
1006 ok(size == 7, "Expected 7, got %d\n", size);
1008 GlobalFree((HGLOBAL)lo);
1009 GlobalDeleteAtom(hi);
1011 break;
1014 default:
1015 ok(FALSE, "Unhandled msg: %08x\n", msg);
1018 return DefWindowProcA(hwnd, msg, wparam, lparam);
1021 static HGLOBAL create_poke(void)
1023 HGLOBAL hglobal;
1024 DDEPOKE *poke;
1025 DWORD size;
1027 size = FIELD_OFFSET(DDEPOKE, Value[sizeof("poke data\r\n")]);
1028 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
1029 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1031 poke = GlobalLock(hglobal);
1032 poke->unused = 0;
1033 poke->fRelease = TRUE;
1034 poke->fReserved = TRUE;
1035 poke->cfFormat = CF_TEXT;
1036 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
1037 GlobalUnlock(hglobal);
1039 return hglobal;
1042 static HGLOBAL create_execute(LPCSTR command)
1044 HGLOBAL hglobal;
1045 LPSTR ptr;
1047 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1048 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1050 ptr = GlobalLock(hglobal);
1051 lstrcpyA(ptr, command);
1052 GlobalUnlock(hglobal);
1054 return hglobal;
1057 static void test_msg_client(void)
1059 HGLOBAL hglobal;
1060 LPARAM lparam;
1062 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1064 server = GlobalAddAtomA("TestDDEServer");
1065 ok(server != 0, "Expected non-NULL server\n");
1067 topic = GlobalAddAtomA("TestDDETopic");
1068 ok(topic != 0, "Expected non-NULL topic\n");
1070 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1072 GlobalDeleteAtom(server);
1073 GlobalDeleteAtom(topic);
1075 flush_events();
1077 item = GlobalAddAtomA("request");
1078 ok(item != 0, "Expected non-NULL item\n");
1080 /* WM_DDE_REQUEST, bad clipboard format */
1081 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1082 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1084 flush_events();
1086 /* WM_DDE_REQUEST, no item */
1087 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1088 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1090 flush_events();
1092 /* WM_DDE_REQUEST, no client hwnd */
1093 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1094 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1096 flush_events();
1098 /* WM_DDE_REQUEST, correct params */
1099 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1100 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1102 flush_events();
1104 GlobalDeleteAtom(item);
1105 item = GlobalAddAtomA("poke");
1106 ok(item != 0, "Expected non-NULL item\n");
1108 hglobal = create_poke();
1110 /* WM_DDE_POKE, no ddepoke */
1111 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1112 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1113 flush_events();
1115 /* WM_DDE_POKE, no item */
1116 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1117 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1119 flush_events();
1121 hglobal = create_poke();
1123 /* WM_DDE_POKE, no client hwnd */
1124 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1125 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1127 flush_events();
1129 /* WM_DDE_POKE, all params correct */
1130 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1131 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1133 flush_events();
1135 execute_hglobal = create_execute("[Command(Var)]");
1137 /* WM_DDE_EXECUTE, no lparam */
1138 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1140 flush_events();
1142 /* WM_DDE_EXECUTE, no hglobal */
1143 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1144 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1146 flush_events();
1148 /* WM_DDE_EXECUTE, no client hwnd */
1149 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1150 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1152 flush_events();
1154 /* WM_DDE_EXECUTE, all params correct */
1155 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1156 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1158 flush_events();
1160 GlobalFree(execute_hglobal);
1161 execute_hglobal = create_execute("[Command-2(Var)]");
1163 /* WM_DDE_EXECUTE, all params correct */
1164 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1165 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1167 flush_events();
1169 GlobalFree(execute_hglobal);
1170 execute_hglobal = create_execute("[BadCommand(Var)]");
1172 /* WM_DDE_EXECUTE that will get rejected */
1173 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1174 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1176 flush_events();
1178 destroy_dde_window(&client_hwnd, "dde_client");
1181 static LRESULT WINAPI hook_dde_client_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1183 UINT_PTR lo, hi;
1185 if (winetest_debug > 1) trace("hook_dde_client_wndprocA: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1187 switch (msg)
1189 case WM_DDE_ACK:
1190 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1191 if (winetest_debug > 1) trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1192 break;
1194 default:
1195 break;
1197 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1200 static LRESULT WINAPI hook_dde_client_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1202 UINT_PTR lo, hi;
1204 if (winetest_debug > 1) trace("hook_dde_client_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1206 switch (msg)
1208 case WM_DDE_ACK:
1209 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1210 if (winetest_debug > 1) trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1211 break;
1213 default:
1214 break;
1216 return CallWindowProcW(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1219 static LRESULT WINAPI dde_server_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1221 static BOOL client_unicode, conv_unicode;
1222 static int step;
1224 switch (msg)
1226 case WM_DDE_INITIATE:
1228 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1230 if (winetest_debug > 1) trace("server A: got WM_DDE_INITIATE from %p (%s) with %08lx\n",
1231 (HWND)wparam, client_unicode ? "Unicode" : "ANSI", lparam);
1233 if (LOWORD(lparam) == aService)
1235 client_unicode = IsWindowUnicode((HWND)wparam);
1236 conv_unicode = client_unicode;
1237 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1239 if (client_unicode)
1240 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1241 (ULONG_PTR)hook_dde_client_wndprocW);
1242 else
1243 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1244 (ULONG_PTR)hook_dde_client_wndprocA);
1245 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1247 else
1248 GlobalDeleteAtom(aService);
1249 return 0;
1252 case WM_DDE_EXECUTE:
1254 DDEACK ack;
1255 WORD status;
1256 LPCSTR cmd;
1257 UINT_PTR lo, hi;
1259 if (winetest_debug > 1) trace("server A: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1261 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1262 if (winetest_debug > 1) trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1264 ack.bAppReturnCode = 0;
1265 ack.reserved = 0;
1266 ack.fBusy = 0;
1267 /* We have to send a negative acknowledge even if we don't
1268 * accept the command, otherwise Windows goes mad and next time
1269 * we send an acknowledge DDEML drops the connection.
1270 * Not sure how to call it: a bug or a feature.
1272 ack.fAck = 0;
1274 if ((cmd = GlobalLock((HGLOBAL)hi)))
1276 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1278 switch (step % 5)
1280 case 0: /* bad command */
1281 break;
1283 case 1: /* ANSI command */
1284 if (!conv_unicode)
1285 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1286 else /* we get garbage as the A command was mapped W->A */
1287 ok( cmd[0] != exec_cmdA[0], "server A got wrong command '%s'\n", cmd );
1288 break;
1290 case 2: /* ANSI command in Unicode format */
1291 if (conv_unicode)
1292 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1293 else
1294 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server A got wrong command '%s'\n", cmd );
1295 break;
1297 case 3: /* Unicode command */
1298 if (!conv_unicode)
1299 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server A got wrong command '%s'\n", cmd );
1300 else /* correctly mapped W->A */
1301 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1302 break;
1304 case 4: /* Unicode command in ANSI format */
1305 if (!conv_unicode)
1306 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1307 else /* we get garbage as the A command was mapped W->A */
1308 ok( cmd[0] != exec_cmdWA[0], "server A got wrong command '%s'\n", cmd );
1309 break;
1311 GlobalUnlock((HGLOBAL)hi);
1313 else ok( 0, "bad command data %lx\n", hi );
1315 step++;
1317 status = *((WORD *)&ack);
1318 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1320 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1321 return 0;
1324 case WM_DDE_TERMINATE:
1326 DDEACK ack;
1327 WORD status;
1329 if (winetest_debug > 1) trace("server A: got WM_DDE_TERMINATE from %#lx with %08lx\n", wparam, lparam);
1331 ack.bAppReturnCode = 0;
1332 ack.reserved = 0;
1333 ack.fBusy = 0;
1334 ack.fAck = 1;
1336 status = *((WORD *)&ack);
1337 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1339 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1340 return 0;
1343 default:
1344 break;
1347 return DefWindowProcA(hwnd, msg, wparam, lparam);
1350 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1352 static BOOL client_unicode, conv_unicode;
1353 static int step;
1355 switch (msg)
1357 case WM_DDE_INITIATE:
1359 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1361 if (LOWORD(lparam) == aService)
1363 client_unicode = IsWindowUnicode((HWND)wparam);
1364 conv_unicode = client_unicode;
1365 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1367 if (client_unicode)
1368 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1369 (ULONG_PTR)hook_dde_client_wndprocW);
1370 else
1371 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1372 (ULONG_PTR)hook_dde_client_wndprocA);
1373 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1375 else
1376 GlobalDeleteAtom(aService);
1378 if (winetest_debug > 1)
1379 trace("server W: got WM_DDE_INITIATE from %p with %08lx (client %s conv %s)\n", (HWND)wparam,
1380 lparam, client_unicode ? "Unicode" : "ANSI", conv_unicode ? "Unicode" : "ANSI" );
1382 return 0;
1385 case WM_DDE_EXECUTE:
1387 DDEACK ack;
1388 WORD status;
1389 LPCSTR cmd;
1390 UINT_PTR lo, hi;
1392 if (winetest_debug > 1) trace("server W: got WM_DDE_EXECUTE from %#lx with %08lx\n", wparam, lparam);
1394 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1395 if (winetest_debug > 1) trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1397 ack.bAppReturnCode = 0;
1398 ack.reserved = 0;
1399 ack.fBusy = 0;
1400 /* We have to send a negative acknowledge even if we don't
1401 * accept the command, otherwise Windows goes mad and next time
1402 * we send an acknowledge DDEML drops the connection.
1403 * Not sure how to call it: a bug or a feature.
1405 ack.fAck = 0;
1407 if ((cmd = GlobalLock((HGLOBAL)hi)))
1409 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1411 switch (step % 5)
1413 case 0: /* bad command */
1414 break;
1416 case 1: /* ANSI command */
1417 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1418 ok( cmd[0] != exec_cmdA[0], "server W got wrong command '%s'\n", cmd );
1419 else if (!conv_unicode && client_unicode) /* A->W mapping */
1420 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1421 else
1422 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1423 break;
1425 case 2: /* ANSI command in Unicode format */
1426 if (conv_unicode && !client_unicode) /* W->A mapping */
1427 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1428 else if (!conv_unicode && client_unicode) /* A->W mapping */
1429 ok( *(WCHAR *)cmd == exec_cmdAW[0], "server W got wrong command '%s'\n", cmd );
1430 else
1431 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1432 break;
1434 case 3: /* Unicode command */
1435 if (conv_unicode && !client_unicode) /* W->A mapping */
1436 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1437 else if (!conv_unicode && client_unicode) /* A->W mapping */
1438 ok( *(WCHAR *)cmd == exec_cmdW[0], "server W got wrong command '%s'\n", cmd );
1439 else
1440 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1441 break;
1443 case 4: /* Unicode command in ANSI format */
1444 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1445 ok( cmd[0] != exec_cmdWA[0], "server W got wrong command '%s'\n", cmd );
1446 else if (!conv_unicode && client_unicode) /* A->W mapping */
1447 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1448 else
1449 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1450 break;
1452 GlobalUnlock((HGLOBAL)hi);
1454 else ok( 0, "bad command data %lx\n", hi );
1456 step++;
1458 status = *((WORD *)&ack);
1459 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1461 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1462 return 0;
1465 case WM_DDE_TERMINATE:
1467 DDEACK ack;
1468 WORD status;
1470 if (winetest_debug > 1) trace("server W: got WM_DDE_TERMINATE from %#lx with %08lx\n", wparam, lparam);
1472 ack.bAppReturnCode = 0;
1473 ack.reserved = 0;
1474 ack.fBusy = 0;
1475 ack.fAck = 1;
1477 status = *((WORD *)&ack);
1478 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1480 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1481 return 0;
1484 default:
1485 break;
1488 return DefWindowProcW(hwnd, msg, wparam, lparam);
1491 static HWND create_dde_server( BOOL unicode )
1493 WNDCLASSA wcA;
1494 WNDCLASSW wcW;
1495 HWND server;
1496 static const char server_class_nameA[] = "dde_server_windowA";
1497 static const WCHAR server_class_nameW[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w','W',0};
1499 if (unicode)
1501 memset(&wcW, 0, sizeof(wcW));
1502 wcW.lpfnWndProc = dde_server_wndprocW;
1503 wcW.lpszClassName = server_class_nameW;
1504 wcW.hInstance = GetModuleHandleA(0);
1505 RegisterClassW(&wcW);
1507 server = CreateWindowExW(0, server_class_nameW, NULL, WS_POPUP,
1508 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1509 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1511 else
1513 memset(&wcA, 0, sizeof(wcA));
1514 wcA.lpfnWndProc = dde_server_wndprocA;
1515 wcA.lpszClassName = server_class_nameA;
1516 wcA.hInstance = GetModuleHandleA(0);
1517 RegisterClassA(&wcA);
1519 server = CreateWindowExA(0, server_class_nameA, NULL, WS_POPUP,
1520 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1521 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1523 ok(!IsWindowUnicode(server) == !unicode, "wrong unicode type\n");
1524 return server;
1527 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1528 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1529 ULONG_PTR dwData1, ULONG_PTR dwData2)
1531 static const char * const cmd_type[15] = {
1532 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1533 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1534 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1535 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1536 UINT type;
1537 const char *cmd_name;
1539 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1540 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1542 if (winetest_debug > 1)
1543 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1544 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1545 return 0;
1548 static void test_dde_aw_transaction( BOOL client_unicode, BOOL server_unicode )
1550 HSZ hsz_server;
1551 DWORD dde_inst, ret, err;
1552 HCONV hconv;
1553 HWND hwnd_server;
1554 CONVINFO info;
1555 HDDEDATA hdata;
1556 BOOL conv_unicode = client_unicode;
1557 BOOL got;
1558 static char test_cmd[] = "test dde command";
1560 if (!(hwnd_server = create_dde_server( server_unicode ))) return;
1562 dde_inst = 0;
1563 if (client_unicode)
1564 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1565 else
1566 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1567 ok(ret == DMLERR_NO_ERROR, "DdeInitializeA failed with error %04x (%x)\n",
1568 ret, DdeGetLastError(dde_inst));
1570 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1572 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1573 if (broken(!hconv)) /* Windows 10 version 1607 */
1575 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(dde_inst));
1576 DdeUninitialize(dde_inst);
1577 return;
1579 err = DdeGetLastError(dde_inst);
1580 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1582 info.cb = sizeof(info);
1583 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1584 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1585 ok(info.ConvCtxt.iCodePage == (client_unicode ? CP_WINUNICODE : CP_WINANSI),
1586 "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1587 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1588 todo_wine {
1589 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1591 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1592 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1593 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1595 client_unicode = IsWindowUnicode( info.hwnd );
1597 ret = 0xdeadbeef;
1598 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1599 ok(!hdata, "DdeClientTransaction succeeded\n");
1600 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1601 err = DdeGetLastError(dde_inst);
1602 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1604 ret = 0xdeadbeef;
1605 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1606 err = DdeGetLastError(dde_inst);
1607 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1609 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1610 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1611 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1613 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> wrong cmd */
1615 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1616 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1617 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1619 else /* no mapping */
1621 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1622 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1623 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1626 ret = 0xdeadbeef;
1627 hdata = DdeClientTransaction((LPBYTE)exec_cmdAW, (lstrlenW(exec_cmdAW) + 1) * sizeof(WCHAR),
1628 hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1629 err = DdeGetLastError(dde_inst);
1630 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping */
1632 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1633 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1634 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1636 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1638 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1639 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1640 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1642 else /* no mapping */
1644 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1645 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1646 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1649 ret = 0xdeadbeef;
1650 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1651 err = DdeGetLastError(dde_inst);
1652 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> wrong cmd */
1654 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1655 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1656 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1658 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1660 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1661 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1662 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1664 else /* no mapping */
1666 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1667 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1668 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1671 ret = 0xdeadbeef;
1672 hdata = DdeClientTransaction((LPBYTE)exec_cmdWA, lstrlenA(exec_cmdWA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1673 err = DdeGetLastError(dde_inst);
1674 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1676 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1677 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1678 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1680 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping */
1682 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1683 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1684 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1686 else /* no mapping */
1688 ok(!hdata, "DdeClientTransaction returned %p, error %x\n", hdata, err);
1689 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1690 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %x\n", err);
1693 got = DdeDisconnect(hconv);
1694 ok(got, "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1696 info.cb = sizeof(info);
1697 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1698 ok(!ret, "DdeQueryConvInfo should fail\n");
1699 err = DdeGetLastError(dde_inst);
1700 todo_wine {
1701 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1704 got = DdeFreeStringHandle(dde_inst, hsz_server);
1705 ok(got, "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1707 /* This call hangs on win2k SP4 and XP SP1.
1708 DdeUninitialize(dde_inst);*/
1710 DestroyWindow(hwnd_server);
1713 static void test_initialisation(void)
1715 UINT ret;
1716 DWORD res;
1717 HDDEDATA hdata;
1718 HSZ server, topic, item;
1719 DWORD client_pid;
1720 HCONV conversation;
1722 /* Initialise without a valid server window. */
1723 client_pid = 0;
1724 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1725 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
1728 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
1729 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
1731 DdeGetLastError(client_pid);
1733 /* There is no server window so no conversation can be extracted */
1734 conversation = DdeConnect(client_pid, server, topic, NULL);
1735 ok(conversation == NULL, "Expected NULL conversation, %p\n", conversation);
1736 ret = DdeGetLastError(client_pid);
1737 ok(ret == DMLERR_NO_CONV_ESTABLISHED, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret);
1739 DdeFreeStringHandle(client_pid, server);
1741 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
1743 /* There is no conversation so an invalid parameter results */
1744 res = 0xdeadbeef;
1745 DdeGetLastError(client_pid);
1746 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
1747 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1748 ret = DdeGetLastError(client_pid);
1749 todo_wine
1750 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
1751 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
1753 DdeFreeStringHandle(client_pid, server);
1754 ret = DdeDisconnect(conversation);
1755 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1757 ret = DdeUninitialize(client_pid);
1758 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1761 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1763 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1764 HSZ str_handle;
1765 WCHAR bufW[256];
1766 char buf[256];
1767 ATOM atom;
1768 int ret;
1770 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1771 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1772 DdeGetLastError(dde_inst));
1774 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1775 if (codepage == CP_WINANSI)
1776 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1777 else
1778 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1780 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1781 if (codepage == CP_WINANSI)
1783 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1784 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1786 else
1788 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1789 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1792 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1793 if (codepage == CP_WINANSI)
1795 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1796 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1798 else
1800 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1801 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1804 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1805 if (codepage == CP_WINANSI)
1807 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1808 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1810 else
1812 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1813 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1816 if (codepage == CP_WINANSI)
1818 atom = FindAtomA((LPSTR)dde_string);
1819 ok(atom != 0, "Expected a valid atom\n");
1821 SetLastError(0xdeadbeef);
1822 atom = GlobalFindAtomA((LPSTR)dde_string);
1823 ok(atom == 0, "Expected 0, got %d\n", atom);
1824 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1825 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1827 else
1829 atom = FindAtomW(dde_string);
1830 ok(atom != 0, "Expected a valid atom\n");
1832 SetLastError(0xdeadbeef);
1833 atom = GlobalFindAtomW(dde_string);
1834 ok(atom == 0, "Expected 0, got %d\n", atom);
1835 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1836 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1839 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1842 static void test_DdeCreateDataHandle(void)
1844 HDDEDATA hdata;
1845 DWORD dde_inst, dde_inst2;
1846 DWORD size;
1847 UINT res, err;
1848 BOOL ret;
1849 HSZ item;
1850 LPBYTE ptr;
1851 WCHAR item_str[] = {'i','t','e','m',0};
1853 dde_inst = 0;
1854 dde_inst2 = 0;
1855 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1856 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1858 res = DdeInitializeA(&dde_inst2, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1859 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1861 /* 0 instance id
1862 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1863 * is invalid then the lastError of all instances is set to the error. There are two instances
1864 * created, lastError is cleared, an error is generated and then both instances are checked to
1865 * ensure that they both have the same error set
1867 item = DdeCreateStringHandleA(0, "item", CP_WINANSI);
1868 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1869 err = DdeGetLastError(dde_inst);
1870 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1871 err = DdeGetLastError(dde_inst2);
1872 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1873 item = DdeCreateStringHandleW(0, item_str, CP_WINUNICODE);
1874 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1875 err = DdeGetLastError(dde_inst);
1876 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1877 err = DdeGetLastError(dde_inst2);
1878 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1880 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1881 ok(item != NULL, "Expected non-NULL hsz\n");
1882 item = DdeCreateStringHandleA(dde_inst2, "item", CP_WINANSI);
1883 ok(item != NULL, "Expected non-NULL hsz\n");
1885 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1887 /* 0 instance id
1888 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1889 * is invalid then the lastError of all instances is set to the error. There are two instances
1890 * created, lastError is cleared, an error is generated and then both instances are checked to
1891 * ensure that they both have the same error set
1893 DdeGetLastError(dde_inst);
1894 DdeGetLastError(dde_inst2);
1895 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1896 err = DdeGetLastError(dde_inst);
1897 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1898 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1899 err = DdeGetLastError(dde_inst2);
1900 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1902 ret = DdeUninitialize(dde_inst2);
1903 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1906 /* NULL pSrc */
1907 DdeGetLastError(dde_inst);
1908 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1909 err = DdeGetLastError(dde_inst);
1910 ok(hdata != NULL, "Expected non-NULL hdata\n");
1911 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1913 ptr = DdeAccessData(hdata, &size);
1914 ok(ptr != NULL, "Expected non-NULL ptr\n");
1915 ok(size == 260, "Expected 260, got %d\n", size);
1917 ret = DdeUnaccessData(hdata);
1918 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1920 ret = DdeFreeDataHandle(hdata);
1921 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1923 /* cb is zero */
1924 DdeGetLastError(dde_inst);
1925 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1926 err = DdeGetLastError(dde_inst);
1927 ok(hdata != NULL, "Expected non-NULL hdata\n");
1928 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1930 ptr = DdeAccessData(hdata, &size);
1931 ok(ptr != NULL, "Expected non-NULL ptr\n");
1932 ok(size == 0, "Expected 0, got %d\n", size);
1934 ret = DdeUnaccessData(hdata);
1935 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1937 ret = DdeFreeDataHandle(hdata);
1938 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1940 /* cbOff is non-zero */
1941 DdeGetLastError(dde_inst);
1942 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1943 err = DdeGetLastError(dde_inst);
1944 ok(hdata != NULL, "Expected non-NULL hdata\n");
1945 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1947 ptr = DdeAccessData(hdata, &size);
1948 ok(ptr != NULL, "Expected non-NULL ptr\n");
1949 ok(size == 262, "Expected 262, got %d\n", size);
1950 todo_wine
1952 ok(ptr && !*ptr, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1955 ret = DdeUnaccessData(hdata);
1956 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1958 ret = DdeFreeDataHandle(hdata);
1959 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1961 /* NULL item */
1962 DdeGetLastError(dde_inst);
1963 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1964 err = DdeGetLastError(dde_inst);
1965 ok(hdata != NULL, "Expected non-NULL hdata\n");
1966 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1968 ptr = DdeAccessData(hdata, &size);
1969 ok(ptr != NULL, "Expected non-NULL ptr\n");
1970 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1971 ok(size == 260, "Expected 260, got %d\n", size);
1973 ret = DdeUnaccessData(hdata);
1974 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1976 ret = DdeFreeDataHandle(hdata);
1977 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1979 /* NULL item */
1980 DdeGetLastError(dde_inst);
1981 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1982 err = DdeGetLastError(dde_inst);
1983 ok(hdata != NULL, "Expected non-NULL hdata\n");
1984 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1986 ptr = DdeAccessData(hdata, &size);
1987 ok(ptr != NULL, "Expected non-NULL ptr\n");
1988 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1989 ok(size == 260, "Expected 260, got %d\n", size);
1991 ret = DdeUnaccessData(hdata);
1992 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1994 ret = DdeFreeDataHandle(hdata);
1995 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1997 /* invalid clipboard format */
1998 DdeGetLastError(dde_inst);
1999 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
2000 err = DdeGetLastError(dde_inst);
2001 ok(hdata != NULL, "Expected non-NULL hdata\n");
2002 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
2004 ptr = DdeAccessData(hdata, &size);
2005 ok(ptr != NULL, "Expected non-NULL ptr\n");
2006 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
2007 ok(size == 260, "Expected 260, got %d\n", size);
2009 ret = DdeUnaccessData(hdata);
2010 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2012 ret = DdeFreeDataHandle(hdata);
2013 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2015 ret = DdeUninitialize(dde_inst);
2016 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2019 static void test_DdeCreateStringHandle(void)
2021 DWORD dde_inst, ret;
2023 dde_inst = 0xdeadbeef;
2024 SetLastError(0xdeadbeef);
2025 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2026 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
2027 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
2029 dde_inst = 0;
2030 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2031 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
2032 ret, DdeGetLastError(dde_inst));
2034 test_DdeCreateStringHandleW(dde_inst, 0);
2035 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
2036 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
2038 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
2041 static void test_FreeDDElParam(void)
2043 HGLOBAL val, hglobal;
2044 BOOL ret;
2046 ret = FreeDDElParam(WM_DDE_INITIATE, 0);
2047 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2049 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2050 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
2051 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2052 val = GlobalFree(hglobal);
2053 ok(val == NULL, "Expected NULL, got %p\n", val);
2055 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2056 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
2057 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2059 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2060 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
2061 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2062 val = GlobalFree(hglobal);
2063 ok(val == NULL, "Expected NULL, got %p\n", val);
2065 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2066 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
2067 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2069 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2070 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
2071 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2073 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2074 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
2075 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2076 val = GlobalFree(hglobal);
2077 ok(val == NULL, "Expected NULL, got %p\n", val);
2079 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2080 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
2081 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2083 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2084 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
2085 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2086 val = GlobalFree(hglobal);
2087 ok(val == NULL, "Expected NULL, got %p\n", val);
2090 static void test_PackDDElParam(void)
2092 UINT_PTR lo, hi, *ptr;
2093 LPARAM lparam;
2094 BOOL ret;
2096 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
2097 /* value gets sign-extended despite being an LPARAM */
2098 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2100 lo = hi = 0;
2101 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
2102 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2103 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2104 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2106 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
2107 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2109 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
2110 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2112 lo = hi = 0;
2113 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
2114 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2115 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2116 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2118 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
2119 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2121 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
2122 ptr = GlobalLock((HGLOBAL)lparam);
2123 ok(ptr != NULL, "Expected non-NULL ptr\n");
2124 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2125 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2127 ret = GlobalUnlock((HGLOBAL)lparam);
2128 ok(ret == 1, "Expected 1, got %d\n", ret);
2130 lo = hi = 0;
2131 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
2132 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2133 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2134 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2136 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
2137 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2139 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
2140 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2142 lo = hi = 0;
2143 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
2144 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2145 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2146 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2148 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
2149 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2151 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
2152 ptr = GlobalLock((HGLOBAL)lparam);
2153 ok(ptr != NULL, "Expected non-NULL ptr\n");
2154 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2155 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2157 ret = GlobalUnlock((HGLOBAL)lparam);
2158 ok(ret == 1, "Expected 1, got %d\n", ret);
2160 lo = hi = 0;
2161 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
2162 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2163 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2164 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2166 ret = FreeDDElParam(WM_DDE_ACK, lparam);
2167 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2169 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
2170 ptr = GlobalLock((HGLOBAL)lparam);
2171 ok(ptr != NULL, "Expected non-NULL ptr\n");
2172 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2173 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2175 ret = GlobalUnlock((HGLOBAL)lparam);
2176 ok(ret == 1, "Expected 1, got %d\n", ret);
2178 lo = hi = 0;
2179 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
2180 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2181 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2182 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2184 ret = FreeDDElParam(WM_DDE_DATA, lparam);
2185 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2187 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
2188 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
2190 lo = hi = 0;
2191 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
2192 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2193 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2194 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2196 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
2197 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2199 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
2200 ptr = GlobalLock((HGLOBAL)lparam);
2201 ok(ptr != NULL, "Expected non-NULL ptr\n");
2202 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2203 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2205 ret = GlobalUnlock((HGLOBAL)lparam);
2206 ok(ret == 1, "Expected 1, got %d\n", ret);
2208 lo = hi = 0;
2209 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
2210 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2211 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2212 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2214 ret = FreeDDElParam(WM_DDE_POKE, lparam);
2215 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2217 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
2218 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
2220 lo = hi = 0;
2221 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
2222 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2223 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2224 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2226 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
2227 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2230 static void test_UnpackDDElParam(void)
2232 UINT_PTR lo, hi, *ptr;
2233 HGLOBAL hglobal;
2234 BOOL ret;
2236 /* NULL lParam */
2237 lo = 0xdead;
2238 hi = 0xbeef;
2239 ret = UnpackDDElParam(WM_DDE_INITIATE, 0, &lo, &hi);
2240 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2241 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2242 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2244 /* NULL lo */
2245 lo = 0xdead;
2246 hi = 0xbeef;
2247 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
2248 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2249 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
2250 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2252 /* NULL hi */
2253 lo = 0xdead;
2254 hi = 0xbeef;
2255 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
2256 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2257 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2258 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2260 lo = 0xdead;
2261 hi = 0xbeef;
2262 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
2263 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2264 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2265 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2267 lo = 0xdead;
2268 hi = 0xbeef;
2269 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
2270 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2271 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2272 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2274 lo = 0xdead;
2275 hi = 0xbeef;
2276 ret = UnpackDDElParam(WM_DDE_ADVISE, 0, &lo, &hi);
2277 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2278 ok(lo == 0 ||
2279 broken(lo == 0xdead), /* win2k */
2280 "Expected 0, got %08lx\n", lo);
2281 ok(hi == 0 ||
2282 broken(hi == 0xbeef), /* win2k */
2283 "Expected 0, got %08lx\n", hi);
2285 hglobal = GlobalAlloc(GMEM_DDESHARE, 2 * sizeof(*ptr));
2286 ptr = GlobalLock(hglobal);
2287 ptr[0] = 0xcafebabe;
2288 ptr[1] = 0xdeadbeef;
2289 GlobalUnlock(hglobal);
2291 lo = 0xdead;
2292 hi = 0xbeef;
2293 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2294 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2295 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2296 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2298 lo = 0xdead;
2299 hi = 0xbeef;
2300 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2301 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2302 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2303 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2305 lo = 0xdead;
2306 hi = 0xbeef;
2307 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2308 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2309 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2310 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2312 lo = 0xdead;
2313 hi = 0xbeef;
2314 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2315 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2316 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2317 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2319 lo = 0xdead;
2320 hi = 0xbeef;
2321 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2322 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2323 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2324 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2326 lo = 0xdead;
2327 hi = 0xbeef;
2328 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2329 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2330 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2331 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2333 lo = 0xdead;
2334 hi = 0xbeef;
2335 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2336 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2337 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2338 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2340 GlobalFree(hglobal);
2343 static char test_cmd_a_to_a[] = "Test dde command";
2344 static WCHAR test_cmd_w_to_w[][32] = {
2345 {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0},
2346 { 0x2018, 0x2019, 0x0161, 0x0041, 0x02dc, 0 }, /* some chars that should map properly to CP1252 */
2347 { 0x2026, 0x2020, 0x2021, 0x0d0a, 0 }, /* false negative for IsTextUnicode */
2348 { 0x4efa, 0x4efc, 0x0061, 0x4efe, 0 }, /* some Chinese chars */
2349 { 0x0061, 0x0062, 0x0063, 0x9152, 0 }, /* Chinese with latin characters begin */
2351 static int msg_index;
2352 static BOOL unicode_server, unicode_client;
2354 static HDDEDATA CALLBACK server_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2355 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2356 ULONG_PTR dwData1, ULONG_PTR dwData2)
2358 DWORD size, rsize;
2359 char str[MAX_PATH];
2360 static HCONV conversation = 0;
2361 static const char test_service [] = "TestDDEService";
2362 static const char test_topic [] = "TestDDETopic";
2364 if (winetest_debug > 1) trace("type %#x, fmt %#x\n", uType, uFmt);
2366 ok(msg_index < 5 + ARRAY_SIZE(test_cmd_w_to_w), "Got unexpected message type %#x.\n", uType);
2367 msg_index++;
2369 switch (uType)
2371 case XTYP_REGISTER:
2373 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
2374 return (HDDEDATA)TRUE;
2377 case XTYP_CONNECT:
2379 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
2380 ok(uFmt == 0, "Expected 0, got %d, msg_index=%d\n", uFmt, msg_index);
2381 ok(hconv == 0, "Expected 0, got %p, msg_index=%d\n", hconv, msg_index);
2382 ok(hdata == 0, "Expected 0, got %p, msg_index=%d\n", hdata, msg_index);
2383 ok(dwData1 != 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2384 ok(dwData2 == FALSE, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2, msg_index);
2386 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2387 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2388 test_topic, str, msg_index);
2389 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2391 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
2392 ok(!lstrcmpA(str, test_service), "Expected %s, got %s, msg_index=%d\n",
2393 test_service, str, msg_index);
2394 ok(size == 14, "Expected 14, got %d, msg_index=%d\n", size, msg_index);
2396 return (HDDEDATA) TRUE;
2398 case XTYP_CONNECT_CONFIRM:
2400 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
2401 conversation = hconv;
2402 return (HDDEDATA) TRUE;
2404 case XTYP_EXECUTE:
2406 BYTE *buffer = NULL;
2407 WCHAR *cmd_w;
2408 char test_cmd_w_to_a[64];
2409 WCHAR test_cmd_a_to_w[64];
2410 DWORD size_a, size_w, size_w_to_a, size_a_to_w;
2411 BOOL str_index;
2413 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
2414 ok(hconv == conversation, "Expected conversation handle, got %p, msg_index=%d\n",
2415 hconv, msg_index);
2416 ok(dwData1 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2417 ok(dwData2 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2, msg_index);
2418 ok(hsz2 == 0, "Expected 0, got %p, msg_index=%d\n", hsz2, msg_index);
2419 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2420 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2421 test_topic, str, msg_index);
2422 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2424 size = DdeGetData(hdata, NULL, 0, 0);
2425 ok((buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size)) != NULL, "should not be null\n");
2426 rsize = DdeGetData(hdata, buffer, size, 0);
2427 ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2428 size, rsize, msg_index);
2429 if (winetest_debug > 1) trace("msg %u strA \"%s\" strW %s\n", msg_index, buffer, wine_dbgstr_w((WCHAR*)buffer));
2431 str_index = msg_index - 4;
2432 cmd_w = test_cmd_w_to_w[str_index - 1];
2433 size_a = strlen(test_cmd_a_to_a) + 1;
2434 size_w = (lstrlenW(cmd_w) + 1) * sizeof(WCHAR);
2435 size_a_to_w = MultiByteToWideChar( CP_ACP, 0, test_cmd_a_to_a, -1, test_cmd_a_to_w,
2436 ARRAY_SIZE(test_cmd_a_to_w)) * sizeof(WCHAR);
2437 size_w_to_a = WideCharToMultiByte( CP_ACP, 0, cmd_w, -1,
2438 test_cmd_w_to_a, sizeof(test_cmd_w_to_a), NULL, NULL );
2439 switch (str_index)
2441 case 0: /* ASCII string */
2442 if (unicode_server)
2444 ok(size == size_a_to_w, "Wrong size %d/%d, msg_index=%d\n", size, size_a_to_w, msg_index);
2445 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2446 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2448 else if (unicode_client)
2450 /* ASCII string mapped W->A -> garbage */
2452 else
2454 ok(size == size_a, "Wrong size %d/%d, msg_index=%d\n", size, size_a, msg_index);
2455 ok(!lstrcmpA((CHAR*)buffer, test_cmd_a_to_a), "Expected %s, got %s, msg_index=%d\n",
2456 test_cmd_a_to_a, buffer, msg_index);
2458 break;
2460 case 1: /* Unicode string with only 8-bit chars */
2461 if (unicode_server)
2463 ok(size == size_w, "Wrong size %d/%d, msg_index=%d\n", size, size_w, msg_index);
2464 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2465 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2467 else
2469 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n",
2470 size, size_w_to_a, msg_index);
2471 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2472 test_cmd_w_to_a, buffer, msg_index);
2474 break;
2476 case 2: /* normal Unicode string */
2477 case 3: /* IsTextUnicode false negative */
2478 case 4: /* Chinese chars */
2479 if (unicode_server)
2481 /* double A->W mapping */
2482 /* NT uses the full size, XP+ only until the first null */
2483 DWORD nt_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, size_w, test_cmd_a_to_w,
2484 ARRAY_SIZE(test_cmd_a_to_w)) * sizeof(WCHAR);
2485 DWORD xp_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, -1, NULL, 0 ) * sizeof(WCHAR);
2486 ok(size == xp_size || broken(size == nt_size) ||
2487 broken(str_index == 4 && IsDBCSLeadByte(cmd_w[0])) /* East Asian */,
2488 "Wrong size %d/%d, msg_index=%d\n", size, size_a_to_w, msg_index);
2489 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2490 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2492 else if (unicode_client)
2494 ok(size == size_w_to_a, "Wrong size %d/%d, msg_index=%d\n", size, size_w_to_a, msg_index);
2495 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2496 test_cmd_w_to_a, buffer, msg_index);
2498 else
2500 ok(size == size_w, "Wrong size %d/%d, msg_index=%d\n", size, size_w, msg_index);
2501 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2502 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2504 break;
2505 case 5: /* Chinese with latin characters begin */
2506 if (unicode_server && unicode_client)
2508 todo_wine ok(size == size_w, "Wrong size %d expected %d, msg_index=%d\n", size, size_w, msg_index);
2509 MultiByteToWideChar(CP_ACP, 0, test_cmd_w_to_a, size_w, test_cmd_a_to_w,
2510 ARRAY_SIZE(test_cmd_a_to_w));
2511 todo_wine ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2512 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), wine_dbgstr_w((WCHAR *)buffer), msg_index);
2514 else if (unicode_server)
2516 todo_wine ok(size == size_w, "Wrong size %d expected %d, msg_index=%d\n", size, size_w, msg_index);
2517 MultiByteToWideChar(CP_ACP, 0, test_cmd_w_to_a, size_w, test_cmd_a_to_w,
2518 ARRAY_SIZE(test_cmd_a_to_w));
2519 if (!is_cjk())
2520 todo_wine ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w), "Expected %s, got %s, msg_index=%d\n",
2521 wine_dbgstr_w(test_cmd_a_to_w), wine_dbgstr_w((WCHAR*)buffer), msg_index);
2522 else
2523 todo_wine ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2524 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), wine_dbgstr_w((WCHAR *)buffer), msg_index);
2526 else if (unicode_client)
2528 ok(size == size_w_to_a, "Wrong size %d expected %d, msg_index=%d\n", size, size_w_to_a, msg_index);
2529 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2530 test_cmd_w_to_a, buffer, msg_index);
2532 else
2534 todo_wine ok(size == size_w_to_a || size == (size_w_to_a - 1), "Wrong size %d expected %d or %d, msg_index=%d\n",
2535 size, size_w_to_a, size_w_to_a - 1, msg_index);
2536 todo_wine ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2537 test_cmd_w_to_a, buffer, msg_index);
2539 break;
2541 default:
2542 ok( 0, "Invalid message %u\n", msg_index );
2543 break;
2545 HeapFree(GetProcessHeap(), 0, buffer);
2546 return (HDDEDATA) DDE_FACK;
2548 case XTYP_DISCONNECT:
2549 return (HDDEDATA) TRUE;
2551 default:
2552 ok(FALSE, "Unhandled msg: %08x, msg_index=%d\n", uType, msg_index);
2555 return NULL;
2558 static HDDEDATA CALLBACK client_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2559 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2560 ULONG_PTR dwData1, ULONG_PTR dwData2)
2562 switch (uType)
2564 case XTYP_DISCONNECT:
2565 return (HDDEDATA) TRUE;
2567 default:
2568 ok(FALSE, "Unhandled msg: %08x\n", uType);
2571 return NULL;
2574 static void test_end_to_end_client(BOOL type_a)
2576 DWORD i, ret, err;
2577 DWORD client_pid = 0;
2578 HSZ server, topic;
2579 HCONV hconv;
2580 HDDEDATA hdata;
2581 static const char test_service[] = "TestDDEService";
2582 static const WCHAR test_service_w[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2583 static const char test_topic[] = "TestDDETopic";
2584 static const WCHAR test_topic_w[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2586 if (type_a)
2587 ret = DdeInitializeA(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2588 else
2589 ret = DdeInitializeW(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2590 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2592 if (type_a)
2594 server = DdeCreateStringHandleA(client_pid, test_service, CP_WINANSI);
2595 topic = DdeCreateStringHandleA(client_pid, test_topic, CP_WINANSI);
2597 else {
2598 server = DdeCreateStringHandleW(client_pid, test_service_w, CP_WINUNICODE);
2599 topic = DdeCreateStringHandleW(client_pid, test_topic_w, CP_WINUNICODE);
2602 DdeGetLastError(client_pid);
2603 hconv = DdeConnect(client_pid, server, topic, NULL);
2604 if (broken(!hconv)) /* Windows 10 version 1607 */
2606 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(client_pid));
2607 DdeUninitialize(client_pid);
2608 return;
2610 ret = DdeGetLastError(client_pid);
2611 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2612 DdeFreeStringHandle(client_pid, server);
2614 /* Test both A and W data being passed to DdeClientTransaction */
2615 hdata = DdeClientTransaction((LPBYTE)test_cmd_a_to_a, sizeof(test_cmd_a_to_a),
2616 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2617 ok(hdata != NULL, "DdeClientTransaction failed\n");
2618 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2619 err = DdeGetLastError(client_pid);
2620 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2622 for (i = 0; i < ARRAY_SIZE(test_cmd_w_to_w); i++)
2624 hdata = DdeClientTransaction((LPBYTE)test_cmd_w_to_w[i],
2625 (lstrlenW(test_cmd_w_to_w[i]) + 1) * sizeof(WCHAR),
2626 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2627 ok(hdata != NULL, "DdeClientTransaction failed\n");
2628 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2629 err = DdeGetLastError(client_pid);
2630 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2633 DdeFreeStringHandle(client_pid, topic);
2634 ret = DdeDisconnect(hconv);
2635 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2637 ret = DdeUninitialize(client_pid);
2638 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2642 static void test_end_to_end_server(void)
2644 HANDLE client;
2645 MSG msg;
2646 HSZ server;
2647 BOOL ret;
2648 DWORD res;
2649 HDDEDATA hdata;
2650 static const char test_service[] = "TestDDEService";
2652 trace("client %s, server %s\n", unicode_client ? "unicode" : "ascii",
2653 unicode_server ? "unicode" : "ascii");
2654 server_pid = 0;
2655 msg_index = 0;
2657 if (unicode_server)
2658 res = DdeInitializeW(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2659 else
2660 res = DdeInitializeA(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2661 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
2663 server = DdeCreateStringHandleA(server_pid, test_service, CP_WINANSI);
2664 ok(server != NULL, "Expected non-NULL string handle\n");
2666 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
2667 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
2669 client = create_process(unicode_client ? "endw" : "enda");
2671 while (MsgWaitForMultipleObjects(1, &client, FALSE, INFINITE, QS_ALLINPUT) != 0)
2673 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2676 ret = DdeUninitialize(server_pid);
2677 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2678 GetExitCodeProcess(client, &res);
2679 ok( !res, "client failed with %u error(s)\n", res );
2680 CloseHandle(client);
2683 START_TEST(dde)
2685 int argc;
2686 char **argv;
2687 DWORD dde_inst = 0xdeadbeef;
2689 argc = winetest_get_mainargs(&argv);
2690 if (argc == 3)
2692 if (!lstrcmpA(argv[2], "ddeml"))
2693 test_ddeml_client();
2694 else if (!lstrcmpA(argv[2], "msg"))
2695 test_msg_client();
2696 else if (!lstrcmpA(argv[2], "enda"))
2697 test_end_to_end_client(TRUE);
2698 else if (!lstrcmpA(argv[2], "endw"))
2699 test_end_to_end_client(FALSE);
2701 return;
2704 test_initialisation();
2706 DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2708 test_msg_server();
2709 test_ddeml_server();
2711 /* Test the combinations of A and W interfaces with A and W data
2712 end to end to ensure that data conversions are accurate */
2713 unicode_client = unicode_server = FALSE;
2714 test_end_to_end_server();
2715 unicode_client = unicode_server = TRUE;
2716 test_end_to_end_server();
2717 unicode_client = FALSE;
2718 unicode_server = TRUE;
2719 test_end_to_end_server();
2720 unicode_client = TRUE;
2721 unicode_server = FALSE;
2722 test_end_to_end_server();
2724 test_dde_aw_transaction( FALSE, TRUE );
2725 test_dde_aw_transaction( TRUE, FALSE );
2726 test_dde_aw_transaction( TRUE, TRUE );
2727 test_dde_aw_transaction( FALSE, FALSE );
2729 test_dde_aw_transaction( FALSE, TRUE );
2730 test_dde_aw_transaction( TRUE, FALSE );
2731 test_dde_aw_transaction( TRUE, TRUE );
2732 test_dde_aw_transaction( FALSE, FALSE );
2734 test_DdeCreateDataHandle();
2735 test_DdeCreateStringHandle();
2736 test_FreeDDElParam();
2737 test_PackDDElParam();
2738 test_UnpackDDElParam();