cryptnet: Add CertDllVerifyRevocation stub.
[wine/hacks.git] / dlls / user32 / tests / dde.c
blob4f4e09c08dd0e42145160a901c189b485e0a7a42
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 LPSTR str;
258 DWORD size, res;
259 HDDEDATA hdata, op;
260 HSZ server, topic, item;
261 DWORD client_pid;
262 HCONV conversation;
264 client_pid = 0;
265 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
266 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
268 /* FIXME: make these atoms global and check them in the server */
270 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
271 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
273 DdeGetLastError(client_pid);
274 conversation = DdeConnect(client_pid, server, topic, NULL);
275 ok(conversation != NULL, "Expected non-NULL conversation\n");
276 ret = DdeGetLastError(client_pid);
277 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
279 DdeFreeStringHandle(client_pid, server);
281 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
283 /* XTYP_REQUEST, fRelease = TRUE */
284 res = 0xdeadbeef;
285 DdeGetLastError(client_pid);
286 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
287 ret = DdeGetLastError(client_pid);
288 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
289 todo_wine
291 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
292 ok(ret == DMLERR_DATAACKTIMEOUT, "Expected DMLERR_DATAACKTIMEOUT, got %d\n", ret);
295 /* XTYP_REQUEST, fAckReq = TRUE */
296 res = 0xdeadbeef;
297 DdeGetLastError(client_pid);
298 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
299 ret = DdeGetLastError(client_pid);
300 ok(hdata != NULL, "Expected non-NULL hdata\n");
301 todo_wine
303 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
304 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
307 str = (LPSTR)DdeAccessData(hdata, &size);
308 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
309 ok(size == 19, "Expected 19, got %d\n", size);
311 ret = DdeUnaccessData(hdata);
312 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
314 /* XTYP_REQUEST, all params normal */
315 res = 0xdeadbeef;
316 DdeGetLastError(client_pid);
317 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
318 ret = DdeGetLastError(client_pid);
319 ok(hdata != NULL, "Expected non-NULL hdata\n");
320 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
321 todo_wine
323 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
326 str = (LPSTR)DdeAccessData(hdata, &size);
327 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
328 ok(size == 19, "Expected 19, got %d\n", size);
330 ret = DdeUnaccessData(hdata);
331 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
333 /* XTYP_REQUEST, no item */
334 res = 0xdeadbeef;
335 DdeGetLastError(client_pid);
336 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
337 ret = DdeGetLastError(client_pid);
338 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
339 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
340 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
342 DdeFreeStringHandle(client_pid, item);
344 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
346 lstrcpyA(str, "poke data\r\n");
347 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
348 0, item, CF_TEXT, 0);
349 ok(hdata != NULL, "Expected non-NULL hdata\n");
351 /* XTYP_POKE, no item */
352 res = 0xdeadbeef;
353 DdeGetLastError(client_pid);
354 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
355 ret = DdeGetLastError(client_pid);
356 ok(op == NULL, "Expected NULL, got %p\n", op);
357 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
358 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
360 /* XTYP_POKE, no data */
361 res = 0xdeadbeef;
362 DdeGetLastError(client_pid);
363 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
364 ret = DdeGetLastError(client_pid);
365 ok(op == NULL, "Expected NULL, got %p\n", op);
366 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
367 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
369 /* XTYP_POKE, wrong size */
370 res = 0xdeadbeef;
371 DdeGetLastError(client_pid);
372 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
373 ret = DdeGetLastError(client_pid);
374 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
375 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
376 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
378 /* XTYP_POKE, correct params */
379 res = 0xdeadbeef;
380 DdeGetLastError(client_pid);
381 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
382 ret = DdeGetLastError(client_pid);
383 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
384 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
385 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
387 DdeFreeDataHandle(hdata);
389 lstrcpyA(str, "[Command(Var)]");
390 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
391 0, NULL, CF_TEXT, 0);
392 ok(hdata != NULL, "Expected non-NULL hdata\n");
394 /* XTYP_EXECUTE, correct params */
395 res = 0xdeadbeef;
396 DdeGetLastError(client_pid);
397 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
398 ret = DdeGetLastError(client_pid);
399 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
400 todo_wine
402 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
403 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
406 /* XTYP_EXECUTE, no data */
407 res = 0xdeadbeef;
408 DdeGetLastError(client_pid);
409 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
410 ret = DdeGetLastError(client_pid);
411 ok(op == NULL, "Expected NULL, got %p\n", op);
412 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
413 todo_wine
415 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
418 /* XTYP_EXECUTE, no data, -1 size */
419 res = 0xdeadbeef;
420 DdeGetLastError(client_pid);
421 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
422 ret = DdeGetLastError(client_pid);
423 ok(op == NULL, "Expected NULL, got %p\n", op);
424 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
425 todo_wine
427 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
430 DdeFreeStringHandle(client_pid, topic);
431 DdeFreeDataHandle(hdata);
433 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
435 /* verify the execute */
436 res = 0xdeadbeef;
437 DdeGetLastError(client_pid);
438 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
439 ret = DdeGetLastError(client_pid);
440 ok(hdata != NULL, "Expected non-NULL hdata\n");
441 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
442 todo_wine
444 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
447 str = (LPSTR)DdeAccessData(hdata, &size);
448 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
449 ok(size == 21, "Expected 21, got %d\n", size);
451 ret = DdeUnaccessData(hdata);
452 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
454 /* invalid transactions */
456 res = 0xdeadbeef;
457 DdeGetLastError(client_pid);
458 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
459 ret = DdeGetLastError(client_pid);
460 ok(op == NULL, "Expected NULL, got %p\n", op);
461 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
462 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
464 res = 0xdeadbeef;
465 DdeGetLastError(client_pid);
466 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, default_timeout, &res);
467 ret = DdeGetLastError(client_pid);
468 ok(op == NULL, "Expected NULL, got %p\n", op);
469 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
470 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
472 res = 0xdeadbeef;
473 DdeGetLastError(client_pid);
474 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, 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_DISCONNECT, 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_ERROR, 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_MONITOR, 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_REGISTER, 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_UNREGISTER, 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_WILDCONNECT, 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_XACT_COMPLETE, 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 DdeFreeStringHandle(client_pid, item);
538 ret = DdeDisconnect(conversation);
539 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
541 ret = DdeUninitialize(client_pid);
542 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
545 static DWORD server_pid;
547 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
548 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
549 ULONG_PTR dwData1, ULONG_PTR dwData2)
551 char str[MAX_PATH], *ptr;
552 HDDEDATA ret;
553 DWORD size;
555 static int msg_index = 0;
556 static HCONV conversation = 0;
558 msg_index++;
560 switch (uType)
562 case XTYP_REGISTER:
564 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
565 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
566 ok(hconv == 0, "Expected 0, got %p\n", hconv);
567 ok(hdata == 0, "Expected 0, got %p\n", hdata);
568 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
569 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
571 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
572 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
573 ok(size == 13, "Expected 13, got %d\n", size);
575 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
576 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
577 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
578 ok(size == 25, "Expected 25, got %d\n", size);
580 return (HDDEDATA)TRUE;
583 case XTYP_CONNECT:
585 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
586 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
587 ok(hconv == 0, "Expected 0, got %p\n", hconv);
588 ok(hdata == 0, "Expected 0, got %p\n", hdata);
589 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
590 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
592 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
593 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
594 ok(size == 12, "Expected 12, got %d\n", size);
596 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
597 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
598 ok(size == 13, "Expected 13, got %d\n", size);
600 return (HDDEDATA)TRUE;
603 case XTYP_CONNECT_CONFIRM:
605 conversation = hconv;
607 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
608 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
609 ok(hconv != NULL, "Expected non-NULL hconv\n");
610 ok(hdata == 0, "Expected 0, got %p\n", hdata);
611 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
612 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
614 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
615 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
616 ok(size == 12, "Expected 12, got %d\n", size);
618 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
619 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
620 ok(size == 13, "Expected 13, got %d\n", size);
622 return (HDDEDATA)TRUE;
625 case XTYP_REQUEST:
627 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
628 "Expected 4, 5 or 6, got %d\n", msg_index);
629 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
630 ok(hdata == 0, "Expected 0, got %p\n", hdata);
631 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
632 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
634 if (msg_index == 4)
635 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
636 else
637 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
639 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
640 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
641 ok(size == 12, "Expected 12, got %d\n", size);
643 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
645 if (msg_index == 5)
647 todo_wine
649 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
650 ok(size == 1, "Expected 1, got %d\n", size);
653 else if (msg_index == 6)
655 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
656 ok(size == 7, "Expected 7, got %d\n", size);
659 if (msg_index == 6)
661 lstrcpyA(str, "requested data\r\n");
662 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
663 0, hsz2, CF_TEXT, 0);
666 return NULL;
669 case XTYP_POKE:
671 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
672 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
673 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
674 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
675 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
677 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
678 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
679 ok(size == 12, "Expected 12, got %d\n", size);
681 ptr = (LPSTR)DdeAccessData(hdata, &size);
682 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
683 todo_wine
685 ok(size == 14, "Expected 14, got %d\n", size);
687 DdeUnaccessData(hdata);
689 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
690 if (msg_index == 7)
692 todo_wine
694 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
695 ok(size == 1, "Expected 1, got %d\n", size);
698 else
700 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
701 ok(size == 4, "Expected 4, got %d\n", size);
704 return (HDDEDATA)DDE_FACK;
707 case XTYP_EXECUTE:
709 ok(msg_index == 9 || msg_index == 10, "Expected 9 or 10, got %d\n", msg_index);
710 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
711 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
712 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
713 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
714 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
716 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
717 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
718 ok(size == 12, "Expected 12, got %d\n", size);
720 ptr = (LPSTR)DdeAccessData(hdata, &size);
722 if (msg_index == 9)
724 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
725 ok(size == 15, "Expected 15, got %d\n", size);
726 ret = (HDDEDATA)DDE_FACK;
728 else
730 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
731 ok(size == 18, "Expected 18, got %d\n", size);
732 ret = (HDDEDATA)DDE_FNOTPROCESSED;
735 DdeUnaccessData(hdata);
737 return ret;
740 case XTYP_DISCONNECT:
742 ok(msg_index == 11, "Expected 11, got %d\n", msg_index);
743 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
744 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
745 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
746 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
747 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
748 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
750 return 0;
753 default:
754 ok(FALSE, "Unhandled msg: %08x\n", uType);
757 return 0;
760 static void test_ddeml_server(HANDLE hproc)
762 MSG msg;
763 UINT res;
764 BOOL ret;
765 HSZ server;
766 HDDEDATA hdata;
768 /* set up DDE server */
769 server_pid = 0;
770 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
771 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
773 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
774 ok(server != NULL, "Expected non-NULL string handle\n");
776 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
777 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
779 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
781 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
783 ret = DdeUninitialize(server_pid);
784 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
785 GetExitCodeProcess( hproc, &res );
786 ok( !res, "client failed with %u error(s)\n", res );
789 static HWND client_hwnd, server_hwnd;
790 static ATOM server, topic, item;
791 static HGLOBAL execute_hglobal;
793 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
795 char str[MAX_PATH];
796 UINT_PTR lo, hi;
797 DDEDATA *data;
798 DDEACK *ack;
799 DWORD size;
800 LPSTR ptr;
802 static int msg_index = 0;
804 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
805 return DefWindowProcA(hwnd, msg, wparam, lparam);
807 msg_index++;
809 switch (msg)
811 case WM_DDE_INITIATE:
813 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
814 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
816 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
817 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
818 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
819 ok(size == 13, "Expected 13, got %d\n", size);
821 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
822 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
823 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
824 ok(size == 12, "Expected 12, got %d\n", size);
826 break;
829 case WM_DDE_ACK:
831 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 10),
832 "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index);
834 if (msg_index == 2)
836 server_hwnd = (HWND)wparam;
837 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
839 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
840 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
841 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
842 ok(size == 13, "Expected 13, got %d\n", size);
844 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
845 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
846 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
847 ok(size == 12, "Expected 12, got %d\n", size);
849 else if (msg_index == 9 || msg_index == 10)
851 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
853 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
855 ack = (DDEACK *)&lo;
856 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
857 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
858 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
860 ok(hi == (UINT_PTR)execute_hglobal, "Execpted execute hglobal, got %08lx\n", hi);
861 ptr = GlobalLock((HGLOBAL)hi);
863 if (msg_index == 9)
865 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
866 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
868 else
870 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
871 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
874 GlobalUnlock((HGLOBAL)hi);
876 else
878 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
880 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
882 ack = (DDEACK *)&lo;
883 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
884 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
885 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
887 if (msg_index >= 7)
888 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
889 else
891 if (msg_index == 6) todo_wine
892 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
895 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
896 if (msg_index == 3)
898 ok(hi == item, "Expected item atom, got %08lx\n", hi);
899 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
900 ok(size == 7, "Expected 7, got %d\n", size);
902 else if (msg_index == 4 || msg_index == 7)
904 ok(hi == 0, "Expected 0, got %08lx\n", hi);
905 ok(size == 0, "Expected empty string, got %d\n", size);
907 else
909 ok(hi == item, "Expected item atom, got %08lx\n", hi);
910 if (msg_index == 6) todo_wine
912 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
913 ok(size == 4, "Expected 4, got %d\n", size);
918 break;
921 case WM_DDE_DATA:
923 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
924 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
926 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
928 data = GlobalLock((HGLOBAL)lo);
929 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
930 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
931 todo_wine
933 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
935 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
936 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
937 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
938 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
939 GlobalUnlock((HGLOBAL)lo);
941 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
942 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
943 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
944 ok(size == 7, "Expected 7, got %d\n", size);
946 GlobalFree((HGLOBAL)lo);
947 GlobalDeleteAtom(hi);
949 break;
952 default:
953 ok(FALSE, "Unhandled msg: %08x\n", msg);
956 return DefWindowProcA(hwnd, msg, wparam, lparam);
959 static HGLOBAL create_poke()
961 HGLOBAL hglobal;
962 DDEPOKE *poke;
963 DWORD size;
965 size = sizeof(DDEPOKE) + lstrlenA("poke data\r\n") + 1;
966 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
967 ok(hglobal != 0, "Expected non-NULL hglobal\n");
969 poke = GlobalLock(hglobal);
970 poke->unused = 0;
971 poke->fRelease = TRUE;
972 poke->fReserved = TRUE;
973 poke->cfFormat = CF_TEXT;
974 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
975 GlobalUnlock(hglobal);
977 return hglobal;
980 static HGLOBAL create_execute(LPCSTR command)
982 HGLOBAL hglobal;
983 LPSTR ptr;
985 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
986 ok(hglobal != 0, "Expected non-NULL hglobal\n");
988 ptr = GlobalLock(hglobal);
989 lstrcpyA(ptr, command);
990 GlobalUnlock(hglobal);
992 return hglobal;
995 static void test_msg_client()
997 HGLOBAL hglobal;
998 LPARAM lparam;
1000 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1002 server = GlobalAddAtomA("TestDDEServer");
1003 ok(server != 0, "Expected non-NULL server\n");
1005 topic = GlobalAddAtomA("TestDDETopic");
1006 ok(topic != 0, "Expected non-NULL topic\n");
1008 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1010 GlobalDeleteAtom(server);
1011 GlobalDeleteAtom(topic);
1013 flush_events();
1015 item = GlobalAddAtom("request");
1016 ok(item != 0, "Expected non-NULL item\n");
1018 /* WM_DDE_REQUEST, bad clipboard format */
1019 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1020 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1022 flush_events();
1024 /* WM_DDE_REQUEST, no item */
1025 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1026 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1028 flush_events();
1030 /* WM_DDE_REQUEST, no client hwnd */
1031 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1032 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1034 flush_events();
1036 /* WM_DDE_REQUEST, correct params */
1037 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1038 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1040 flush_events();
1042 GlobalDeleteAtom(item);
1043 item = GlobalAddAtomA("poke");
1044 ok(item != 0, "Expected non-NULL item\n");
1046 hglobal = create_poke();
1048 /* WM_DDE_POKE, no ddepoke */
1049 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1050 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1052 flush_events();
1054 /* WM_DDE_POKE, no item */
1055 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1056 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1058 flush_events();
1060 hglobal = create_poke();
1062 /* WM_DDE_POKE, no client hwnd */
1063 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1064 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1066 flush_events();
1068 /* WM_DDE_POKE, all params correct */
1069 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1070 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1072 flush_events();
1074 execute_hglobal = create_execute("[Command(Var)]");
1076 /* WM_DDE_EXECUTE, no lparam */
1077 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1079 flush_events();
1081 /* WM_DDE_EXECUTE, no hglobal */
1082 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1083 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1085 flush_events();
1087 /* WM_DDE_EXECUTE, no client hwnd */
1088 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1089 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1091 flush_events();
1093 /* WM_DDE_EXECUTE, all params correct */
1094 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1095 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1097 flush_events();
1099 GlobalFree(execute_hglobal);
1100 execute_hglobal = create_execute("[BadCommand(Var)]");
1102 /* WM_DDE_EXECUTE that will get rejected */
1103 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1104 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1106 flush_events();
1108 DestroyWindow(client_hwnd);
1111 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1113 UINT_PTR lo, hi;
1115 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1117 switch (msg)
1119 case WM_DDE_ACK:
1120 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1121 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1122 break;
1124 default:
1125 break;
1127 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1130 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1132 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1134 switch (msg)
1136 case WM_DDE_INITIATE:
1138 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1140 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
1142 if (LOWORD(lparam) == aService)
1144 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
1145 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
1146 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1147 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
1149 else
1150 GlobalDeleteAtom(aService);
1151 return 0;
1154 case WM_DDE_EXECUTE:
1156 DDEACK ack;
1157 WORD status;
1158 LPCSTR cmd;
1159 UINT_PTR lo, hi;
1161 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1163 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1164 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1166 ack.bAppReturnCode = 0;
1167 ack.reserved = 0;
1168 ack.fBusy = 0;
1170 cmd = GlobalLock((HGLOBAL)hi);
1172 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
1174 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1175 /* We have to send a negative acknowledge even if we don't
1176 * accept the command, otherwise Windows goes mad and next time
1177 * we send an acknowledge DDEML drops the connection.
1178 * Not sure how to call it: a bug or a feature.
1180 ack.fAck = 0;
1182 else
1183 ack.fAck = 1;
1184 GlobalUnlock((HGLOBAL)hi);
1186 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1188 status = *((WORD *)&ack);
1189 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1191 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1192 return 0;
1195 case WM_DDE_TERMINATE:
1197 DDEACK ack;
1198 WORD status;
1200 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1202 ack.bAppReturnCode = 0;
1203 ack.reserved = 0;
1204 ack.fBusy = 0;
1205 ack.fAck = 1;
1207 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1209 status = *((WORD *)&ack);
1210 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1212 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1213 return 0;
1216 default:
1217 break;
1220 return DefWindowProcW(hwnd, msg, wparam, lparam);
1223 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1225 return DefWindowProcA(hwnd, msg, wparam, lparam);
1228 static BOOL create_dde_windows(HWND *client, HWND *server)
1230 WNDCLASSA wcA;
1231 WNDCLASSW wcW;
1232 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1233 static const char client_class_name[] = "dde_client_window";
1235 memset(&wcW, 0, sizeof(wcW));
1236 wcW.lpfnWndProc = dde_server_wndprocW;
1237 wcW.lpszClassName = server_class_name;
1238 wcW.hInstance = GetModuleHandleA(0);
1239 if (!RegisterClassW(&wcW)) return FALSE;
1241 memset(&wcA, 0, sizeof(wcA));
1242 wcA.lpfnWndProc = dde_client_wndproc;
1243 wcA.lpszClassName = client_class_name;
1244 wcA.hInstance = GetModuleHandleA(0);
1245 assert(RegisterClassA(&wcA));
1247 *server = CreateWindowExW(0, server_class_name, NULL,
1248 WS_POPUP,
1249 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1250 GetDesktopWindow(), 0,
1251 GetModuleHandleA(0), NULL);
1252 assert(*server);
1254 *client = CreateWindowExA(0, client_class_name, NULL,
1255 WS_POPUP,
1256 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1257 GetDesktopWindow(), 0,
1258 GetModuleHandleA(0), NULL);
1259 assert(*client);
1261 trace("server hwnd %p, client hwnd %p\n", *server, *client);
1263 ok(IsWindowUnicode(*server), "server has to be a unicode window\n");
1264 ok(!IsWindowUnicode(*client), "client has to be an ANSI window\n");
1266 return TRUE;
1269 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1270 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1271 ULONG_PTR dwData1, ULONG_PTR dwData2)
1273 static const char * const cmd_type[15] = {
1274 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1275 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1276 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1277 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1278 UINT type;
1279 const char *cmd_name;
1281 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1282 cmd_name = (type >= 0 && type <= 14) ? cmd_type[type] : "unknown";
1284 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1285 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1286 return 0;
1289 static void test_dde_aw_transaction(void)
1291 HSZ hsz_server;
1292 DWORD dde_inst, ret, err;
1293 HCONV hconv;
1294 HWND hwnd_client, hwnd_server;
1295 CONVINFO info;
1296 HDDEDATA hdata;
1297 static char test_cmd[] = "test dde command";
1299 /* server: unicode, client: ansi */
1300 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
1302 dde_inst = 0;
1303 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1304 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
1305 ret, DdeGetLastError(dde_inst));
1307 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1309 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1310 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1311 err = DdeGetLastError(dde_inst);
1312 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1314 info.cb = sizeof(info);
1315 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1316 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1317 /* should be CP_WINANSI since we used DdeInitializeA */
1318 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1319 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1320 todo_wine {
1321 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1323 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1324 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1325 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1327 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
1329 trace("sending test client transaction command\n");
1330 ret = 0xdeadbeef;
1331 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1332 ok(!hdata, "DdeClientTransaction succeeded\n");
1333 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1334 err = DdeGetLastError(dde_inst);
1335 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1337 trace("sending ANSI client transaction command\n");
1338 ret = 0xdeadbeef;
1339 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1340 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1341 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1343 err = DdeGetLastError(dde_inst);
1344 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1346 trace("sending unicode client transaction command\n");
1347 ret = 0xdeadbeef;
1348 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1349 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1350 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1351 err = DdeGetLastError(dde_inst);
1352 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1354 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1356 info.cb = sizeof(info);
1357 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1358 ok(!ret, "DdeQueryConvInfo should fail\n");
1359 err = DdeGetLastError(dde_inst);
1360 todo_wine {
1361 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1364 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1366 /* This call hangs on win2k SP4 and XP SP1.
1367 DdeUninitialize(dde_inst);*/
1369 DestroyWindow(hwnd_client);
1370 DestroyWindow(hwnd_server);
1373 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1375 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1376 HSZ str_handle;
1377 WCHAR bufW[256];
1378 char buf[256];
1379 ATOM atom;
1380 int ret;
1382 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1383 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1384 DdeGetLastError(dde_inst));
1386 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1387 if (codepage == CP_WINANSI)
1388 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1389 else
1390 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1392 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1393 if (codepage == CP_WINANSI)
1395 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1396 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1398 else
1400 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1401 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1404 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1405 if (codepage == CP_WINANSI)
1407 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1408 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1410 else
1412 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1413 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1416 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1417 if (codepage == CP_WINANSI)
1419 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1420 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1422 else
1424 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1425 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1428 if (codepage == CP_WINANSI)
1430 atom = FindAtomA((LPSTR)dde_string);
1431 ok(atom != 0, "Expected a valid atom\n");
1433 SetLastError(0xdeadbeef);
1434 atom = GlobalFindAtomA((LPSTR)dde_string);
1435 ok(atom == 0, "Expected 0, got %d\n", atom);
1436 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1437 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1439 else
1441 atom = FindAtomW(dde_string);
1442 ok(atom != 0, "Expected a valid atom\n");
1444 SetLastError(0xdeadbeef);
1445 atom = GlobalFindAtomW(dde_string);
1446 ok(atom == 0, "Expected 0, got %d\n", atom);
1447 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1448 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1451 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1454 static void test_DdeCreateDataHandle(void)
1456 HDDEDATA hdata;
1457 DWORD dde_inst;
1458 DWORD size;
1459 UINT res, err;
1460 BOOL ret;
1461 HSZ item;
1462 LPBYTE ptr;
1464 dde_inst = 0;
1465 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1466 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1468 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1469 ok(item != NULL, "Expected non-NULL hsz\n");
1471 /* invalid instance id */
1472 DdeGetLastError(dde_inst);
1473 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1474 err = DdeGetLastError(dde_inst);
1475 todo_wine
1477 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1478 ok(err == DMLERR_INVALIDPARAMETER,
1479 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1482 /* 0 instance id */
1483 DdeGetLastError(dde_inst);
1484 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1485 err = DdeGetLastError(dde_inst);
1486 todo_wine
1488 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1489 ok(err == DMLERR_INVALIDPARAMETER,
1490 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1493 /* NULL pSrc */
1494 DdeGetLastError(dde_inst);
1495 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1496 err = DdeGetLastError(dde_inst);
1497 ok(hdata != NULL, "Expected non-NULL hdata\n");
1498 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1500 ptr = GlobalLock(hdata);
1501 todo_wine
1503 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1506 ptr = DdeAccessData(hdata, &size);
1507 ok(ptr != NULL, "Expected non-NULL ptr\n");
1508 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1509 ok(size == 260, "Expected 260, got %d\n", size);
1511 ret = DdeUnaccessData(hdata);
1512 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1514 ret = DdeFreeDataHandle(hdata);
1515 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1517 /* cb is zero */
1518 DdeGetLastError(dde_inst);
1519 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1520 err = DdeGetLastError(dde_inst);
1521 ok(hdata != NULL, "Expected non-NULL hdata\n");
1522 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1524 ptr = GlobalLock(hdata);
1525 todo_wine
1527 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1530 ptr = DdeAccessData(hdata, &size);
1531 ok(ptr != NULL, "Expected non-NULL ptr\n");
1532 ok(lstrlenA((LPSTR)ptr) != 0, "Expected non-empty string\n");
1533 ok(lstrcmpA((LPSTR)ptr, "data"), "Did not expect data\n");
1534 ok(size == 0, "Expected 0, got %d\n", size);
1536 ret = DdeUnaccessData(hdata);
1537 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1539 ret = DdeFreeDataHandle(hdata);
1540 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1542 /* cbOff is non-zero */
1543 DdeGetLastError(dde_inst);
1544 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1545 err = DdeGetLastError(dde_inst);
1546 ok(hdata != NULL, "Expected non-NULL hdata\n");
1547 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1549 ptr = GlobalLock(hdata);
1550 todo_wine
1552 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1555 ptr = DdeAccessData(hdata, &size);
1556 ok(ptr != NULL, "Expected non-NULL ptr\n");
1557 ok(size == 262, "Expected 262, got %d\n", size);
1558 todo_wine
1560 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1563 ret = DdeUnaccessData(hdata);
1564 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1566 ret = DdeFreeDataHandle(hdata);
1567 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1569 /* NULL item */
1570 DdeGetLastError(dde_inst);
1571 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1572 err = DdeGetLastError(dde_inst);
1573 ok(hdata != NULL, "Expected non-NULL hdata\n");
1574 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1576 ptr = GlobalLock(hdata);
1577 todo_wine
1579 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1582 ptr = DdeAccessData(hdata, &size);
1583 ok(ptr != NULL, "Expected non-NULL ptr\n");
1584 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1585 ok(size == 260, "Expected 260, got %d\n", size);
1587 ret = DdeUnaccessData(hdata);
1588 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1590 ret = DdeFreeDataHandle(hdata);
1591 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1593 /* NULL item */
1594 DdeGetLastError(dde_inst);
1595 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1596 err = DdeGetLastError(dde_inst);
1597 ok(hdata != NULL, "Expected non-NULL hdata\n");
1598 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1600 ptr = GlobalLock(hdata);
1601 todo_wine
1603 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1606 ptr = DdeAccessData(hdata, &size);
1607 ok(ptr != NULL, "Expected non-NULL ptr\n");
1608 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1609 ok(size == 260, "Expected 260, got %d\n", size);
1611 ret = DdeUnaccessData(hdata);
1612 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1614 ret = DdeFreeDataHandle(hdata);
1615 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1617 /* invalid clipboard format */
1618 DdeGetLastError(dde_inst);
1619 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
1620 err = DdeGetLastError(dde_inst);
1621 ok(hdata != NULL, "Expected non-NULL hdata\n");
1622 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1624 ptr = GlobalLock(hdata);
1625 todo_wine
1627 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1630 ptr = DdeAccessData(hdata, &size);
1631 ok(ptr != NULL, "Expected non-NULL ptr\n");
1632 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1633 ok(size == 260, "Expected 260, got %d\n", size);
1635 ret = DdeUnaccessData(hdata);
1636 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1638 ret = DdeFreeDataHandle(hdata);
1639 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1641 ret = DdeUninitialize(dde_inst);
1642 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1645 static void test_DdeCreateStringHandle(void)
1647 DWORD dde_inst, ret;
1649 dde_inst = 0xdeadbeef;
1650 SetLastError(0xdeadbeef);
1651 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1652 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1654 trace("Skipping the DDE test on a Win9x platform\n");
1655 return;
1658 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
1659 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
1661 dde_inst = 0;
1662 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1663 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
1664 ret, DdeGetLastError(dde_inst));
1666 test_DdeCreateStringHandleW(dde_inst, 0);
1667 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
1668 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
1670 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
1673 static void test_FreeDDElParam(void)
1675 HGLOBAL val, hglobal;
1676 BOOL ret;
1678 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
1679 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1681 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1682 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
1683 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1684 val = GlobalFree(hglobal);
1685 ok(val == NULL, "Expected NULL, got %p\n", val);
1687 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1688 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
1689 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1690 val = GlobalFree(hglobal);
1691 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1692 ok(GetLastError() == ERROR_INVALID_HANDLE,
1693 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1695 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1696 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
1697 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1698 val = GlobalFree(hglobal);
1699 ok(val == NULL, "Expected NULL, got %p\n", val);
1701 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1702 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
1703 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1704 val = GlobalFree(hglobal);
1705 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1706 ok(GetLastError() == ERROR_INVALID_HANDLE,
1707 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1709 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1710 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
1711 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1712 val = GlobalFree(hglobal);
1713 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1714 ok(GetLastError() == ERROR_INVALID_HANDLE,
1715 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1717 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1718 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
1719 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1720 val = GlobalFree(hglobal);
1721 ok(val == NULL, "Expected NULL, got %p\n", val);
1723 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1724 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1725 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1726 val = GlobalFree(hglobal);
1727 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1728 ok(GetLastError() == ERROR_INVALID_HANDLE,
1729 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1731 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1732 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1733 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1734 val = GlobalFree(hglobal);
1735 ok(val == NULL, "Expected NULL, got %p\n", val);
1738 static void test_PackDDElParam(void)
1740 UINT_PTR lo, hi, *ptr;
1741 HGLOBAL hglobal;
1742 LPARAM lparam;
1743 BOOL ret;
1745 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1746 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1747 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1748 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1749 ok(GetLastError() == ERROR_INVALID_HANDLE,
1750 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1752 lo = hi = 0;
1753 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1754 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1755 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1756 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1758 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1759 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1761 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1762 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1763 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1764 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1765 ok(GetLastError() == ERROR_INVALID_HANDLE,
1766 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1768 lo = hi = 0;
1769 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1770 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1771 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1772 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1774 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1775 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1777 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1778 ptr = GlobalLock((HGLOBAL)lparam);
1779 ok(ptr != NULL, "Expected non-NULL ptr\n");
1780 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1781 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1783 ret = GlobalUnlock((HGLOBAL)lparam);
1784 ok(ret == 1, "Expected 1, got %d\n", ret);
1786 lo = hi = 0;
1787 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1788 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1789 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1790 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1792 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1793 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1795 hglobal = GlobalFree((HGLOBAL)lparam);
1796 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1797 ok(GetLastError() == ERROR_INVALID_HANDLE,
1798 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1800 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1801 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1802 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1803 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1804 ok(GetLastError() == ERROR_INVALID_HANDLE,
1805 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1807 lo = hi = 0;
1808 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1809 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1810 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1811 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1813 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1814 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1816 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1817 ptr = GlobalLock((HGLOBAL)lparam);
1818 ok(ptr != NULL, "Expected non-NULL ptr\n");
1819 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1820 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1822 ret = GlobalUnlock((HGLOBAL)lparam);
1823 ok(ret == 1, "Expected 1, got %d\n", ret);
1825 lo = hi = 0;
1826 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1827 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1828 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1829 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1831 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1832 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1834 hglobal = GlobalFree((HGLOBAL)lparam);
1835 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1836 ok(GetLastError() == ERROR_INVALID_HANDLE,
1837 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1839 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1840 ptr = GlobalLock((HGLOBAL)lparam);
1841 ok(ptr != NULL, "Expected non-NULL ptr\n");
1842 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1843 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1845 ret = GlobalUnlock((HGLOBAL)lparam);
1846 ok(ret == 1, "Expected 1, got %d\n", ret);
1848 lo = hi = 0;
1849 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1850 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1851 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1852 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1854 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1855 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1857 hglobal = GlobalFree((HGLOBAL)lparam);
1858 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1859 ok(GetLastError() == ERROR_INVALID_HANDLE,
1860 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1862 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1863 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1864 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1865 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1866 ok(GetLastError() == ERROR_INVALID_HANDLE,
1867 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1869 lo = hi = 0;
1870 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1871 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1872 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1873 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1875 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1876 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1878 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1879 ptr = GlobalLock((HGLOBAL)lparam);
1880 ok(ptr != NULL, "Expected non-NULL ptr\n");
1881 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1882 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1884 ret = GlobalUnlock((HGLOBAL)lparam);
1885 ok(ret == 1, "Expected 1, got %d\n", ret);
1887 lo = hi = 0;
1888 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1889 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1890 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1891 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1893 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1894 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1896 hglobal = GlobalFree((HGLOBAL)lparam);
1897 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1898 ok(GetLastError() == ERROR_INVALID_HANDLE,
1899 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1901 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1902 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1903 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1904 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1905 ok(GetLastError() == ERROR_INVALID_HANDLE,
1906 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1908 lo = hi = 0;
1909 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1910 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1911 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1912 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1914 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1915 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1918 static void test_UnpackDDElParam(void)
1920 UINT_PTR lo, hi, *ptr;
1921 HGLOBAL hglobal;
1922 BOOL ret;
1924 /* NULL lParam */
1925 lo = 0xdead;
1926 hi = 0xbeef;
1927 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1928 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1929 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1930 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1932 /* NULL lo */
1933 lo = 0xdead;
1934 hi = 0xbeef;
1935 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1936 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1937 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1938 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1940 /* NULL hi */
1941 lo = 0xdead;
1942 hi = 0xbeef;
1943 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1944 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1945 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1946 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1948 lo = 0xdead;
1949 hi = 0xbeef;
1950 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1951 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1952 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1953 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1955 lo = 0xdead;
1956 hi = 0xbeef;
1957 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1958 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1959 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1960 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1962 lo = 0xdead;
1963 hi = 0xbeef;
1964 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1965 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1966 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1967 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1969 lo = 0xdead;
1970 hi = 0xbeef;
1971 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1972 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1973 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1974 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1976 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1977 ptr = GlobalLock(hglobal);
1978 ptr[0] = 0xcafebabe;
1979 ptr[1] = 0xdeadbeef;
1980 GlobalUnlock(hglobal);
1982 lo = 0xdead;
1983 hi = 0xbeef;
1984 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
1985 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1986 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1987 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1989 lo = 0xdead;
1990 hi = 0xbeef;
1991 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
1992 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1993 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1994 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1996 lo = 0xdead;
1997 hi = 0xbeef;
1998 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
1999 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2000 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2001 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2003 lo = 0xdead;
2004 hi = 0xbeef;
2005 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2006 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2007 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2008 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2010 lo = 0xdead;
2011 hi = 0xbeef;
2012 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
2013 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2014 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2015 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2017 lo = 0xdead;
2018 hi = 0xbeef;
2019 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2020 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2021 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2022 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2024 lo = 0xdead;
2025 hi = 0xbeef;
2026 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2027 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2028 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2029 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2031 lo = 0xdead;
2032 hi = 0xbeef;
2033 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
2034 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2035 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2036 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2038 lo = 0xdead;
2039 hi = 0xbeef;
2040 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2041 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2042 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2043 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2045 lo = 0xdead;
2046 hi = 0xbeef;
2047 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2048 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2049 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2050 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2053 START_TEST(dde)
2055 int argc;
2056 char **argv;
2057 char buffer[MAX_PATH];
2058 STARTUPINFO startup;
2059 PROCESS_INFORMATION proc;
2061 argc = winetest_get_mainargs(&argv);
2062 if (argc == 3)
2064 if (!lstrcmpA(argv[2], "ddeml"))
2065 test_ddeml_client();
2066 else if (!lstrcmpA(argv[2], "msg"))
2067 test_msg_client();
2069 return;
2072 ZeroMemory(&startup, sizeof(STARTUPINFO));
2073 sprintf(buffer, "%s dde ddeml", argv[0]);
2074 startup.cb = sizeof(startup);
2075 startup.dwFlags = STARTF_USESHOWWINDOW;
2076 startup.wShowWindow = SW_SHOWNORMAL;
2078 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2079 0, NULL, NULL, &startup, &proc);
2081 test_msg_server(proc.hProcess);
2083 sprintf(buffer, "%s dde msg", argv[0]);
2084 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2085 0, NULL, NULL, &startup, &proc);
2087 test_ddeml_server(proc.hProcess);
2089 test_dde_aw_transaction();
2091 test_DdeCreateDataHandle();
2092 test_DdeCreateStringHandle();
2093 test_FreeDDElParam();
2094 test_PackDDElParam();
2095 test_UnpackDDElParam();