wined3d/glsl: Flush NaN to zero in ftoi.
[wine.git] / dlls / user32 / tests / dde.c
blobcd97bef165d0071be9bb421ccea0d6dbec89ea89
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: %lu\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 %08Ix\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 %08Ix\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 %ld\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 %08Ix\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 %08Ix\n", wparam);
253 ok(lparam == 0, "Expected 0, got %08Ix\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 %lu 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 %08lx\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 %ld\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 %lx\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 %ld\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 %lx\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 %ld\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 %08lx\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 %ld\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 %ld\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 %lx\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 %lx\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 %lx\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %ld\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 %08Ix\n", dwData1);
608 ok(dwData2 == 0, "Expected 0, got %08Ix\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 %ld\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 %ld 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 %08Ix\n", dwData1);
629 ok(dwData2 == FALSE, "Expected FALSE, got %08Ix\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 %ld\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 %ld\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 %08Ix\n", dwData1);
651 ok(dwData2 == FALSE, "Expected FALSE, got %08Ix\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 %ld\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 %ld\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 %08Ix\n", dwData1);
671 ok(dwData2 == 0, "Expected 0, got %08Ix\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 %ld\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 %ld\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 %ld\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 %08Ix\n", dwData1);
713 ok(dwData2 == 0, "Expected 0, got %08Ix\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 %ld\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 %ld\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 %ld\n", size);
732 else
734 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
735 ok(size == 4, "Expected 4, got %ld\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 %08Ix\n", dwData1);
747 ok(dwData2 == 0, "Expected 0, got %08Ix\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 %ld\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 %ld\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 %ld\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 %ld\n", size);
779 ptr = malloc(size);
780 ok(ptr != NULL, "malloc should have returned ptr not NULL\n");
781 rsize = DdeGetData(hdata, (LPBYTE)ptr, size, 0);
782 ok(rsize == size, "DdeGetData did not return %ld bytes but %ld\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 %ld\n", size);
786 ret = (HDDEDATA)DDE_FACK;
788 free(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 %08Ix\n", dwData1);
800 ok(dwData2 == 0, "Expected 0, got %08Ix\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 DWORD exit_code;
820 BOOL ret;
821 HSZ server;
822 HDDEDATA hdata;
824 client = create_process("msg");
826 /* set up DDE server */
827 server_pid = 0;
828 res = DdeInitializeA(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
829 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
831 server = DdeCreateStringHandleA(server_pid, "TestDDEServer", CP_WINANSI);
832 ok(server != NULL, "Expected non-NULL string handle\n");
834 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
835 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
837 while (MsgWaitForMultipleObjects(1, &client, FALSE, INFINITE, QS_ALLINPUT) != 0)
839 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
841 ret = DdeUninitialize(server_pid);
842 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
843 GetExitCodeProcess(client, &exit_code);
844 ok( !res, "client failed with %lu error(s)\n", exit_code );
845 CloseHandle(client);
848 static HWND client_hwnd, server_hwnd;
849 static ATOM server, topic, item;
850 static HGLOBAL execute_hglobal;
852 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
854 char str[MAX_PATH];
855 UINT_PTR lo, hi;
856 DDEDATA *data;
857 DDEACK *ack;
858 DWORD size;
859 LPSTR ptr;
861 static int msg_index = 0;
863 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
864 return DefWindowProcA(hwnd, msg, wparam, lparam);
866 msg_index++;
868 switch (msg)
870 case WM_DDE_INITIATE:
872 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
873 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08Ix\n", wparam);
875 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
876 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
877 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
878 ok(size == 13, "Expected 13, got %ld\n", size);
880 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
881 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
882 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
883 ok(size == 12, "Expected 12, got %ld\n", size);
885 break;
888 case WM_DDE_ACK:
890 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 11),
891 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index);
893 if (msg_index == 2)
895 server_hwnd = (HWND)wparam;
896 ok(wparam != 0, "Expected non-NULL wparam, got %08Ix\n", wparam);
898 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
899 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
900 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
901 ok(size == 13, "Expected 13, got %ld\n", size);
903 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
904 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
905 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
906 ok(size == 12, "Expected 12, got %ld\n", size);
908 else if (msg_index >= 9 && msg_index <= 11)
910 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08Ix\n", wparam);
912 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
914 ack = (DDEACK *)&lo;
915 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
916 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
917 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
919 ok(hi == (UINT_PTR)execute_hglobal, "Expected execute hglobal, got %08Ix\n", hi);
920 ptr = GlobalLock((HGLOBAL)hi);
922 if (msg_index == 9)
924 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
925 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
926 } else if (msg_index == 10)
928 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
929 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr);
931 else
933 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
934 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
937 GlobalUnlock((HGLOBAL)hi);
939 else
941 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08Ix\n", wparam);
943 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
945 ack = (DDEACK *)&lo;
946 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
947 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
948 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
950 if (msg_index >= 7)
951 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
952 else
954 if (msg_index == 6) todo_wine
955 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
958 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
959 if (msg_index == 3)
961 ok(hi == item, "Expected item atom, got %08Ix\n", hi);
962 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
963 ok(size == 7, "Expected 7, got %ld\n", size);
965 else if (msg_index == 4 || msg_index == 7)
967 ok(hi == 0, "Expected 0, got %08Ix\n", hi);
968 ok(size == 0, "Expected empty string, got %ld\n", size);
970 else
972 ok(hi == item, "Expected item atom, got %08Ix\n", hi);
973 if (msg_index == 6) todo_wine
975 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
976 ok(size == 4, "Expected 4, got %ld\n", size);
981 break;
984 case WM_DDE_DATA:
986 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
987 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08Ix\n", wparam);
989 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
991 data = GlobalLock((HGLOBAL)lo);
992 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
993 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
994 todo_wine
996 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
998 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
999 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
1000 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
1001 "Expected 'requested data\\r\\n', got %s\n", data->Value);
1002 GlobalUnlock((HGLOBAL)lo);
1004 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
1005 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
1006 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
1007 ok(size == 7, "Expected 7, got %ld\n", size);
1009 GlobalFree((HGLOBAL)lo);
1010 GlobalDeleteAtom(hi);
1012 break;
1015 default:
1016 ok(FALSE, "Unhandled msg: %08x\n", msg);
1019 return DefWindowProcA(hwnd, msg, wparam, lparam);
1022 static HGLOBAL create_poke(void)
1024 HGLOBAL hglobal;
1025 DDEPOKE *poke;
1026 DWORD size;
1028 size = FIELD_OFFSET(DDEPOKE, Value[sizeof("poke data\r\n")]);
1029 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
1030 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1032 poke = GlobalLock(hglobal);
1033 poke->unused = 0;
1034 poke->fRelease = TRUE;
1035 poke->fReserved = TRUE;
1036 poke->cfFormat = CF_TEXT;
1037 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
1038 GlobalUnlock(hglobal);
1040 return hglobal;
1043 static HGLOBAL create_execute(LPCSTR command)
1045 HGLOBAL hglobal;
1046 LPSTR ptr;
1048 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1049 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1051 ptr = GlobalLock(hglobal);
1052 lstrcpyA(ptr, command);
1053 GlobalUnlock(hglobal);
1055 return hglobal;
1058 static void test_msg_client(void)
1060 HGLOBAL hglobal;
1061 LPARAM lparam;
1063 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1065 server = GlobalAddAtomA("TestDDEServer");
1066 ok(server != 0, "Expected non-NULL server\n");
1068 topic = GlobalAddAtomA("TestDDETopic");
1069 ok(topic != 0, "Expected non-NULL topic\n");
1071 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1073 GlobalDeleteAtom(server);
1074 GlobalDeleteAtom(topic);
1076 flush_events();
1078 item = GlobalAddAtomA("request");
1079 ok(item != 0, "Expected non-NULL item\n");
1081 /* WM_DDE_REQUEST, bad clipboard format */
1082 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1083 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1085 flush_events();
1087 /* WM_DDE_REQUEST, no item */
1088 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1089 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1091 flush_events();
1093 /* WM_DDE_REQUEST, no client hwnd */
1094 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1095 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1097 flush_events();
1099 /* WM_DDE_REQUEST, correct params */
1100 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1101 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1103 flush_events();
1105 GlobalDeleteAtom(item);
1106 item = GlobalAddAtomA("poke");
1107 ok(item != 0, "Expected non-NULL item\n");
1109 hglobal = create_poke();
1111 /* WM_DDE_POKE, no ddepoke */
1112 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1113 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1114 flush_events();
1116 /* WM_DDE_POKE, no item */
1117 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1118 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1120 flush_events();
1122 hglobal = create_poke();
1124 /* WM_DDE_POKE, no client hwnd */
1125 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1126 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1128 flush_events();
1130 /* WM_DDE_POKE, all params correct */
1131 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1132 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1134 flush_events();
1136 execute_hglobal = create_execute("[Command(Var)]");
1138 /* WM_DDE_EXECUTE, no lparam */
1139 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1141 flush_events();
1143 /* WM_DDE_EXECUTE, no hglobal */
1144 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1145 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1147 flush_events();
1149 /* WM_DDE_EXECUTE, no client hwnd */
1150 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1151 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1153 flush_events();
1155 /* WM_DDE_EXECUTE, all params correct */
1156 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1157 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1159 flush_events();
1161 GlobalFree(execute_hglobal);
1162 execute_hglobal = create_execute("[Command-2(Var)]");
1164 /* WM_DDE_EXECUTE, all params correct */
1165 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1166 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1168 flush_events();
1170 GlobalFree(execute_hglobal);
1171 execute_hglobal = create_execute("[BadCommand(Var)]");
1173 /* WM_DDE_EXECUTE that will get rejected */
1174 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1175 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1177 flush_events();
1179 destroy_dde_window(&client_hwnd, "dde_client");
1182 static LRESULT WINAPI hook_dde_client_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1184 UINT_PTR lo, hi;
1186 if (winetest_debug > 1) trace("hook_dde_client_wndprocA: %p %04x %08Ix %08Ix\n", hwnd, msg, wparam, lparam);
1188 switch (msg)
1190 case WM_DDE_ACK:
1191 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1192 if (winetest_debug > 1) trace("WM_DDE_ACK: status %04Ix hglobal %p\n", lo, (HGLOBAL)hi);
1193 break;
1195 default:
1196 break;
1198 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1201 static LRESULT WINAPI hook_dde_client_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1203 UINT_PTR lo, hi;
1205 if (winetest_debug > 1) trace("hook_dde_client_wndprocW: %p %04x %08Ix %08Ix\n", hwnd, msg, wparam, lparam);
1207 switch (msg)
1209 case WM_DDE_ACK:
1210 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1211 if (winetest_debug > 1) trace("WM_DDE_ACK: status %04Ix hglobal %p\n", lo, (HGLOBAL)hi);
1212 break;
1214 default:
1215 break;
1217 return CallWindowProcW(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1220 static LRESULT WINAPI dde_server_wndprocA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1222 static BOOL client_unicode, conv_unicode;
1223 static int step;
1225 switch (msg)
1227 case WM_DDE_INITIATE:
1229 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1231 if (winetest_debug > 1) trace("server A: got WM_DDE_INITIATE from %p (%s) with %08Ix\n",
1232 (HWND)wparam, client_unicode ? "Unicode" : "ANSI", lparam);
1234 if (LOWORD(lparam) == aService)
1236 client_unicode = IsWindowUnicode((HWND)wparam);
1237 conv_unicode = client_unicode;
1238 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1240 if (client_unicode)
1241 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1242 (ULONG_PTR)hook_dde_client_wndprocW);
1243 else
1244 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1245 (ULONG_PTR)hook_dde_client_wndprocA);
1246 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1248 else
1249 GlobalDeleteAtom(aService);
1250 return 0;
1253 case WM_DDE_EXECUTE:
1255 DDEACK ack;
1256 WORD status;
1257 LPCSTR cmd;
1258 UINT_PTR lo, hi;
1260 if (winetest_debug > 1) trace("server A: got WM_DDE_EXECUTE from %p with %08Ix\n", (HWND)wparam, lparam);
1262 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1263 if (winetest_debug > 1) trace("%08Ix => lo %04Ix hi %04Ix\n", lparam, lo, hi);
1265 ack.bAppReturnCode = 0;
1266 ack.reserved = 0;
1267 ack.fBusy = 0;
1268 /* We have to send a negative acknowledge even if we don't
1269 * accept the command, otherwise Windows goes mad and next time
1270 * we send an acknowledge DDEML drops the connection.
1271 * Not sure how to call it: a bug or a feature.
1273 ack.fAck = 0;
1275 if ((cmd = GlobalLock((HGLOBAL)hi)))
1277 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1279 switch (step % 5)
1281 case 0: /* bad command */
1282 break;
1284 case 1: /* ANSI command */
1285 if (!conv_unicode)
1286 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1287 else /* we get garbage as the A command was mapped W->A */
1288 ok( cmd[0] != exec_cmdA[0], "server A got wrong command '%s'\n", cmd );
1289 break;
1291 case 2: /* ANSI command in Unicode format */
1292 if (conv_unicode)
1293 ok( !lstrcmpA(cmd, exec_cmdA), "server A got wrong command '%s'\n", cmd );
1294 else
1295 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server A got wrong command '%s'\n", cmd );
1296 break;
1298 case 3: /* Unicode command */
1299 if (!conv_unicode)
1300 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server A got wrong command '%s'\n", cmd );
1301 else /* correctly mapped W->A */
1302 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1303 break;
1305 case 4: /* Unicode command in ANSI format */
1306 if (!conv_unicode)
1307 ok( !lstrcmpA(cmd, exec_cmdWA), "server A got wrong command '%s'\n", cmd );
1308 else /* we get garbage as the A command was mapped W->A */
1309 ok( cmd[0] != exec_cmdWA[0], "server A got wrong command '%s'\n", cmd );
1310 break;
1312 GlobalUnlock((HGLOBAL)hi);
1314 else ok( 0, "bad command data %Ix\n", hi );
1316 step++;
1318 status = *((WORD *)&ack);
1319 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1321 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1322 return 0;
1325 case WM_DDE_TERMINATE:
1327 DDEACK ack;
1328 WORD status;
1330 if (winetest_debug > 1) trace("server A: got WM_DDE_TERMINATE from %#Ix with %08Ix\n", wparam, lparam);
1332 ack.bAppReturnCode = 0;
1333 ack.reserved = 0;
1334 ack.fBusy = 0;
1335 ack.fAck = 1;
1337 status = *((WORD *)&ack);
1338 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1340 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1341 return 0;
1344 default:
1345 break;
1348 return DefWindowProcA(hwnd, msg, wparam, lparam);
1351 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1353 static BOOL client_unicode, conv_unicode;
1354 static int step;
1356 switch (msg)
1358 case WM_DDE_INITIATE:
1360 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1362 if (LOWORD(lparam) == aService)
1364 client_unicode = IsWindowUnicode((HWND)wparam);
1365 conv_unicode = client_unicode;
1366 if (step >= 10) client_unicode = !client_unicode; /* change the client window type */
1368 if (client_unicode)
1369 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrW((HWND)wparam, GWLP_WNDPROC,
1370 (ULONG_PTR)hook_dde_client_wndprocW);
1371 else
1372 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC,
1373 (ULONG_PTR)hook_dde_client_wndprocA);
1374 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, PackDDElParam(WM_DDE_ACK, aService, 0));
1376 else
1377 GlobalDeleteAtom(aService);
1379 if (winetest_debug > 1)
1380 trace("server W: got WM_DDE_INITIATE from %p with %08Ix (client %s conv %s)\n", (HWND)wparam,
1381 lparam, client_unicode ? "Unicode" : "ANSI", conv_unicode ? "Unicode" : "ANSI" );
1383 return 0;
1386 case WM_DDE_EXECUTE:
1388 DDEACK ack;
1389 WORD status;
1390 LPCSTR cmd;
1391 UINT_PTR lo, hi;
1393 if (winetest_debug > 1) trace("server W: got WM_DDE_EXECUTE from %#Ix with %08Ix\n", wparam, lparam);
1395 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1396 if (winetest_debug > 1) trace("%08Ix => lo %04Ix hi %04Ix\n", lparam, lo, hi);
1398 ack.bAppReturnCode = 0;
1399 ack.reserved = 0;
1400 ack.fBusy = 0;
1401 /* We have to send a negative acknowledge even if we don't
1402 * accept the command, otherwise Windows goes mad and next time
1403 * we send an acknowledge DDEML drops the connection.
1404 * Not sure how to call it: a bug or a feature.
1406 ack.fAck = 0;
1408 if ((cmd = GlobalLock((HGLOBAL)hi)))
1410 ack.fAck = !lstrcmpA(cmd, exec_cmdA) || !lstrcmpW((LPCWSTR)cmd, exec_cmdW);
1412 switch (step % 5)
1414 case 0: /* bad command */
1415 break;
1417 case 1: /* ANSI command */
1418 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1419 ok( cmd[0] != exec_cmdA[0], "server W got wrong command '%s'\n", cmd );
1420 else if (!conv_unicode && client_unicode) /* A->W mapping */
1421 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1422 else
1423 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1424 break;
1426 case 2: /* ANSI command in Unicode format */
1427 if (conv_unicode && !client_unicode) /* W->A mapping */
1428 ok( !lstrcmpA(cmd, exec_cmdA), "server W got wrong command '%s'\n", cmd );
1429 else if (!conv_unicode && client_unicode) /* A->W mapping */
1430 ok( *(WCHAR *)cmd == exec_cmdAW[0], "server W got wrong command '%s'\n", cmd );
1431 else
1432 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdAW), "server W got wrong command '%s'\n", cmd );
1433 break;
1435 case 3: /* Unicode command */
1436 if (conv_unicode && !client_unicode) /* W->A mapping */
1437 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1438 else if (!conv_unicode && client_unicode) /* A->W mapping */
1439 ok( *(WCHAR *)cmd == exec_cmdW[0], "server W got wrong command '%s'\n", cmd );
1440 else
1441 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1442 break;
1444 case 4: /* Unicode command in ANSI format */
1445 if (conv_unicode && !client_unicode) /* W->A mapping -> garbage */
1446 ok( cmd[0] != exec_cmdWA[0], "server W got wrong command '%s'\n", cmd );
1447 else if (!conv_unicode && client_unicode) /* A->W mapping */
1448 ok( !lstrcmpW((LPCWSTR)cmd, exec_cmdW), "server W got wrong command '%s'\n", cmd );
1449 else
1450 ok( !lstrcmpA(cmd, exec_cmdWA), "server W got wrong command '%s'\n", cmd );
1451 break;
1453 GlobalUnlock((HGLOBAL)hi);
1455 else ok( 0, "bad command data %Ix\n", hi );
1457 step++;
1459 status = *((WORD *)&ack);
1460 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1462 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1463 return 0;
1466 case WM_DDE_TERMINATE:
1468 DDEACK ack;
1469 WORD status;
1471 if (winetest_debug > 1) trace("server W: got WM_DDE_TERMINATE from %#Ix with %08Ix\n", wparam, lparam);
1473 ack.bAppReturnCode = 0;
1474 ack.reserved = 0;
1475 ack.fBusy = 0;
1476 ack.fAck = 1;
1478 status = *((WORD *)&ack);
1479 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1481 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1482 return 0;
1485 default:
1486 break;
1489 return DefWindowProcW(hwnd, msg, wparam, lparam);
1492 static HWND create_dde_server( BOOL unicode )
1494 WNDCLASSA wcA;
1495 WNDCLASSW wcW;
1496 HWND server;
1497 static const char server_class_nameA[] = "dde_server_windowA";
1498 static const WCHAR server_class_nameW[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w','W',0};
1500 if (unicode)
1502 memset(&wcW, 0, sizeof(wcW));
1503 wcW.lpfnWndProc = dde_server_wndprocW;
1504 wcW.lpszClassName = server_class_nameW;
1505 wcW.hInstance = GetModuleHandleA(0);
1506 RegisterClassW(&wcW);
1508 server = CreateWindowExW(0, server_class_nameW, NULL, WS_POPUP,
1509 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1510 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1512 else
1514 memset(&wcA, 0, sizeof(wcA));
1515 wcA.lpfnWndProc = dde_server_wndprocA;
1516 wcA.lpszClassName = server_class_nameA;
1517 wcA.hInstance = GetModuleHandleA(0);
1518 RegisterClassA(&wcA);
1520 server = CreateWindowExA(0, server_class_nameA, NULL, WS_POPUP,
1521 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1522 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
1524 ok(!IsWindowUnicode(server) == !unicode, "wrong unicode type\n");
1525 return server;
1528 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1529 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1530 ULONG_PTR dwData1, ULONG_PTR dwData2)
1532 static const char * const cmd_type[15] = {
1533 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1534 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1535 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1536 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1537 UINT type;
1538 const char *cmd_name;
1540 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1541 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1543 if (winetest_debug > 1)
1544 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08Ix %08Ix\n",
1545 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1546 return 0;
1549 static void test_dde_aw_transaction( BOOL client_unicode, BOOL server_unicode )
1551 HSZ hsz_server;
1552 DWORD dde_inst, ret, err;
1553 HCONV hconv;
1554 HWND hwnd_server;
1555 CONVINFO info;
1556 HDDEDATA hdata;
1557 BOOL conv_unicode = client_unicode;
1558 BOOL got;
1559 static char test_cmd[] = "test dde command";
1561 if (!(hwnd_server = create_dde_server( server_unicode ))) return;
1563 dde_inst = 0;
1564 if (client_unicode)
1565 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1566 else
1567 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1568 ok(ret == DMLERR_NO_ERROR, "DdeInitializeA failed with error %04lx (%x)\n",
1569 ret, DdeGetLastError(dde_inst));
1571 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1573 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1574 if (broken(!hconv)) /* Windows 10 version 1607 */
1576 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(dde_inst));
1577 DdeUninitialize(dde_inst);
1578 return;
1580 err = DdeGetLastError(dde_inst);
1581 ok(err == DMLERR_NO_ERROR, "wrong dde error %lx\n", err);
1583 info.cb = sizeof(info);
1584 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1585 ok(ret, "wrong info size %ld, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1586 ok(info.ConvCtxt.iCodePage == (client_unicode ? CP_WINUNICODE : CP_WINANSI),
1587 "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1588 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1589 todo_wine {
1590 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1592 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1593 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1594 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1596 client_unicode = IsWindowUnicode( info.hwnd );
1598 ret = 0xdeadbeef;
1599 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1600 ok(!hdata, "DdeClientTransaction succeeded\n");
1601 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1602 err = DdeGetLastError(dde_inst);
1603 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %lx\n", err);
1605 ret = 0xdeadbeef;
1606 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1607 err = DdeGetLastError(dde_inst);
1608 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1610 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1611 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1612 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1614 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> wrong cmd */
1616 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1617 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1618 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1620 else /* no mapping */
1622 ok(hdata != 0, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1623 ok(ret == DDE_FACK, "wrong status code %04lx\n", ret);
1624 ok(err == DMLERR_NO_ERROR, "wrong dde error %lx\n", err);
1627 ret = 0xdeadbeef;
1628 hdata = DdeClientTransaction((LPBYTE)exec_cmdAW, (lstrlenW(exec_cmdAW) + 1) * sizeof(WCHAR),
1629 hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1630 err = DdeGetLastError(dde_inst);
1631 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping */
1633 ok(hdata != 0, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1634 ok(ret == DDE_FACK, "wrong status code %04lx\n", ret);
1635 ok(err == DMLERR_NO_ERROR, "wrong dde error %lx\n", err);
1637 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1639 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1640 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1641 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1643 else /* no mapping */
1645 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1646 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1647 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1650 ret = 0xdeadbeef;
1651 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1652 err = DdeGetLastError(dde_inst);
1653 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> wrong cmd */
1655 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1656 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1657 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1659 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping -> garbage */
1661 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1662 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1663 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1665 else /* no mapping */
1667 ok(hdata != 0, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1668 ok(ret == DDE_FACK, "wrong status code %04lx\n", ret);
1669 ok(err == DMLERR_NO_ERROR, "wrong dde error %lx\n", err);
1672 ret = 0xdeadbeef;
1673 hdata = DdeClientTransaction((LPBYTE)exec_cmdWA, lstrlenA(exec_cmdWA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1674 err = DdeGetLastError(dde_inst);
1675 if (conv_unicode && (!client_unicode || !server_unicode)) /* W->A mapping -> garbage */
1677 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1678 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1679 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1681 else if (!conv_unicode && client_unicode && server_unicode) /* A->W mapping */
1683 ok(hdata != 0, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1684 ok(ret == DDE_FACK, "wrong status code %04lx\n", ret);
1685 ok(err == DMLERR_NO_ERROR, "wrong dde error %lx\n", err);
1687 else /* no mapping */
1689 ok(!hdata, "DdeClientTransaction returned %p, error %lx\n", hdata, err);
1690 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04lx\n", ret);
1691 ok(err == DMLERR_NOTPROCESSED, "DdeClientTransaction returned error %lx\n", err);
1694 got = DdeDisconnect(hconv);
1695 ok(got, "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1697 info.cb = sizeof(info);
1698 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1699 ok(!ret, "DdeQueryConvInfo should fail\n");
1700 err = DdeGetLastError(dde_inst);
1701 todo_wine {
1702 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %lx\n", err);
1705 got = DdeFreeStringHandle(dde_inst, hsz_server);
1706 ok(got, "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1708 /* This call hangs on win2k SP4 and XP SP1.
1709 DdeUninitialize(dde_inst);*/
1711 DestroyWindow(hwnd_server);
1714 static void test_initialisation(void)
1716 UINT ret;
1717 DWORD res;
1718 HDDEDATA hdata;
1719 HSZ server, topic, item;
1720 DWORD client_pid;
1721 HCONV conversation;
1723 /* Initialise without a valid server window. */
1724 client_pid = 0;
1725 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1726 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
1729 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
1730 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
1732 DdeGetLastError(client_pid);
1734 /* There is no server window so no conversation can be extracted */
1735 conversation = DdeConnect(client_pid, server, topic, NULL);
1736 ok(conversation == NULL, "Expected NULL conversation, %p\n", conversation);
1737 ret = DdeGetLastError(client_pid);
1738 ok(ret == DMLERR_NO_CONV_ESTABLISHED, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret);
1740 DdeFreeStringHandle(client_pid, server);
1742 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
1744 /* There is no conversation so an invalid parameter results */
1745 res = 0xdeadbeef;
1746 DdeGetLastError(client_pid);
1747 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
1748 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1749 ret = DdeGetLastError(client_pid);
1750 todo_wine
1751 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
1752 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", res);
1754 DdeFreeStringHandle(client_pid, server);
1755 ret = DdeDisconnect(conversation);
1756 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1758 ret = DdeUninitialize(client_pid);
1759 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1762 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1764 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1765 HSZ str_handle;
1766 WCHAR bufW[256];
1767 char buf[256];
1768 ATOM atom;
1769 int ret;
1771 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1772 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1773 DdeGetLastError(dde_inst));
1775 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1776 if (codepage == CP_WINANSI)
1777 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1778 else
1779 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1781 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1782 if (codepage == CP_WINANSI)
1784 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1785 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1787 else
1789 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1790 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1793 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1794 if (codepage == CP_WINANSI)
1796 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1797 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1799 else
1801 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1802 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1805 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1806 if (codepage == CP_WINANSI)
1808 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1809 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1811 else
1813 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1814 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1817 if (codepage == CP_WINANSI)
1819 atom = FindAtomA((LPSTR)dde_string);
1820 ok(atom != 0, "Expected a valid atom\n");
1822 SetLastError(0xdeadbeef);
1823 atom = GlobalFindAtomA((LPSTR)dde_string);
1824 ok(atom == 0, "Expected 0, got %d\n", atom);
1825 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1826 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
1828 else
1830 atom = FindAtomW(dde_string);
1831 ok(atom != 0, "Expected a valid atom\n");
1833 SetLastError(0xdeadbeef);
1834 atom = GlobalFindAtomW(dde_string);
1835 ok(atom == 0, "Expected 0, got %d\n", atom);
1836 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1837 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
1840 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1843 static void test_DdeCreateDataHandle(void)
1845 HDDEDATA hdata;
1846 DWORD dde_inst, dde_inst2;
1847 DWORD size;
1848 UINT res, err;
1849 BOOL ret;
1850 HSZ item;
1851 LPBYTE ptr;
1852 WCHAR item_str[] = {'i','t','e','m',0};
1854 dde_inst = 0;
1855 dde_inst2 = 0;
1856 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1857 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1859 res = DdeInitializeA(&dde_inst2, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1860 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1862 /* 0 instance id
1863 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1864 * is invalid then the lastError of all instances is set to the error. There are two instances
1865 * created, lastError is cleared, an error is generated and then both instances are checked to
1866 * ensure that they both have the same error set
1868 item = DdeCreateStringHandleA(0, "item", CP_WINANSI);
1869 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1870 err = DdeGetLastError(dde_inst);
1871 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1872 err = DdeGetLastError(dde_inst2);
1873 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1874 item = DdeCreateStringHandleW(0, item_str, CP_WINUNICODE);
1875 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1876 err = DdeGetLastError(dde_inst);
1877 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1878 err = DdeGetLastError(dde_inst2);
1879 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1881 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1882 ok(item != NULL, "Expected non-NULL hsz\n");
1883 item = DdeCreateStringHandleA(dde_inst2, "item", CP_WINANSI);
1884 ok(item != NULL, "Expected non-NULL hsz\n");
1886 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1888 /* 0 instance id
1889 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1890 * is invalid then the lastError of all instances is set to the error. There are two instances
1891 * created, lastError is cleared, an error is generated and then both instances are checked to
1892 * ensure that they both have the same error set
1894 DdeGetLastError(dde_inst);
1895 DdeGetLastError(dde_inst2);
1896 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1897 err = DdeGetLastError(dde_inst);
1898 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1899 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1900 err = DdeGetLastError(dde_inst2);
1901 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1903 ret = DdeUninitialize(dde_inst2);
1904 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1907 /* NULL pSrc */
1908 DdeGetLastError(dde_inst);
1909 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1910 err = DdeGetLastError(dde_inst);
1911 ok(hdata != NULL, "Expected non-NULL hdata\n");
1912 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1914 ptr = DdeAccessData(hdata, &size);
1915 ok(ptr != NULL, "Expected non-NULL ptr\n");
1916 ok(size == 260, "Expected 260, got %ld\n", size);
1918 ret = DdeUnaccessData(hdata);
1919 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1921 ret = DdeFreeDataHandle(hdata);
1922 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1924 /* cb is zero */
1925 DdeGetLastError(dde_inst);
1926 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1927 err = DdeGetLastError(dde_inst);
1928 ok(hdata != NULL, "Expected non-NULL hdata\n");
1929 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1931 ptr = DdeAccessData(hdata, &size);
1932 ok(ptr != NULL, "Expected non-NULL ptr\n");
1933 ok(size == 0, "Expected 0, got %ld\n", size);
1935 ret = DdeUnaccessData(hdata);
1936 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1938 ret = DdeFreeDataHandle(hdata);
1939 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1941 /* cbOff is non-zero */
1942 DdeGetLastError(dde_inst);
1943 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1944 err = DdeGetLastError(dde_inst);
1945 ok(hdata != NULL, "Expected non-NULL hdata\n");
1946 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1948 ptr = DdeAccessData(hdata, &size);
1949 ok(ptr != NULL, "Expected non-NULL ptr\n");
1950 ok(size == 262, "Expected 262, got %ld\n", size);
1951 todo_wine
1953 ok(ptr && !*ptr, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1956 ret = DdeUnaccessData(hdata);
1957 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1959 ret = DdeFreeDataHandle(hdata);
1960 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1962 /* NULL item */
1963 DdeGetLastError(dde_inst);
1964 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1965 err = DdeGetLastError(dde_inst);
1966 ok(hdata != NULL, "Expected non-NULL hdata\n");
1967 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1969 ptr = DdeAccessData(hdata, &size);
1970 ok(ptr != NULL, "Expected non-NULL ptr\n");
1971 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1972 ok(size == 260, "Expected 260, got %ld\n", size);
1974 ret = DdeUnaccessData(hdata);
1975 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1977 ret = DdeFreeDataHandle(hdata);
1978 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1980 /* NULL item */
1981 DdeGetLastError(dde_inst);
1982 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1983 err = DdeGetLastError(dde_inst);
1984 ok(hdata != NULL, "Expected non-NULL hdata\n");
1985 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1987 ptr = DdeAccessData(hdata, &size);
1988 ok(ptr != NULL, "Expected non-NULL ptr\n");
1989 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1990 ok(size == 260, "Expected 260, got %ld\n", size);
1992 ret = DdeUnaccessData(hdata);
1993 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1995 ret = DdeFreeDataHandle(hdata);
1996 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1998 /* invalid clipboard format */
1999 DdeGetLastError(dde_inst);
2000 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
2001 err = DdeGetLastError(dde_inst);
2002 ok(hdata != NULL, "Expected non-NULL hdata\n");
2003 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
2005 ptr = DdeAccessData(hdata, &size);
2006 ok(ptr != NULL, "Expected non-NULL ptr\n");
2007 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
2008 ok(size == 260, "Expected 260, got %ld\n", size);
2010 ret = DdeUnaccessData(hdata);
2011 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2013 ret = DdeFreeDataHandle(hdata);
2014 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2016 ret = DdeUninitialize(dde_inst);
2017 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2020 static void test_DdeCreateStringHandle(void)
2022 DWORD dde_inst, ret;
2024 dde_inst = 0xdeadbeef;
2025 SetLastError(0xdeadbeef);
2026 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2027 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04lx instead\n", ret);
2028 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
2030 dde_inst = 0;
2031 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2032 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04lx (%08x)\n",
2033 ret, DdeGetLastError(dde_inst));
2035 test_DdeCreateStringHandleW(dde_inst, 0);
2036 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
2037 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
2039 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
2042 static void test_FreeDDElParam(void)
2044 HGLOBAL val, hglobal;
2045 BOOL ret;
2047 ret = FreeDDElParam(WM_DDE_INITIATE, 0);
2048 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2050 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2051 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
2052 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2053 val = GlobalFree(hglobal);
2054 ok(val == NULL, "Expected NULL, got %p\n", val);
2056 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2057 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
2058 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2060 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2061 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
2062 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2063 val = GlobalFree(hglobal);
2064 ok(val == NULL, "Expected NULL, got %p\n", val);
2066 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2067 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
2068 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2070 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2071 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
2072 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2074 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2075 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
2076 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2077 val = GlobalFree(hglobal);
2078 ok(val == NULL, "Expected NULL, got %p\n", val);
2080 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2081 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
2082 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2084 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
2085 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
2086 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2087 val = GlobalFree(hglobal);
2088 ok(val == NULL, "Expected NULL, got %p\n", val);
2091 static void test_PackDDElParam(void)
2093 UINT_PTR lo, hi, *ptr;
2094 LPARAM lparam;
2095 BOOL ret;
2097 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
2098 /* value gets sign-extended despite being an LPARAM */
2099 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam);
2101 lo = hi = 0;
2102 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
2103 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2104 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2105 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2107 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
2108 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2110 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
2111 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam);
2113 lo = hi = 0;
2114 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
2115 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2116 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2117 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2119 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
2120 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2122 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
2123 ptr = GlobalLock((HGLOBAL)lparam);
2124 ok(ptr != NULL, "Expected non-NULL ptr\n");
2125 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr[0]);
2126 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr[1]);
2128 ret = GlobalUnlock((HGLOBAL)lparam);
2129 ok(ret == 1, "Expected 1, got %d\n", ret);
2131 lo = hi = 0;
2132 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
2133 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2134 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2135 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2137 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
2138 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2140 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
2141 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam);
2143 lo = hi = 0;
2144 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
2145 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2146 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2147 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2149 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
2150 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2152 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
2153 ptr = GlobalLock((HGLOBAL)lparam);
2154 ok(ptr != NULL, "Expected non-NULL ptr\n");
2155 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr[0]);
2156 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr[1]);
2158 ret = GlobalUnlock((HGLOBAL)lparam);
2159 ok(ret == 1, "Expected 1, got %d\n", ret);
2161 lo = hi = 0;
2162 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
2163 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2164 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2165 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2167 ret = FreeDDElParam(WM_DDE_ACK, lparam);
2168 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2170 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
2171 ptr = GlobalLock((HGLOBAL)lparam);
2172 ok(ptr != NULL, "Expected non-NULL ptr\n");
2173 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr[0]);
2174 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr[1]);
2176 ret = GlobalUnlock((HGLOBAL)lparam);
2177 ok(ret == 1, "Expected 1, got %d\n", ret);
2179 lo = hi = 0;
2180 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
2181 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2182 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2183 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2185 ret = FreeDDElParam(WM_DDE_DATA, lparam);
2186 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2188 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
2189 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam);
2191 lo = hi = 0;
2192 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
2193 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2194 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2195 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2197 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
2198 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2200 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
2201 ptr = GlobalLock((HGLOBAL)lparam);
2202 ok(ptr != NULL, "Expected non-NULL ptr\n");
2203 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr[0]);
2204 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr[1]);
2206 ret = GlobalUnlock((HGLOBAL)lparam);
2207 ok(ret == 1, "Expected 1, got %d\n", ret);
2209 lo = hi = 0;
2210 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
2211 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2212 ok(lo == 0xcafe, "Expected 0xcafe, got %08Ix\n", lo);
2213 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2215 ret = FreeDDElParam(WM_DDE_POKE, lparam);
2216 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2218 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
2219 ok(lparam == 0xbeef, "Expected 0xbeef, got %08Ix\n", lparam);
2221 lo = hi = 0;
2222 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
2223 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2224 ok(lo == 0, "Expected 0, got %08Ix\n", lo);
2225 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2227 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
2228 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2231 static void test_UnpackDDElParam(void)
2233 UINT_PTR lo, hi, *ptr;
2234 HGLOBAL hglobal;
2235 BOOL ret;
2237 /* NULL lParam */
2238 lo = 0xdead;
2239 hi = 0xbeef;
2240 ret = UnpackDDElParam(WM_DDE_INITIATE, 0, &lo, &hi);
2241 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2242 ok(lo == 0, "Expected 0, got %08Ix\n", lo);
2243 ok(hi == 0, "Expected 0, got %08Ix\n", hi);
2245 /* NULL lo */
2246 lo = 0xdead;
2247 hi = 0xbeef;
2248 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
2249 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2250 ok(lo == 0xdead, "Expected 0xdead, got %08Ix\n", lo);
2251 ok(hi == 0xcafe, "Expected 0xcafe, got %08Ix\n", hi);
2253 /* NULL hi */
2254 lo = 0xdead;
2255 hi = 0xbeef;
2256 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
2257 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2258 ok(lo == 0xbabe, "Expected 0xbabe, got %08Ix\n", lo);
2259 ok(hi == 0xbeef, "Expected 0xbeef, got %08Ix\n", hi);
2261 lo = 0xdead;
2262 hi = 0xbeef;
2263 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
2264 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2265 ok(lo == 0xbabe, "Expected 0xbabe, got %08Ix\n", lo);
2266 ok(hi == 0xcafe, "Expected 0xcafe, got %08Ix\n", hi);
2268 lo = 0xdead;
2269 hi = 0xbeef;
2270 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
2271 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2272 ok(lo == 0xbabe, "Expected 0xbabe, got %08Ix\n", lo);
2273 ok(hi == 0xcafe, "Expected 0xcafe, got %08Ix\n", hi);
2275 lo = 0xdead;
2276 hi = 0xbeef;
2277 ret = UnpackDDElParam(WM_DDE_ADVISE, 0, &lo, &hi);
2278 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2279 ok(lo == 0 ||
2280 broken(lo == 0xdead), /* win2k */
2281 "Expected 0, got %08Ix\n", lo);
2282 ok(hi == 0 ||
2283 broken(hi == 0xbeef), /* win2k */
2284 "Expected 0, got %08Ix\n", hi);
2286 hglobal = GlobalAlloc(GMEM_DDESHARE, 2 * sizeof(*ptr));
2287 ptr = GlobalLock(hglobal);
2288 ptr[0] = 0xcafebabe;
2289 ptr[1] = 0xdeadbeef;
2290 GlobalUnlock(hglobal);
2292 lo = 0xdead;
2293 hi = 0xbeef;
2294 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2295 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2296 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo);
2297 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi);
2299 lo = 0xdead;
2300 hi = 0xbeef;
2301 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2302 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2303 ok(lo == 0xbabe, "Expected 0xbabe, got %08Ix\n", lo);
2304 ok(hi == 0xcafe, "Expected 0xcafe, got %08Ix\n", hi);
2306 lo = 0xdead;
2307 hi = 0xbeef;
2308 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2309 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2310 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo);
2311 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi);
2313 lo = 0xdead;
2314 hi = 0xbeef;
2315 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2316 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2317 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo);
2318 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi);
2320 lo = 0xdead;
2321 hi = 0xbeef;
2322 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2323 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2324 ok(lo == 0xbabe, "Expected 0xbabe, got %08Ix\n", lo);
2325 ok(hi == 0xcafe, "Expected 0xcafe, got %08Ix\n", hi);
2327 lo = 0xdead;
2328 hi = 0xbeef;
2329 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2330 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2331 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo);
2332 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi);
2334 lo = 0xdead;
2335 hi = 0xbeef;
2336 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2337 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2338 ok(lo == 0, "Expected 0, got %08Ix\n", lo);
2339 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", hi);
2341 GlobalFree(hglobal);
2344 static char test_cmd_a_to_a[] = "Test dde command";
2345 static WCHAR test_cmd_w_to_w[][32] = {
2346 {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0},
2347 { 0x2018, 0x2019, 0x0161, 0x0041, 0x02dc, 0 }, /* some chars that should map properly to CP1252 */
2348 { 0x2026, 0x2020, 0x2021, 0x0d0a, 0 }, /* false negative for IsTextUnicode */
2349 { 0x4efa, 0x4efc, 0x0061, 0x4efe, 0 }, /* some Chinese chars */
2350 { 0x0061, 0x0062, 0x0063, 0x9152, 0 }, /* Chinese with latin characters begin */
2352 static int msg_index;
2353 static BOOL unicode_server, unicode_client;
2355 static HDDEDATA CALLBACK server_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2356 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2357 ULONG_PTR dwData1, ULONG_PTR dwData2)
2359 DWORD size, rsize;
2360 char str[MAX_PATH];
2361 static HCONV conversation = 0;
2362 static const char test_service [] = "TestDDEService";
2363 static const char test_topic [] = "TestDDETopic";
2365 if (winetest_debug > 1) trace("type %#x, fmt %#x\n", uType, uFmt);
2367 ok(msg_index < 5 + ARRAY_SIZE(test_cmd_w_to_w), "Got unexpected message type %#x.\n", uType);
2368 msg_index++;
2370 switch (uType)
2372 case XTYP_REGISTER:
2374 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
2375 return (HDDEDATA)TRUE;
2378 case XTYP_CONNECT:
2380 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
2381 ok(uFmt == 0, "Expected 0, got %d, msg_index=%d\n", uFmt, msg_index);
2382 ok(hconv == 0, "Expected 0, got %p, msg_index=%d\n", hconv, msg_index);
2383 ok(hdata == 0, "Expected 0, got %p, msg_index=%d\n", hdata, msg_index);
2384 ok(dwData1 != 0, "Expected not 0, got %08Ix, msg_index=%d\n", dwData1, msg_index);
2385 ok(dwData2 == FALSE, "Expected FALSE, got %08Ix, msg_index=%d\n", dwData2, msg_index);
2387 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2388 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2389 test_topic, str, msg_index);
2390 ok(size == 12, "Expected 12, got %ld, msg_index=%d\n", size, msg_index);
2392 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
2393 ok(!lstrcmpA(str, test_service), "Expected %s, got %s, msg_index=%d\n",
2394 test_service, str, msg_index);
2395 ok(size == 14, "Expected 14, got %ld, msg_index=%d\n", size, msg_index);
2397 return (HDDEDATA) TRUE;
2399 case XTYP_CONNECT_CONFIRM:
2401 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
2402 conversation = hconv;
2403 return (HDDEDATA) TRUE;
2405 case XTYP_EXECUTE:
2407 BYTE *buffer = NULL;
2408 WCHAR *cmd_w;
2409 char test_cmd_w_to_a[64];
2410 WCHAR test_cmd_a_to_w[64];
2411 DWORD size_a, size_w, size_w_to_a, size_a_to_w;
2412 BOOL str_index;
2414 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
2415 ok(hconv == conversation, "Expected conversation handle, got %p, msg_index=%d\n",
2416 hconv, msg_index);
2417 ok(dwData1 == 0, "Expected 0, got %08Ix, msg_index=%d\n", dwData1, msg_index);
2418 ok(dwData2 == 0, "Expected 0, got %08Ix, msg_index=%d\n", dwData2, msg_index);
2419 ok(hsz2 == 0, "Expected 0, got %p, msg_index=%d\n", hsz2, msg_index);
2420 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2421 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2422 test_topic, str, msg_index);
2423 ok(size == 12, "Expected 12, got %ld, msg_index=%d\n", size, msg_index);
2425 size = DdeGetData(hdata, NULL, 0, 0);
2426 ok((buffer = calloc(1, size)) != NULL, "should not be null\n");
2427 rsize = DdeGetData(hdata, buffer, size, 0);
2428 ok(rsize == size, "Incorrect size returned, expected %ld got %ld, msg_index=%d\n",
2429 size, rsize, msg_index);
2430 if (winetest_debug > 1) trace("msg %u strA \"%s\" strW %s\n", msg_index, buffer, wine_dbgstr_w((WCHAR*)buffer));
2432 str_index = msg_index - 4;
2433 cmd_w = test_cmd_w_to_w[str_index - 1];
2434 size_a = strlen(test_cmd_a_to_a) + 1;
2435 size_w = (lstrlenW(cmd_w) + 1) * sizeof(WCHAR);
2436 size_a_to_w = MultiByteToWideChar( CP_ACP, 0, test_cmd_a_to_a, -1, test_cmd_a_to_w,
2437 ARRAY_SIZE(test_cmd_a_to_w)) * sizeof(WCHAR);
2438 size_w_to_a = WideCharToMultiByte( CP_ACP, 0, cmd_w, -1,
2439 test_cmd_w_to_a, sizeof(test_cmd_w_to_a), NULL, NULL );
2440 switch (str_index)
2442 case 0: /* ANSI string */
2443 if (unicode_server)
2445 ok(size == size_a_to_w, "Wrong size %ld/%ld, msg_index=%d\n", size, size_a_to_w, msg_index);
2446 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2447 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2449 else if (unicode_client)
2451 /* ANSI string mapped W->A -> garbage */
2453 else
2455 ok(size == size_a, "Wrong size %ld/%ld, msg_index=%d\n", size, size_a, msg_index);
2456 ok(!lstrcmpA((CHAR*)buffer, test_cmd_a_to_a), "Expected %s, got %s, msg_index=%d\n",
2457 test_cmd_a_to_a, buffer, msg_index);
2459 break;
2461 case 1: /* Unicode string with only 8-bit chars */
2462 if (unicode_server)
2464 ok(size == size_w, "Wrong size %ld/%ld, msg_index=%d\n", size, size_w, msg_index);
2465 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2466 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2468 else
2470 ok(size == size_w_to_a, "Wrong size %ld/%ld, msg_index=%d\n",
2471 size, size_w_to_a, msg_index);
2472 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2473 test_cmd_w_to_a, buffer, msg_index);
2475 break;
2477 case 2: /* normal Unicode string */
2478 case 3: /* IsTextUnicode false negative */
2479 case 4: /* Chinese chars */
2480 if (unicode_server)
2482 /* double A->W mapping */
2483 /* NT uses the full size, XP+ only until the first null */
2484 DWORD nt_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, size_w, test_cmd_a_to_w,
2485 ARRAY_SIZE(test_cmd_a_to_w)) * sizeof(WCHAR);
2486 DWORD xp_size = MultiByteToWideChar( CP_ACP, 0, (char *)cmd_w, -1, NULL, 0 ) * sizeof(WCHAR);
2487 ok(size == xp_size || broken(size == nt_size) ||
2488 broken(str_index == 4 && IsDBCSLeadByte(cmd_w[0])) /* East Asian */,
2489 "Wrong size %ld/%ld, msg_index=%d\n", size, size_a_to_w, msg_index);
2490 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2491 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w), msg_index);
2493 else if (unicode_client)
2495 ok(size == size_w_to_a, "Wrong size %ld/%ld, msg_index=%d\n", size, size_w_to_a, msg_index);
2496 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2497 test_cmd_w_to_a, buffer, msg_index);
2499 else
2501 ok(size == size_w, "Wrong size %ld/%ld, msg_index=%d\n", size, size_w, msg_index);
2502 ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2503 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), msg_index);
2505 break;
2506 case 5: /* Chinese with latin characters begin */
2507 if (unicode_server && unicode_client)
2509 todo_wine ok(size == size_w, "Wrong size %ld expected %ld, msg_index=%d\n", size, size_w, msg_index);
2510 MultiByteToWideChar(CP_ACP, 0, test_cmd_w_to_a, size_w, test_cmd_a_to_w,
2511 ARRAY_SIZE(test_cmd_a_to_w));
2512 todo_wine ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2513 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), wine_dbgstr_w((WCHAR *)buffer), msg_index);
2515 else if (unicode_server)
2517 todo_wine ok(size == size_w, "Wrong size %ld expected %ld, msg_index=%d\n", size, size_w, msg_index);
2518 MultiByteToWideChar(CP_ACP, 0, test_cmd_w_to_a, size_w, test_cmd_a_to_w,
2519 ARRAY_SIZE(test_cmd_a_to_w));
2520 if (!is_cjk())
2521 todo_wine ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w), "Expected %s, got %s, msg_index=%d\n",
2522 wine_dbgstr_w(test_cmd_a_to_w), wine_dbgstr_w((WCHAR*)buffer), msg_index);
2523 else
2524 todo_wine ok(!lstrcmpW((WCHAR*)buffer, cmd_w),
2525 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w), wine_dbgstr_w((WCHAR *)buffer), msg_index);
2527 else if (unicode_client)
2529 ok(size == size_w_to_a, "Wrong size %ld expected %ld, msg_index=%d\n", size, size_w_to_a, msg_index);
2530 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2531 test_cmd_w_to_a, buffer, msg_index);
2533 else
2535 todo_wine ok(size == size_w_to_a || size == (size_w_to_a - 1), "Wrong size %ld expected %ld or %ld, msg_index=%d\n",
2536 size, size_w_to_a, size_w_to_a - 1, msg_index);
2537 todo_wine ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2538 test_cmd_w_to_a, buffer, msg_index);
2540 break;
2542 default:
2543 ok( 0, "Invalid message %u\n", msg_index );
2544 break;
2546 free(buffer);
2547 return (HDDEDATA) DDE_FACK;
2549 case XTYP_DISCONNECT:
2550 return (HDDEDATA) TRUE;
2552 default:
2553 ok(FALSE, "Unhandled msg: %08x, msg_index=%d\n", uType, msg_index);
2556 return NULL;
2559 static HDDEDATA CALLBACK client_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2560 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2561 ULONG_PTR dwData1, ULONG_PTR dwData2)
2563 switch (uType)
2565 case XTYP_DISCONNECT:
2566 return (HDDEDATA) TRUE;
2568 default:
2569 ok(FALSE, "Unhandled msg: %08x\n", uType);
2572 return NULL;
2575 static void test_end_to_end_client(BOOL type_a)
2577 DWORD i, ret, err;
2578 DWORD client_pid = 0;
2579 HSZ server, topic;
2580 HCONV hconv;
2581 HDDEDATA hdata;
2582 static const char test_service[] = "TestDDEService";
2583 static const WCHAR test_service_w[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2584 static const char test_topic[] = "TestDDETopic";
2585 static const WCHAR test_topic_w[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2587 if (type_a)
2588 ret = DdeInitializeA(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2589 else
2590 ret = DdeInitializeW(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2591 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %lx\n", ret);
2593 if (type_a)
2595 server = DdeCreateStringHandleA(client_pid, test_service, CP_WINANSI);
2596 topic = DdeCreateStringHandleA(client_pid, test_topic, CP_WINANSI);
2598 else {
2599 server = DdeCreateStringHandleW(client_pid, test_service_w, CP_WINUNICODE);
2600 topic = DdeCreateStringHandleW(client_pid, test_topic_w, CP_WINUNICODE);
2603 DdeGetLastError(client_pid);
2604 hconv = DdeConnect(client_pid, server, topic, NULL);
2605 if (broken(!hconv)) /* Windows 10 version 1607 */
2607 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(client_pid));
2608 DdeUninitialize(client_pid);
2609 return;
2611 ret = DdeGetLastError(client_pid);
2612 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %lx\n", ret);
2613 DdeFreeStringHandle(client_pid, server);
2615 /* Test both A and W data being passed to DdeClientTransaction */
2616 hdata = DdeClientTransaction((LPBYTE)test_cmd_a_to_a, sizeof(test_cmd_a_to_a),
2617 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2618 ok(hdata != NULL, "DdeClientTransaction failed\n");
2619 ok(ret == DDE_FACK, "wrong status code %lx\n", ret);
2620 err = DdeGetLastError(client_pid);
2621 ok(err == DMLERR_NO_ERROR, "wrong dde error %lx\n", err);
2623 for (i = 0; i < ARRAY_SIZE(test_cmd_w_to_w); i++)
2625 hdata = DdeClientTransaction((LPBYTE)test_cmd_w_to_w[i],
2626 (lstrlenW(test_cmd_w_to_w[i]) + 1) * sizeof(WCHAR),
2627 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2628 ok(hdata != NULL, "DdeClientTransaction failed\n");
2629 ok(ret == DDE_FACK, "wrong status code %lx\n", ret);
2630 err = DdeGetLastError(client_pid);
2631 ok(err == DMLERR_NO_ERROR, "wrong dde error %lx\n", err);
2634 DdeFreeStringHandle(client_pid, topic);
2635 ret = DdeDisconnect(hconv);
2636 ok(ret == TRUE, "Expected TRUE, got %lx\n", ret);
2638 ret = DdeUninitialize(client_pid);
2639 ok(ret == TRUE, "Expected TRUE, got %lx\n", ret);
2643 static void test_end_to_end_server(void)
2645 HANDLE client;
2646 MSG msg;
2647 HSZ server;
2648 BOOL ret;
2649 DWORD res;
2650 HDDEDATA hdata;
2651 static const char test_service[] = "TestDDEService";
2653 trace("client %s, server %s\n", unicode_client ? "unicode" : "ansi",
2654 unicode_server ? "unicode" : "ansi");
2655 server_pid = 0;
2656 msg_index = 0;
2658 if (unicode_server)
2659 res = DdeInitializeW(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2660 else
2661 res = DdeInitializeA(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2662 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %ld\n", res);
2664 server = DdeCreateStringHandleA(server_pid, test_service, CP_WINANSI);
2665 ok(server != NULL, "Expected non-NULL string handle\n");
2667 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
2668 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
2670 client = create_process(unicode_client ? "endw" : "enda");
2672 while (MsgWaitForMultipleObjects(1, &client, FALSE, INFINITE, QS_ALLINPUT) != 0)
2674 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2677 ret = DdeUninitialize(server_pid);
2678 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2679 GetExitCodeProcess(client, &res);
2680 ok( !res, "client failed with %lu error(s)\n", res );
2681 CloseHandle(client);
2684 START_TEST(dde)
2686 int argc;
2687 char **argv;
2688 DWORD dde_inst = 0xdeadbeef;
2690 argc = winetest_get_mainargs(&argv);
2691 if (argc == 3)
2693 if (!lstrcmpA(argv[2], "ddeml"))
2694 test_ddeml_client();
2695 else if (!lstrcmpA(argv[2], "msg"))
2696 test_msg_client();
2697 else if (!lstrcmpA(argv[2], "enda"))
2698 test_end_to_end_client(TRUE);
2699 else if (!lstrcmpA(argv[2], "endw"))
2700 test_end_to_end_client(FALSE);
2702 return;
2705 test_initialisation();
2707 DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
2709 test_msg_server();
2710 test_ddeml_server();
2712 /* Test the combinations of A and W interfaces with A and W data
2713 end to end to ensure that data conversions are accurate */
2714 unicode_client = unicode_server = FALSE;
2715 test_end_to_end_server();
2716 unicode_client = unicode_server = TRUE;
2717 test_end_to_end_server();
2718 unicode_client = FALSE;
2719 unicode_server = TRUE;
2720 test_end_to_end_server();
2721 unicode_client = TRUE;
2722 unicode_server = FALSE;
2723 test_end_to_end_server();
2725 test_dde_aw_transaction( FALSE, TRUE );
2726 test_dde_aw_transaction( TRUE, FALSE );
2727 test_dde_aw_transaction( TRUE, TRUE );
2728 test_dde_aw_transaction( FALSE, FALSE );
2730 test_dde_aw_transaction( FALSE, TRUE );
2731 test_dde_aw_transaction( TRUE, FALSE );
2732 test_dde_aw_transaction( TRUE, TRUE );
2733 test_dde_aw_transaction( FALSE, FALSE );
2735 test_DdeCreateDataHandle();
2736 test_DdeCreateStringHandle();
2737 test_FreeDDElParam();
2738 test_PackDDElParam();
2739 test_UnpackDDElParam();