shdocvw: Always create BindStatusCallback object.
[wine.git] / dlls / user32 / tests / dde.c
blobe90d8c9d6d259cef2539ff44447b8ae7b4468d29
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 <assert.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.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_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
40 static WNDPROC old_dde_client_wndproc;
42 static const DWORD default_timeout = 200;
44 static void flush_events(void)
46 MSG msg;
47 int diff = default_timeout;
48 DWORD time = GetTickCount() + diff;
50 while (diff > 0)
52 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
53 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
54 diff = time - GetTickCount();
58 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
60 WNDCLASSA wcA;
62 memset(&wcA, 0, sizeof(wcA));
63 wcA.lpfnWndProc = wndproc;
64 wcA.lpszClassName = name;
65 wcA.hInstance = GetModuleHandleA(0);
66 assert(RegisterClassA(&wcA));
68 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
69 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
70 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
71 assert(*hwnd);
74 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
76 UINT_PTR lo, hi;
77 char str[MAX_PATH], *ptr;
78 HGLOBAL hglobal;
79 DDEDATA *data;
80 DDEPOKE *poke;
81 DWORD size;
83 static int msg_index = 0;
84 static HWND client = 0;
85 static BOOL executed = FALSE;
87 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
88 return DefWindowProcA(hwnd, msg, wparam, lparam);
90 msg_index++;
92 switch (msg)
94 case WM_DDE_INITIATE:
96 client = (HWND)wparam;
97 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
99 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
100 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
102 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
103 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
105 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
107 break;
110 case WM_DDE_REQUEST:
112 ok((msg_index >= 2 && msg_index <= 4) ||
113 (msg_index >= 7 && msg_index <= 8),
114 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
115 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
116 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
118 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
119 if (msg_index < 8)
120 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
121 else
122 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
124 if (msg_index == 8)
126 if (executed)
127 lstrcpyA(str, "command executed\r\n");
128 else
129 lstrcpyA(str, "command not executed\r\n");
131 else
132 lstrcpyA(str, "requested data\r\n");
134 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
135 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
136 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
138 data = GlobalLock(hglobal);
139 ZeroMemory(data, size);
141 /* setting fResponse to FALSE at this point destroys
142 * the internal messaging state of native dde
144 data->fResponse = TRUE;
146 if (msg_index == 2)
147 data->fRelease = TRUE;
148 else if (msg_index == 3)
149 data->fAckReq = TRUE;
151 data->cfFormat = CF_TEXT;
152 lstrcpyA((LPSTR)data->Value, str);
153 GlobalUnlock(hglobal);
155 lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
156 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
158 break;
161 case WM_DDE_POKE:
163 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
164 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
166 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
168 GlobalGetAtomNameA(hi, str, MAX_PATH);
169 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
171 poke = GlobalLock((HGLOBAL)lo);
172 ok(poke != NULL, "Expected non-NULL poke\n");
173 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
174 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
175 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
176 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
178 if (msg_index == 5)
179 ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
180 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
181 else
182 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
183 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
185 GlobalUnlock((HGLOBAL)lo);
187 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
188 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
190 break;
193 case WM_DDE_EXECUTE:
195 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
196 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
198 ptr = GlobalLock((HGLOBAL)lparam);
199 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
200 GlobalUnlock((HGLOBAL)lparam);
202 executed = TRUE;
204 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
205 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
207 break;
210 case WM_DDE_TERMINATE:
212 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
213 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
214 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
216 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
218 break;
221 default:
222 ok(FALSE, "Unhandled msg: %08x\n", msg);
225 return DefWindowProcA(hwnd, msg, wparam, lparam);
228 static void test_msg_server(HANDLE hproc)
230 MSG msg;
231 HWND hwnd;
232 DWORD res;
234 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
236 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
238 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
241 DestroyWindow(hwnd);
242 GetExitCodeProcess( hproc, &res );
243 ok( !res, "client failed with %u error(s)\n", res );
246 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
247 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
248 ULONG_PTR dwData1, ULONG_PTR dwData2)
250 ok(FALSE, "Unhandled msg: %08x\n", uType);
251 return 0;
254 static void test_ddeml_client(void)
256 UINT ret;
257 char buffer[32];
258 LPSTR str;
259 DWORD size, res;
260 HDDEDATA hdata, op;
261 HSZ server, topic, item;
262 DWORD client_pid;
263 HCONV conversation;
265 client_pid = 0;
266 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
267 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
269 /* FIXME: make these atoms global and check them in the server */
271 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
272 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
274 DdeGetLastError(client_pid);
275 conversation = DdeConnect(client_pid, server, topic, NULL);
276 ok(conversation != NULL, "Expected non-NULL conversation\n");
277 ret = DdeGetLastError(client_pid);
278 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
280 DdeFreeStringHandle(client_pid, server);
282 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
284 /* XTYP_REQUEST, fRelease = TRUE */
285 res = 0xdeadbeef;
286 DdeGetLastError(client_pid);
287 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
288 ret = DdeGetLastError(client_pid);
289 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
290 todo_wine
292 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", res);
294 if (hdata == NULL)
295 ok(FALSE, "hdata is NULL\n");
296 else
298 str = (LPSTR)DdeAccessData(hdata, &size);
299 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
300 ok(size == 19, "Expected 19, got %d\n", size);
302 ret = DdeUnaccessData(hdata);
303 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
306 /* XTYP_REQUEST, fAckReq = TRUE */
307 res = 0xdeadbeef;
308 DdeGetLastError(client_pid);
309 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
310 ret = DdeGetLastError(client_pid);
311 todo_wine
313 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
314 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
316 if (hdata == NULL)
317 ok(FALSE, "hdata is NULL\n");
318 else
320 str = (LPSTR)DdeAccessData(hdata, &size);
321 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
322 ok(size == 19, "Expected 19, got %d\n", size);
324 ret = DdeUnaccessData(hdata);
325 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
328 /* XTYP_REQUEST, all params normal */
329 res = 0xdeadbeef;
330 DdeGetLastError(client_pid);
331 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
332 ret = DdeGetLastError(client_pid);
333 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
334 todo_wine
336 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
338 if (hdata == NULL)
339 ok(FALSE, "hdata is NULL\n");
340 else
342 str = (LPSTR)DdeAccessData(hdata, &size);
343 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
344 ok(size == 19, "Expected 19, got %d\n", size);
346 ret = DdeUnaccessData(hdata);
347 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
350 /* XTYP_REQUEST, no item */
351 res = 0xdeadbeef;
352 DdeGetLastError(client_pid);
353 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
354 ret = DdeGetLastError(client_pid);
355 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
356 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
357 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
359 DdeFreeStringHandle(client_pid, item);
361 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
363 lstrcpyA(buffer, "poke data\r\n");
364 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
365 0, item, CF_TEXT, 0);
366 ok(hdata != NULL, "Expected non-NULL hdata\n");
368 /* XTYP_POKE, no item */
369 res = 0xdeadbeef;
370 DdeGetLastError(client_pid);
371 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
372 ret = DdeGetLastError(client_pid);
373 ok(op == NULL, "Expected NULL, got %p\n", op);
374 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
375 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
377 /* XTYP_POKE, no data */
378 res = 0xdeadbeef;
379 DdeGetLastError(client_pid);
380 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
381 ret = DdeGetLastError(client_pid);
382 ok(op == NULL, "Expected NULL, got %p\n", op);
383 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
384 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
386 /* XTYP_POKE, wrong size */
387 res = 0xdeadbeef;
388 DdeGetLastError(client_pid);
389 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
390 ret = DdeGetLastError(client_pid);
391 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
392 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
393 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
395 /* XTYP_POKE, correct params */
396 res = 0xdeadbeef;
397 DdeGetLastError(client_pid);
398 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
399 ret = DdeGetLastError(client_pid);
400 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
401 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
402 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
404 DdeFreeDataHandle(hdata);
406 lstrcpyA(buffer, "[Command(Var)]");
407 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
408 0, NULL, CF_TEXT, 0);
409 ok(hdata != NULL, "Expected non-NULL hdata\n");
411 /* XTYP_EXECUTE, correct params */
412 res = 0xdeadbeef;
413 DdeGetLastError(client_pid);
414 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
415 ret = DdeGetLastError(client_pid);
416 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
417 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
418 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
420 /* XTYP_EXECUTE, no data */
421 res = 0xdeadbeef;
422 DdeGetLastError(client_pid);
423 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
424 ret = DdeGetLastError(client_pid);
425 ok(op == NULL, "Expected NULL, got %p\n", op);
426 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
427 todo_wine
429 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
432 /* XTYP_EXECUTE, no data, -1 size */
433 res = 0xdeadbeef;
434 DdeGetLastError(client_pid);
435 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
436 ret = DdeGetLastError(client_pid);
437 ok(op == NULL, "Expected NULL, got %p\n", op);
438 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
439 todo_wine
441 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
444 DdeFreeStringHandle(client_pid, topic);
445 DdeFreeDataHandle(hdata);
447 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
449 /* verify the execute */
450 res = 0xdeadbeef;
451 DdeGetLastError(client_pid);
452 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
453 ret = DdeGetLastError(client_pid);
454 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
455 todo_wine
457 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
459 if (hdata == NULL)
460 ok(FALSE, "hdata is NULL\n");
461 else
463 str = (LPSTR)DdeAccessData(hdata, &size);
464 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
465 ok(size == 21, "Expected 21, got %d\n", size);
467 ret = DdeUnaccessData(hdata);
468 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
471 /* invalid transactions */
472 res = 0xdeadbeef;
473 DdeGetLastError(client_pid);
474 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
475 ret = DdeGetLastError(client_pid);
476 ok(op == NULL, "Expected NULL, got %p\n", op);
477 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
478 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
480 res = 0xdeadbeef;
481 DdeGetLastError(client_pid);
482 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, default_timeout, &res);
483 ret = DdeGetLastError(client_pid);
484 ok(op == NULL, "Expected NULL, got %p\n", op);
485 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
486 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
488 res = 0xdeadbeef;
489 DdeGetLastError(client_pid);
490 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, default_timeout, &res);
491 ret = DdeGetLastError(client_pid);
492 ok(op == NULL, "Expected NULL, got %p\n", op);
493 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
494 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
496 res = 0xdeadbeef;
497 DdeGetLastError(client_pid);
498 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, default_timeout, &res);
499 ret = DdeGetLastError(client_pid);
500 ok(op == NULL, "Expected NULL, got %p\n", op);
501 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
502 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
504 res = 0xdeadbeef;
505 DdeGetLastError(client_pid);
506 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, default_timeout, &res);
507 ret = DdeGetLastError(client_pid);
508 ok(op == NULL, "Expected NULL, got %p\n", op);
509 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
510 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
512 res = 0xdeadbeef;
513 DdeGetLastError(client_pid);
514 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, default_timeout, &res);
515 ret = DdeGetLastError(client_pid);
516 ok(op == NULL, "Expected NULL, got %p\n", op);
517 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
518 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
520 res = 0xdeadbeef;
521 DdeGetLastError(client_pid);
522 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, default_timeout, &res);
523 ret = DdeGetLastError(client_pid);
524 ok(op == NULL, "Expected NULL, got %p\n", op);
525 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
526 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
528 res = 0xdeadbeef;
529 DdeGetLastError(client_pid);
530 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, default_timeout, &res);
531 ret = DdeGetLastError(client_pid);
532 ok(op == NULL, "Expected NULL, got %p\n", op);
533 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
534 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
536 res = 0xdeadbeef;
537 DdeGetLastError(client_pid);
538 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
539 ret = DdeGetLastError(client_pid);
540 ok(op == NULL, "Expected NULL, got %p\n", op);
541 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
542 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
544 res = 0xdeadbeef;
545 DdeGetLastError(client_pid);
546 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
547 ret = DdeGetLastError(client_pid);
548 ok(op == NULL, "Expected NULL, got %p\n", op);
549 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
550 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
552 DdeFreeStringHandle(client_pid, item);
554 ret = DdeDisconnect(conversation);
555 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
557 ret = DdeUninitialize(client_pid);
558 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
561 static DWORD server_pid;
563 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
564 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
565 ULONG_PTR dwData1, ULONG_PTR dwData2)
567 char str[MAX_PATH], *ptr;
568 HDDEDATA ret;
569 DWORD size;
571 static int msg_index = 0;
572 static HCONV conversation = 0;
574 msg_index++;
576 switch (uType)
578 case XTYP_REGISTER:
580 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
581 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
582 ok(hconv == 0, "Expected 0, got %p\n", hconv);
583 ok(hdata == 0, "Expected 0, got %p\n", hdata);
584 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
585 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
587 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
588 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
589 ok(size == 13, "Expected 13, got %d\n", size);
591 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
592 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
593 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
594 ok(size == 25, "Expected 25, got %d\n", size);
596 return (HDDEDATA)TRUE;
599 case XTYP_CONNECT:
601 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
602 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
603 ok(hconv == 0, "Expected 0, got %p\n", hconv);
604 ok(hdata == 0, "Expected 0, got %p\n", hdata);
605 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
606 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
608 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
609 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
610 ok(size == 12, "Expected 12, got %d\n", size);
612 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
613 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
614 ok(size == 13, "Expected 13, got %d\n", size);
616 return (HDDEDATA)TRUE;
619 case XTYP_CONNECT_CONFIRM:
621 conversation = hconv;
623 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
624 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
625 ok(hconv != NULL, "Expected non-NULL hconv\n");
626 ok(hdata == 0, "Expected 0, got %p\n", hdata);
627 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
628 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
630 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
631 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
632 ok(size == 12, "Expected 12, got %d\n", size);
634 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
635 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
636 ok(size == 13, "Expected 13, got %d\n", size);
638 return (HDDEDATA)TRUE;
641 case XTYP_REQUEST:
643 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
644 "Expected 4, 5 or 6, got %d\n", msg_index);
645 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
646 ok(hdata == 0, "Expected 0, got %p\n", hdata);
647 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
648 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
650 if (msg_index == 4)
651 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
652 else
653 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
655 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
656 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
657 ok(size == 12, "Expected 12, got %d\n", size);
659 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
661 if (msg_index == 5)
663 todo_wine
665 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
666 ok(size == 1, "Expected 1, got %d\n", size);
669 else if (msg_index == 6)
671 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
672 ok(size == 7, "Expected 7, got %d\n", size);
675 if (msg_index == 6)
677 lstrcpyA(str, "requested data\r\n");
678 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
679 0, hsz2, CF_TEXT, 0);
682 return NULL;
685 case XTYP_POKE:
687 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
688 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
689 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
690 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
691 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
693 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
694 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
695 ok(size == 12, "Expected 12, got %d\n", size);
697 ptr = (LPSTR)DdeAccessData(hdata, &size);
698 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
699 todo_wine
701 ok(size == 14, "Expected 14, got %d\n", size);
703 DdeUnaccessData(hdata);
705 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
706 if (msg_index == 7)
708 todo_wine
710 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
711 ok(size == 1, "Expected 1, got %d\n", size);
714 else
716 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
717 ok(size == 4, "Expected 4, got %d\n", size);
720 return (HDDEDATA)DDE_FACK;
723 case XTYP_EXECUTE:
725 ok(msg_index == 9 || msg_index == 10, "Expected 9 or 10, got %d\n", msg_index);
726 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
727 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
728 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
729 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
730 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
732 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
733 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
734 ok(size == 12, "Expected 12, got %d\n", size);
736 ptr = (LPSTR)DdeAccessData(hdata, &size);
738 if (msg_index == 9)
740 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
741 ok(size == 15, "Expected 15, got %d\n", size);
742 ret = (HDDEDATA)DDE_FACK;
744 else
746 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
747 ok(size == 18, "Expected 18, got %d\n", size);
748 ret = (HDDEDATA)DDE_FNOTPROCESSED;
751 DdeUnaccessData(hdata);
753 return ret;
756 case XTYP_DISCONNECT:
758 ok(msg_index == 11, "Expected 11, got %d\n", msg_index);
759 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
760 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
761 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
762 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
763 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
764 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
766 return 0;
769 default:
770 ok(FALSE, "Unhandled msg: %08x\n", uType);
773 return 0;
776 static void test_ddeml_server(HANDLE hproc)
778 MSG msg;
779 UINT res;
780 BOOL ret;
781 HSZ server;
782 HDDEDATA hdata;
784 /* set up DDE server */
785 server_pid = 0;
786 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
787 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
789 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
790 ok(server != NULL, "Expected non-NULL string handle\n");
792 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
793 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
795 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
797 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
799 ret = DdeUninitialize(server_pid);
800 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
801 GetExitCodeProcess( hproc, &res );
802 ok( !res, "client failed with %u error(s)\n", res );
805 static HWND client_hwnd, server_hwnd;
806 static ATOM server, topic, item;
807 static HGLOBAL execute_hglobal;
809 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
811 char str[MAX_PATH];
812 UINT_PTR lo, hi;
813 DDEDATA *data;
814 DDEACK *ack;
815 DWORD size;
816 LPSTR ptr;
818 static int msg_index = 0;
820 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
821 return DefWindowProcA(hwnd, msg, wparam, lparam);
823 msg_index++;
825 switch (msg)
827 case WM_DDE_INITIATE:
829 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
830 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
832 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
833 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
834 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
835 ok(size == 13, "Expected 13, got %d\n", size);
837 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
838 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
839 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
840 ok(size == 12, "Expected 12, got %d\n", size);
842 break;
845 case WM_DDE_ACK:
847 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 10),
848 "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index);
850 if (msg_index == 2)
852 server_hwnd = (HWND)wparam;
853 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
855 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
856 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
857 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
858 ok(size == 13, "Expected 13, got %d\n", size);
860 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
861 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
862 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
863 ok(size == 12, "Expected 12, got %d\n", size);
865 else if (msg_index == 9 || msg_index == 10)
867 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
869 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
871 ack = (DDEACK *)&lo;
872 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
873 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
874 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
876 ok(hi == (UINT_PTR)execute_hglobal, "Execpted execute hglobal, got %08lx\n", hi);
877 ptr = GlobalLock((HGLOBAL)hi);
879 if (msg_index == 9)
881 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
882 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
884 else
886 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
887 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
890 GlobalUnlock((HGLOBAL)hi);
892 else
894 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
896 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
898 ack = (DDEACK *)&lo;
899 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
900 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
901 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
903 if (msg_index >= 7)
904 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
905 else
907 if (msg_index == 6) todo_wine
908 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
911 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
912 if (msg_index == 3)
914 ok(hi == item, "Expected item atom, got %08lx\n", hi);
915 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
916 ok(size == 7, "Expected 7, got %d\n", size);
918 else if (msg_index == 4 || msg_index == 7)
920 ok(hi == 0, "Expected 0, got %08lx\n", hi);
921 ok(size == 0, "Expected empty string, got %d\n", size);
923 else
925 ok(hi == item, "Expected item atom, got %08lx\n", hi);
926 if (msg_index == 6) todo_wine
928 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
929 ok(size == 4, "Expected 4, got %d\n", size);
934 break;
937 case WM_DDE_DATA:
939 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
940 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
942 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
944 data = GlobalLock((HGLOBAL)lo);
945 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
946 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
947 todo_wine
949 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
951 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
952 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
953 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
954 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
955 GlobalUnlock((HGLOBAL)lo);
957 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
958 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
959 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
960 ok(size == 7, "Expected 7, got %d\n", size);
962 GlobalFree((HGLOBAL)lo);
963 GlobalDeleteAtom(hi);
965 break;
968 default:
969 ok(FALSE, "Unhandled msg: %08x\n", msg);
972 return DefWindowProcA(hwnd, msg, wparam, lparam);
975 static HGLOBAL create_poke()
977 HGLOBAL hglobal;
978 DDEPOKE *poke;
979 DWORD size;
981 size = sizeof(DDEPOKE) + lstrlenA("poke data\r\n") + 1;
982 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
983 ok(hglobal != 0, "Expected non-NULL hglobal\n");
985 poke = GlobalLock(hglobal);
986 poke->unused = 0;
987 poke->fRelease = TRUE;
988 poke->fReserved = TRUE;
989 poke->cfFormat = CF_TEXT;
990 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
991 GlobalUnlock(hglobal);
993 return hglobal;
996 static HGLOBAL create_execute(LPCSTR command)
998 HGLOBAL hglobal;
999 LPSTR ptr;
1001 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1002 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1004 ptr = GlobalLock(hglobal);
1005 lstrcpyA(ptr, command);
1006 GlobalUnlock(hglobal);
1008 return hglobal;
1011 static void test_msg_client()
1013 HGLOBAL hglobal;
1014 LPARAM lparam;
1016 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1018 server = GlobalAddAtomA("TestDDEServer");
1019 ok(server != 0, "Expected non-NULL server\n");
1021 topic = GlobalAddAtomA("TestDDETopic");
1022 ok(topic != 0, "Expected non-NULL topic\n");
1024 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1026 GlobalDeleteAtom(server);
1027 GlobalDeleteAtom(topic);
1029 flush_events();
1031 item = GlobalAddAtom("request");
1032 ok(item != 0, "Expected non-NULL item\n");
1034 /* WM_DDE_REQUEST, bad clipboard format */
1035 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1036 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1038 flush_events();
1040 /* WM_DDE_REQUEST, no item */
1041 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1042 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1044 flush_events();
1046 /* WM_DDE_REQUEST, no client hwnd */
1047 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1048 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1050 flush_events();
1052 /* WM_DDE_REQUEST, correct params */
1053 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1054 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1056 flush_events();
1058 GlobalDeleteAtom(item);
1059 item = GlobalAddAtomA("poke");
1060 ok(item != 0, "Expected non-NULL item\n");
1062 hglobal = create_poke();
1064 /* WM_DDE_POKE, no ddepoke */
1065 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1066 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1068 flush_events();
1070 /* WM_DDE_POKE, no item */
1071 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1072 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1074 flush_events();
1076 hglobal = create_poke();
1078 /* WM_DDE_POKE, no client hwnd */
1079 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1080 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1082 flush_events();
1084 /* WM_DDE_POKE, all params correct */
1085 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1086 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1088 flush_events();
1090 execute_hglobal = create_execute("[Command(Var)]");
1092 /* WM_DDE_EXECUTE, no lparam */
1093 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1095 flush_events();
1097 /* WM_DDE_EXECUTE, no hglobal */
1098 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1099 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1101 flush_events();
1103 /* WM_DDE_EXECUTE, no client hwnd */
1104 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1105 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1107 flush_events();
1109 /* WM_DDE_EXECUTE, all params correct */
1110 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1111 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1113 flush_events();
1115 GlobalFree(execute_hglobal);
1116 execute_hglobal = create_execute("[BadCommand(Var)]");
1118 /* WM_DDE_EXECUTE that will get rejected */
1119 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1120 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1122 flush_events();
1124 DestroyWindow(client_hwnd);
1127 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1129 UINT_PTR lo, hi;
1131 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1133 switch (msg)
1135 case WM_DDE_ACK:
1136 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1137 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1138 break;
1140 default:
1141 break;
1143 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1146 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1148 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1150 switch (msg)
1152 case WM_DDE_INITIATE:
1154 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1156 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
1158 if (LOWORD(lparam) == aService)
1160 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
1161 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
1162 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1163 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
1165 else
1166 GlobalDeleteAtom(aService);
1167 return 0;
1170 case WM_DDE_EXECUTE:
1172 DDEACK ack;
1173 WORD status;
1174 LPCSTR cmd;
1175 UINT_PTR lo, hi;
1177 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1179 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1180 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1182 ack.bAppReturnCode = 0;
1183 ack.reserved = 0;
1184 ack.fBusy = 0;
1186 cmd = GlobalLock((HGLOBAL)hi);
1188 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
1190 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1191 /* We have to send a negative acknowledge even if we don't
1192 * accept the command, otherwise Windows goes mad and next time
1193 * we send an acknowledge DDEML drops the connection.
1194 * Not sure how to call it: a bug or a feature.
1196 ack.fAck = 0;
1198 else
1199 ack.fAck = 1;
1200 GlobalUnlock((HGLOBAL)hi);
1202 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1204 status = *((WORD *)&ack);
1205 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1207 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1208 return 0;
1211 case WM_DDE_TERMINATE:
1213 DDEACK ack;
1214 WORD status;
1216 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1218 ack.bAppReturnCode = 0;
1219 ack.reserved = 0;
1220 ack.fBusy = 0;
1221 ack.fAck = 1;
1223 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1225 status = *((WORD *)&ack);
1226 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1228 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1229 return 0;
1232 default:
1233 break;
1236 return DefWindowProcW(hwnd, msg, wparam, lparam);
1239 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1241 return DefWindowProcA(hwnd, msg, wparam, lparam);
1244 static BOOL create_dde_windows(HWND *client, HWND *server)
1246 WNDCLASSA wcA;
1247 WNDCLASSW wcW;
1248 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1249 static const char client_class_name[] = "dde_client_window";
1251 memset(&wcW, 0, sizeof(wcW));
1252 wcW.lpfnWndProc = dde_server_wndprocW;
1253 wcW.lpszClassName = server_class_name;
1254 wcW.hInstance = GetModuleHandleA(0);
1255 if (!RegisterClassW(&wcW)) return FALSE;
1257 memset(&wcA, 0, sizeof(wcA));
1258 wcA.lpfnWndProc = dde_client_wndproc;
1259 wcA.lpszClassName = client_class_name;
1260 wcA.hInstance = GetModuleHandleA(0);
1261 assert(RegisterClassA(&wcA));
1263 *server = CreateWindowExW(0, server_class_name, NULL,
1264 WS_POPUP,
1265 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1266 GetDesktopWindow(), 0,
1267 GetModuleHandleA(0), NULL);
1268 assert(*server);
1270 *client = CreateWindowExA(0, client_class_name, NULL,
1271 WS_POPUP,
1272 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1273 GetDesktopWindow(), 0,
1274 GetModuleHandleA(0), NULL);
1275 assert(*client);
1277 trace("server hwnd %p, client hwnd %p\n", *server, *client);
1279 ok(IsWindowUnicode(*server), "server has to be a unicode window\n");
1280 ok(!IsWindowUnicode(*client), "client has to be an ANSI window\n");
1282 return TRUE;
1285 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1286 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1287 ULONG_PTR dwData1, ULONG_PTR dwData2)
1289 static const char * const cmd_type[15] = {
1290 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1291 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1292 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1293 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1294 UINT type;
1295 const char *cmd_name;
1297 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1298 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1300 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1301 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1302 return 0;
1305 static void test_dde_aw_transaction(void)
1307 HSZ hsz_server;
1308 DWORD dde_inst, ret, err;
1309 HCONV hconv;
1310 HWND hwnd_client, hwnd_server;
1311 CONVINFO info;
1312 HDDEDATA hdata;
1313 static char test_cmd[] = "test dde command";
1315 /* server: unicode, client: ansi */
1316 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
1318 dde_inst = 0;
1319 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1320 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
1321 ret, DdeGetLastError(dde_inst));
1323 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1325 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1326 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1327 err = DdeGetLastError(dde_inst);
1328 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1330 info.cb = sizeof(info);
1331 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1332 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1333 /* should be CP_WINANSI since we used DdeInitializeA */
1334 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1335 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1336 todo_wine {
1337 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1339 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1340 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1341 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1343 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
1345 trace("sending test client transaction command\n");
1346 ret = 0xdeadbeef;
1347 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1348 ok(!hdata, "DdeClientTransaction succeeded\n");
1349 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1350 err = DdeGetLastError(dde_inst);
1351 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1353 trace("sending ANSI client transaction command\n");
1354 ret = 0xdeadbeef;
1355 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1356 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1357 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1359 err = DdeGetLastError(dde_inst);
1360 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1362 trace("sending unicode client transaction command\n");
1363 ret = 0xdeadbeef;
1364 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1365 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1366 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1367 err = DdeGetLastError(dde_inst);
1368 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1370 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1372 info.cb = sizeof(info);
1373 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1374 ok(!ret, "DdeQueryConvInfo should fail\n");
1375 err = DdeGetLastError(dde_inst);
1376 todo_wine {
1377 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1380 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1382 /* This call hangs on win2k SP4 and XP SP1.
1383 DdeUninitialize(dde_inst);*/
1385 DestroyWindow(hwnd_client);
1386 DestroyWindow(hwnd_server);
1389 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1391 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1392 HSZ str_handle;
1393 WCHAR bufW[256];
1394 char buf[256];
1395 ATOM atom;
1396 int ret;
1398 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1399 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1400 DdeGetLastError(dde_inst));
1402 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1403 if (codepage == CP_WINANSI)
1404 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1405 else
1406 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1408 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1409 if (codepage == CP_WINANSI)
1411 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1412 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1414 else
1416 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1417 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1420 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1421 if (codepage == CP_WINANSI)
1423 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1424 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1426 else
1428 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1429 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1432 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1433 if (codepage == CP_WINANSI)
1435 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1436 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1438 else
1440 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1441 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1444 if (codepage == CP_WINANSI)
1446 atom = FindAtomA((LPSTR)dde_string);
1447 ok(atom != 0, "Expected a valid atom\n");
1449 SetLastError(0xdeadbeef);
1450 atom = GlobalFindAtomA((LPSTR)dde_string);
1451 ok(atom == 0, "Expected 0, got %d\n", atom);
1452 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1453 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1455 else
1457 atom = FindAtomW(dde_string);
1458 ok(atom != 0, "Expected a valid atom\n");
1460 SetLastError(0xdeadbeef);
1461 atom = GlobalFindAtomW(dde_string);
1462 ok(atom == 0, "Expected 0, got %d\n", atom);
1463 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1464 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1467 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1470 static void test_DdeCreateDataHandle(void)
1472 HDDEDATA hdata;
1473 DWORD dde_inst;
1474 DWORD size;
1475 UINT res, err;
1476 BOOL ret;
1477 HSZ item;
1478 LPBYTE ptr;
1480 dde_inst = 0;
1481 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1482 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1484 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1485 ok(item != NULL, "Expected non-NULL hsz\n");
1487 /* invalid instance id */
1488 DdeGetLastError(dde_inst);
1489 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1490 err = DdeGetLastError(dde_inst);
1491 todo_wine
1493 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1494 ok(err == DMLERR_INVALIDPARAMETER,
1495 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1498 /* 0 instance id */
1499 DdeGetLastError(dde_inst);
1500 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1501 err = DdeGetLastError(dde_inst);
1502 todo_wine
1504 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1505 ok(err == DMLERR_INVALIDPARAMETER,
1506 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1509 /* NULL pSrc */
1510 DdeGetLastError(dde_inst);
1511 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1512 err = DdeGetLastError(dde_inst);
1513 ok(hdata != NULL, "Expected non-NULL hdata\n");
1514 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1516 ptr = GlobalLock(hdata);
1517 todo_wine
1519 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1522 ptr = DdeAccessData(hdata, &size);
1523 ok(ptr != NULL, "Expected non-NULL ptr\n");
1524 ok(size == 260, "Expected 260, got %d\n", size);
1526 ret = DdeUnaccessData(hdata);
1527 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1529 ret = DdeFreeDataHandle(hdata);
1530 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1532 /* cb is zero */
1533 DdeGetLastError(dde_inst);
1534 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1535 err = DdeGetLastError(dde_inst);
1536 ok(hdata != NULL, "Expected non-NULL hdata\n");
1537 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1539 ptr = GlobalLock(hdata);
1540 todo_wine
1542 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1545 ptr = DdeAccessData(hdata, &size);
1546 ok(ptr != NULL, "Expected non-NULL ptr\n");
1547 ok(size == 0, "Expected 0, got %d\n", size);
1549 ret = DdeUnaccessData(hdata);
1550 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1552 ret = DdeFreeDataHandle(hdata);
1553 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1555 /* cbOff is non-zero */
1556 DdeGetLastError(dde_inst);
1557 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1558 err = DdeGetLastError(dde_inst);
1559 ok(hdata != NULL, "Expected non-NULL hdata\n");
1560 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1562 ptr = GlobalLock(hdata);
1563 todo_wine
1565 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1568 ptr = DdeAccessData(hdata, &size);
1569 ok(ptr != NULL, "Expected non-NULL ptr\n");
1570 ok(size == 262, "Expected 262, got %d\n", size);
1571 todo_wine
1573 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1576 ret = DdeUnaccessData(hdata);
1577 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1579 ret = DdeFreeDataHandle(hdata);
1580 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1582 /* NULL item */
1583 DdeGetLastError(dde_inst);
1584 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1585 err = DdeGetLastError(dde_inst);
1586 ok(hdata != NULL, "Expected non-NULL hdata\n");
1587 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1589 ptr = GlobalLock(hdata);
1590 todo_wine
1592 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1595 ptr = DdeAccessData(hdata, &size);
1596 ok(ptr != NULL, "Expected non-NULL ptr\n");
1597 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1598 ok(size == 260, "Expected 260, got %d\n", size);
1600 ret = DdeUnaccessData(hdata);
1601 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1603 ret = DdeFreeDataHandle(hdata);
1604 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1606 /* NULL item */
1607 DdeGetLastError(dde_inst);
1608 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1609 err = DdeGetLastError(dde_inst);
1610 ok(hdata != NULL, "Expected non-NULL hdata\n");
1611 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1613 ptr = GlobalLock(hdata);
1614 todo_wine
1616 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1619 ptr = DdeAccessData(hdata, &size);
1620 ok(ptr != NULL, "Expected non-NULL ptr\n");
1621 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1622 ok(size == 260, "Expected 260, got %d\n", size);
1624 ret = DdeUnaccessData(hdata);
1625 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1627 ret = DdeFreeDataHandle(hdata);
1628 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1630 /* invalid clipboard format */
1631 DdeGetLastError(dde_inst);
1632 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
1633 err = DdeGetLastError(dde_inst);
1634 ok(hdata != NULL, "Expected non-NULL hdata\n");
1635 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1637 ptr = GlobalLock(hdata);
1638 todo_wine
1640 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1643 ptr = DdeAccessData(hdata, &size);
1644 ok(ptr != NULL, "Expected non-NULL ptr\n");
1645 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1646 ok(size == 260, "Expected 260, got %d\n", size);
1648 ret = DdeUnaccessData(hdata);
1649 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1651 ret = DdeFreeDataHandle(hdata);
1652 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1654 ret = DdeUninitialize(dde_inst);
1655 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1658 static void test_DdeCreateStringHandle(void)
1660 DWORD dde_inst, ret;
1662 dde_inst = 0xdeadbeef;
1663 SetLastError(0xdeadbeef);
1664 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1665 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1667 trace("Skipping the DDE test on a Win9x platform\n");
1668 return;
1671 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
1672 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
1674 dde_inst = 0;
1675 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1676 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
1677 ret, DdeGetLastError(dde_inst));
1679 test_DdeCreateStringHandleW(dde_inst, 0);
1680 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
1681 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
1683 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
1686 static void test_FreeDDElParam(void)
1688 HGLOBAL val, hglobal;
1689 BOOL ret;
1691 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
1692 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1694 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1695 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
1696 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1697 val = GlobalFree(hglobal);
1698 ok(val == NULL, "Expected NULL, got %p\n", val);
1700 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1701 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
1702 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1703 val = GlobalFree(hglobal);
1704 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1705 ok(GetLastError() == ERROR_INVALID_HANDLE,
1706 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1708 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1709 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
1710 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1711 val = GlobalFree(hglobal);
1712 ok(val == NULL, "Expected NULL, got %p\n", val);
1714 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1715 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
1716 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1717 val = GlobalFree(hglobal);
1718 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1719 ok(GetLastError() == ERROR_INVALID_HANDLE,
1720 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1722 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1723 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
1724 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1725 val = GlobalFree(hglobal);
1726 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1727 ok(GetLastError() == ERROR_INVALID_HANDLE,
1728 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1730 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1731 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
1732 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1733 val = GlobalFree(hglobal);
1734 ok(val == NULL, "Expected NULL, got %p\n", val);
1736 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1737 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1738 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1739 val = GlobalFree(hglobal);
1740 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1741 ok(GetLastError() == ERROR_INVALID_HANDLE,
1742 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1744 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1745 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1746 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1747 val = GlobalFree(hglobal);
1748 ok(val == NULL, "Expected NULL, got %p\n", val);
1751 static void test_PackDDElParam(void)
1753 UINT_PTR lo, hi, *ptr;
1754 HGLOBAL hglobal;
1755 LPARAM lparam;
1756 BOOL ret;
1758 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1759 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1760 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1761 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1762 ok(GetLastError() == ERROR_INVALID_HANDLE,
1763 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1765 lo = hi = 0;
1766 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1767 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1768 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1769 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1771 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1772 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1774 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1775 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1776 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1777 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1778 ok(GetLastError() == ERROR_INVALID_HANDLE,
1779 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1781 lo = hi = 0;
1782 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1783 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1784 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1785 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1787 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1788 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1790 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1791 ptr = GlobalLock((HGLOBAL)lparam);
1792 ok(ptr != NULL, "Expected non-NULL ptr\n");
1793 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1794 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1796 ret = GlobalUnlock((HGLOBAL)lparam);
1797 ok(ret == 1, "Expected 1, got %d\n", ret);
1799 lo = hi = 0;
1800 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1801 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1802 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1803 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1805 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1806 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1808 hglobal = GlobalFree((HGLOBAL)lparam);
1809 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1810 ok(GetLastError() == ERROR_INVALID_HANDLE,
1811 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1813 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1814 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1815 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1816 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1817 ok(GetLastError() == ERROR_INVALID_HANDLE,
1818 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1820 lo = hi = 0;
1821 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1822 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1823 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1824 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1826 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1827 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1829 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1830 ptr = GlobalLock((HGLOBAL)lparam);
1831 ok(ptr != NULL, "Expected non-NULL ptr\n");
1832 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1833 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1835 ret = GlobalUnlock((HGLOBAL)lparam);
1836 ok(ret == 1, "Expected 1, got %d\n", ret);
1838 lo = hi = 0;
1839 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1840 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1841 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1842 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1844 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1845 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1847 hglobal = GlobalFree((HGLOBAL)lparam);
1848 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1849 ok(GetLastError() == ERROR_INVALID_HANDLE,
1850 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1852 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1853 ptr = GlobalLock((HGLOBAL)lparam);
1854 ok(ptr != NULL, "Expected non-NULL ptr\n");
1855 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1856 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1858 ret = GlobalUnlock((HGLOBAL)lparam);
1859 ok(ret == 1, "Expected 1, got %d\n", ret);
1861 lo = hi = 0;
1862 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1863 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1864 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1865 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1867 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1868 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1870 hglobal = GlobalFree((HGLOBAL)lparam);
1871 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1872 ok(GetLastError() == ERROR_INVALID_HANDLE,
1873 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1875 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1876 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1877 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1878 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1879 ok(GetLastError() == ERROR_INVALID_HANDLE,
1880 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1882 lo = hi = 0;
1883 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1884 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1885 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1886 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1888 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1889 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1891 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1892 ptr = GlobalLock((HGLOBAL)lparam);
1893 ok(ptr != NULL, "Expected non-NULL ptr\n");
1894 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1895 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1897 ret = GlobalUnlock((HGLOBAL)lparam);
1898 ok(ret == 1, "Expected 1, got %d\n", ret);
1900 lo = hi = 0;
1901 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1902 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1903 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1904 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1906 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1907 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1909 hglobal = GlobalFree((HGLOBAL)lparam);
1910 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1911 ok(GetLastError() == ERROR_INVALID_HANDLE,
1912 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1914 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1915 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1916 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1917 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1918 ok(GetLastError() == ERROR_INVALID_HANDLE,
1919 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1921 lo = hi = 0;
1922 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1923 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1924 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1925 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1927 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1928 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1931 static void test_UnpackDDElParam(void)
1933 UINT_PTR lo, hi, *ptr;
1934 HGLOBAL hglobal;
1935 BOOL ret;
1937 /* NULL lParam */
1938 lo = 0xdead;
1939 hi = 0xbeef;
1940 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1941 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1942 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1943 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1945 /* NULL lo */
1946 lo = 0xdead;
1947 hi = 0xbeef;
1948 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1949 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1950 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1951 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1953 /* NULL hi */
1954 lo = 0xdead;
1955 hi = 0xbeef;
1956 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1957 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1958 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1959 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1961 lo = 0xdead;
1962 hi = 0xbeef;
1963 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1964 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1965 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1966 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1968 lo = 0xdead;
1969 hi = 0xbeef;
1970 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1971 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1972 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1973 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1975 lo = 0xdead;
1976 hi = 0xbeef;
1977 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1978 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1979 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1980 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1982 lo = 0xdead;
1983 hi = 0xbeef;
1984 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1985 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1986 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1987 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1989 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1990 ptr = GlobalLock(hglobal);
1991 ptr[0] = 0xcafebabe;
1992 ptr[1] = 0xdeadbeef;
1993 GlobalUnlock(hglobal);
1995 lo = 0xdead;
1996 hi = 0xbeef;
1997 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
1998 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1999 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2000 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2002 lo = 0xdead;
2003 hi = 0xbeef;
2004 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2005 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2006 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2007 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2009 lo = 0xdead;
2010 hi = 0xbeef;
2011 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
2012 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2013 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2014 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2016 lo = 0xdead;
2017 hi = 0xbeef;
2018 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2019 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2020 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2021 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2023 lo = 0xdead;
2024 hi = 0xbeef;
2025 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
2026 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2027 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2028 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2030 lo = 0xdead;
2031 hi = 0xbeef;
2032 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2033 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2034 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2035 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2037 lo = 0xdead;
2038 hi = 0xbeef;
2039 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2040 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2041 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2042 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2044 lo = 0xdead;
2045 hi = 0xbeef;
2046 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
2047 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2048 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2049 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2051 lo = 0xdead;
2052 hi = 0xbeef;
2053 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2054 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2055 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2056 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2058 lo = 0xdead;
2059 hi = 0xbeef;
2060 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2061 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2062 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2063 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2066 START_TEST(dde)
2068 int argc;
2069 char **argv;
2070 char buffer[MAX_PATH];
2071 STARTUPINFO startup;
2072 PROCESS_INFORMATION proc;
2074 argc = winetest_get_mainargs(&argv);
2075 if (argc == 3)
2077 if (!lstrcmpA(argv[2], "ddeml"))
2078 test_ddeml_client();
2079 else if (!lstrcmpA(argv[2], "msg"))
2080 test_msg_client();
2082 return;
2085 ZeroMemory(&startup, sizeof(STARTUPINFO));
2086 sprintf(buffer, "%s dde ddeml", argv[0]);
2087 startup.cb = sizeof(startup);
2088 startup.dwFlags = STARTF_USESHOWWINDOW;
2089 startup.wShowWindow = SW_SHOWNORMAL;
2091 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2092 0, NULL, NULL, &startup, &proc);
2094 test_msg_server(proc.hProcess);
2096 sprintf(buffer, "%s dde msg", argv[0]);
2097 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2098 0, NULL, NULL, &startup, &proc);
2100 test_ddeml_server(proc.hProcess);
2102 test_dde_aw_transaction();
2104 test_DdeCreateDataHandle();
2105 test_DdeCreateStringHandle();
2106 test_FreeDDElParam();
2107 test_PackDDElParam();
2108 test_UnpackDDElParam();