user32/tests: Remove an unneeded cast.
[wine/testsucceed.git] / dlls / user32 / tests / dde.c
blob0c7adba77329321061125408b9d81b90fe062fae
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 void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
44 WNDCLASSA wcA;
46 memset(&wcA, 0, sizeof(wcA));
47 wcA.lpfnWndProc = wndproc;
48 wcA.lpszClassName = name;
49 wcA.hInstance = GetModuleHandleA(0);
50 assert(RegisterClassA(&wcA));
52 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
53 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
54 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
55 assert(*hwnd);
58 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
60 UINT_PTR lo, hi;
61 char str[MAX_PATH], *ptr;
62 HGLOBAL hglobal;
63 DDEDATA *data;
64 DDEPOKE *poke;
65 DWORD size;
67 static int msg_index = 0;
68 static HWND client = 0;
69 static BOOL executed = FALSE;
71 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
72 return DefWindowProcA(hwnd, msg, wparam, lparam);
74 msg_index++;
76 switch (msg)
78 case WM_DDE_INITIATE:
80 client = (HWND)wparam;
81 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
83 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
84 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
86 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
87 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
89 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
91 break;
94 case WM_DDE_REQUEST:
96 ok((msg_index >= 2 && msg_index <= 4) ||
97 (msg_index >= 7 && msg_index <= 8),
98 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
99 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
100 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
102 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
103 if (msg_index < 8)
104 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
105 else
106 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
108 if (msg_index == 8)
110 if (executed)
111 lstrcpyA(str, "command executed\r\n");
112 else
113 lstrcpyA(str, "command not executed\r\n");
115 else
116 lstrcpyA(str, "requested data\r\n");
118 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
119 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
120 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
122 data = GlobalLock(hglobal);
123 ZeroMemory(data, size);
125 /* setting fResponse to FALSE at this point destroys
126 * the internal messaging state of native dde
128 data->fResponse = TRUE;
130 if (msg_index == 2)
131 data->fRelease = TRUE;
132 else if (msg_index == 3)
133 data->fAckReq = TRUE;
135 data->cfFormat = CF_TEXT;
136 lstrcpyA((LPSTR)data->Value, str);
137 GlobalUnlock(hglobal);
139 lparam = PackDDElParam(WM_DDE_ACK, (UINT)hglobal, HIWORD(lparam));
140 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
142 break;
145 case WM_DDE_POKE:
147 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
148 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
150 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
152 GlobalGetAtomNameA(hi, str, MAX_PATH);
153 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
155 poke = GlobalLock((HGLOBAL)lo);
156 ok(poke != NULL, "Expected non-NULL poke\n");
157 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
158 todo_wine
160 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
162 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
163 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
165 if (msg_index == 5)
166 ok(lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
167 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
168 else
169 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
170 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
172 GlobalUnlock((HGLOBAL)lo);
174 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
175 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
177 break;
180 case WM_DDE_EXECUTE:
182 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
183 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
185 ptr = GlobalLock((HGLOBAL)lparam);
186 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
187 GlobalUnlock((HGLOBAL)lparam);
189 executed = TRUE;
191 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
192 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
194 break;
197 case WM_DDE_TERMINATE:
199 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
200 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
201 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
203 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
205 break;
208 default:
209 ok(FALSE, "Unhandled msg: %08x\n", msg);
212 return DefWindowProcA(hwnd, msg, wparam, lparam);
215 static void test_msg_server(HANDLE hproc)
217 MSG msg;
218 HWND hwnd;
220 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
224 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
225 } while (WaitForSingleObject(hproc, 500) == WAIT_TIMEOUT);
227 DestroyWindow(hwnd);
230 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
231 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
232 ULONG_PTR dwData1, ULONG_PTR dwData2)
234 ok(FALSE, "Unhandled msg: %08x\n", uType);
235 return 0;
238 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
240 UINT_PTR lo, hi;
242 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
244 switch (msg)
246 case WM_DDE_ACK:
247 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
248 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
249 break;
251 default:
252 break;
254 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
257 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
259 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
261 switch (msg)
263 case WM_DDE_INITIATE:
265 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
267 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
269 if (LOWORD(lparam) == aService)
271 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
272 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
273 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
274 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
276 else
277 GlobalDeleteAtom(aService);
278 return 0;
281 case WM_DDE_EXECUTE:
283 DDEACK ack;
284 WORD status;
285 LPCSTR cmd;
286 UINT_PTR lo, hi;
288 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
290 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
291 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
293 ack.bAppReturnCode = 0;
294 ack.reserved = 0;
295 ack.fBusy = 0;
297 cmd = GlobalLock((HGLOBAL)hi);
299 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
301 trace("ignoring unknown WM_DDE_EXECUTE command\n");
302 /* We have to send a negative acknowledge even if we don't
303 * accept the command, otherwise Windows goes mad and next time
304 * we send an acknowledge DDEML drops the connection.
305 * Not sure how to call it: a bug or a feature.
307 ack.fAck = 0;
309 else
310 ack.fAck = 1;
311 GlobalUnlock((HGLOBAL)hi);
313 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
315 status = *((WORD *)&ack);
316 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
318 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
319 return 0;
322 case WM_DDE_TERMINATE:
324 DDEACK ack;
325 WORD status;
327 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
329 ack.bAppReturnCode = 0;
330 ack.reserved = 0;
331 ack.fBusy = 0;
332 ack.fAck = 1;
334 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
336 status = *((WORD *)&ack);
337 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
339 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
340 return 0;
343 default:
344 break;
347 return DefWindowProcW(hwnd, msg, wparam, lparam);
350 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
352 return DefWindowProcA(hwnd, msg, wparam, lparam);
355 static BOOL create_dde_windows(HWND *hwnd_client, HWND *hwnd_server)
357 WNDCLASSA wcA;
358 WNDCLASSW wcW;
359 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
360 static const char client_class_name[] = "dde_client_window";
362 memset(&wcW, 0, sizeof(wcW));
363 wcW.lpfnWndProc = dde_server_wndprocW;
364 wcW.lpszClassName = server_class_name;
365 wcW.hInstance = GetModuleHandleA(0);
366 if (!RegisterClassW(&wcW)) return FALSE;
368 memset(&wcA, 0, sizeof(wcA));
369 wcA.lpfnWndProc = dde_client_wndproc;
370 wcA.lpszClassName = client_class_name;
371 wcA.hInstance = GetModuleHandleA(0);
372 assert(RegisterClassA(&wcA));
374 *hwnd_server = CreateWindowExW(0, server_class_name, NULL,
375 WS_POPUP,
376 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
377 GetDesktopWindow(), 0,
378 GetModuleHandleA(0), NULL);
379 assert(*hwnd_server);
381 *hwnd_client = CreateWindowExA(0, client_class_name, NULL,
382 WS_POPUP,
383 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
384 GetDesktopWindow(), 0,
385 GetModuleHandleA(0), NULL);
386 assert(*hwnd_client);
388 trace("server hwnd %p, client hwnd %p\n", *hwnd_server, *hwnd_client);
390 ok(IsWindowUnicode(*hwnd_server), "server has to be a unicode window\n");
391 ok(!IsWindowUnicode(*hwnd_client), "client has to be an ANSI window\n");
393 return TRUE;
396 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
397 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
398 ULONG_PTR dwData1, ULONG_PTR dwData2)
400 static const char * const cmd_type[15] = {
401 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
402 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
403 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
404 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
405 UINT type;
406 const char *cmd_name;
408 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
409 cmd_name = (type >= 0 && type <= 14) ? cmd_type[type] : "unknown";
411 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
412 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
413 return 0;
416 static void test_dde_aw_transaction(void)
418 HSZ hsz_server;
419 DWORD dde_inst, ret, err;
420 HCONV hconv;
421 HWND hwnd_client, hwnd_server;
422 CONVINFO info;
423 HDDEDATA hdata;
424 static char test_cmd[] = "test dde command";
426 /* server: unicode, client: ansi */
427 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
429 dde_inst = 0;
430 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
431 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
432 ret, DdeGetLastError(dde_inst));
434 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
436 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
437 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
438 err = DdeGetLastError(dde_inst);
439 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
441 info.cb = sizeof(info);
442 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
443 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
444 /* should be CP_WINANSI since we used DdeInitializeA */
445 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
446 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
447 todo_wine {
448 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
450 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
451 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
452 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
454 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
456 trace("sending test client transaction command\n");
457 ret = 0xdeadbeef;
458 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
459 ok(!hdata, "DdeClientTransaction succeeded\n");
460 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
461 err = DdeGetLastError(dde_inst);
462 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
464 trace("sending ANSI client transaction command\n");
465 ret = 0xdeadbeef;
466 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
467 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
468 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
470 err = DdeGetLastError(dde_inst);
471 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
473 trace("sending unicode client transaction command\n");
474 ret = 0xdeadbeef;
475 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
476 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
477 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
478 err = DdeGetLastError(dde_inst);
479 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
481 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
483 info.cb = sizeof(info);
484 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
485 ok(!ret, "DdeQueryConvInfo should fail\n");
486 err = DdeGetLastError(dde_inst);
487 todo_wine {
488 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
491 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
493 /* This call hangs on win2k SP4 and XP SP1.
494 DdeUninitialize(dde_inst);*/
496 DestroyWindow(hwnd_client);
497 DestroyWindow(hwnd_server);
500 static void test_ddeml_client(void)
502 UINT ret;
503 LPSTR str;
504 DWORD size, res;
505 HDDEDATA hdata, op;
506 HSZ server, topic, item;
507 DWORD client_pid;
508 HCONV conversation;
510 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
511 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
513 /* FIXME: make these atoms global and check them in the server */
515 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
516 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
518 DdeGetLastError(client_pid);
519 conversation = DdeConnect(client_pid, server, topic, NULL);
520 ok(conversation != NULL, "Expected non-NULL conversation\n");
521 ret = DdeGetLastError(client_pid);
522 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
524 DdeFreeStringHandle(client_pid, server);
526 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
528 /* XTYP_REQUEST, fRelease = TRUE */
529 res = 0xdeadbeef;
530 DdeGetLastError(client_pid);
531 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
532 ret = DdeGetLastError(client_pid);
533 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
534 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
535 ok(ret == DMLERR_DATAACKTIMEOUT, "Expected DMLERR_DATAACKTIMEOUT, got %d\n", ret);
537 /* XTYP_REQUEST, fAckReq = TRUE */
538 res = 0xdeadbeef;
539 DdeGetLastError(client_pid);
540 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
541 ret = DdeGetLastError(client_pid);
542 ok(hdata != NULL, "Expected non-NULL hdata\n");
543 todo_wine
545 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
546 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
549 str = (LPSTR)DdeAccessData(hdata, &size);
550 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
551 ok(size == 19, "Expected 19, got %d\n", size);
553 ret = DdeUnaccessData(hdata);
554 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
556 /* XTYP_REQUEST, all params normal */
557 res = 0xdeadbeef;
558 DdeGetLastError(client_pid);
559 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
560 ret = DdeGetLastError(client_pid);
561 todo_wine
563 ok(hdata != NULL, "Expected non-NULL hdata\n");
564 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
565 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
568 str = (LPSTR)DdeAccessData(hdata, &size);
569 todo_wine
571 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
573 ok(size == 19, "Expected 19, got %d\n", size);
575 ret = DdeUnaccessData(hdata);
576 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
578 /* XTYP_REQUEST, no item */
579 res = 0xdeadbeef;
580 DdeGetLastError(client_pid);
581 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, 500, &res);
582 ret = DdeGetLastError(client_pid);
583 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
584 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
585 todo_wine
587 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
590 DdeFreeStringHandle(client_pid, item);
592 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
594 lstrcpyA(str, "poke data\r\n");
595 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
596 0, item, CF_TEXT, 0);
597 ok(hdata != NULL, "Expected non-NULL hdata\n");
599 /* XTYP_POKE, no item */
600 res = 0xdeadbeef;
601 DdeGetLastError(client_pid);
602 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, 500, &res);
603 ret = DdeGetLastError(client_pid);
604 ok(op == NULL, "Expected NULL, got %p\n", op);
605 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
606 todo_wine
608 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
611 /* XTYP_POKE, no data */
612 res = 0xdeadbeef;
613 DdeGetLastError(client_pid);
614 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, 500, &res);
615 ret = DdeGetLastError(client_pid);
616 ok(op == NULL, "Expected NULL, got %p\n", op);
617 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
618 todo_wine
620 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
623 /* XTYP_POKE, wrong size */
624 res = 0xdeadbeef;
625 DdeGetLastError(client_pid);
626 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, 500, &res);
627 ret = DdeGetLastError(client_pid);
628 todo_wine
630 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
631 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
633 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
635 /* XTYP_POKE, correct params */
636 res = 0xdeadbeef;
637 DdeGetLastError(client_pid);
638 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, 500, &res);
639 ret = DdeGetLastError(client_pid);
640 todo_wine
642 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
643 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
644 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
647 DdeFreeDataHandle(hdata);
649 lstrcpyA(str, "[Command(Var)]");
650 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)str, lstrlenA(str) + 1,
651 0, NULL, CF_TEXT, 0);
652 ok(hdata != NULL, "Expected non-NULL hdata\n");
654 /* XTYP_EXECUTE, correct params */
655 res = 0xdeadbeef;
656 DdeGetLastError(client_pid);
657 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
658 ret = DdeGetLastError(client_pid);
659 todo_wine
661 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
662 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
663 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
666 /* XTYP_EXECUTE, no data */
667 res = 0xdeadbeef;
668 DdeGetLastError(client_pid);
669 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
670 ret = DdeGetLastError(client_pid);
671 ok(op == NULL, "Expected NULL, got %p\n", op);
672 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
673 todo_wine
675 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
678 /* XTYP_EXECUTE, no data, -1 size */
679 res = 0xdeadbeef;
680 DdeGetLastError(client_pid);
681 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, 5000, &res);
682 ret = DdeGetLastError(client_pid);
683 ok(op == NULL, "Expected NULL, got %p\n", op);
684 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
685 todo_wine
687 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
690 DdeFreeStringHandle(client_pid, topic);
691 DdeFreeDataHandle(hdata);
693 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
695 /* verify the execute */
696 res = 0xdeadbeef;
697 DdeGetLastError(client_pid);
698 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, 500, &res);
699 ret = DdeGetLastError(client_pid);
700 todo_wine
702 ok(hdata != NULL, "Expected non-NULL hdata\n");
703 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
704 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
707 str = (LPSTR)DdeAccessData(hdata, &size);
708 todo_wine
710 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
711 ok(size == 21, "Expected 21, got %d\n", size);
714 ret = DdeUnaccessData(hdata);
715 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
717 /* invalid transactions */
719 res = 0xdeadbeef;
720 DdeGetLastError(client_pid);
721 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, 500, &res);
722 ret = DdeGetLastError(client_pid);
723 ok(op == NULL, "Expected NULL, got %p\n", op);
724 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
725 todo_wine
727 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
730 res = 0xdeadbeef;
731 DdeGetLastError(client_pid);
732 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, 500, &res);
733 ret = DdeGetLastError(client_pid);
734 ok(op == NULL, "Expected NULL, got %p\n", op);
735 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
736 todo_wine
738 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
741 res = 0xdeadbeef;
742 DdeGetLastError(client_pid);
743 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, 500, &res);
744 ret = DdeGetLastError(client_pid);
745 ok(op == NULL, "Expected NULL, got %p\n", op);
746 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
747 todo_wine
749 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
752 res = 0xdeadbeef;
753 DdeGetLastError(client_pid);
754 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, 500, &res);
755 ret = DdeGetLastError(client_pid);
756 ok(op == NULL, "Expected NULL, got %p\n", op);
757 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
758 todo_wine
760 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
763 res = 0xdeadbeef;
764 DdeGetLastError(client_pid);
765 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, 500, &res);
766 ret = DdeGetLastError(client_pid);
767 ok(op == NULL, "Expected NULL, got %p\n", op);
768 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
769 todo_wine
771 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
774 res = 0xdeadbeef;
775 DdeGetLastError(client_pid);
776 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, 500, &res);
777 ret = DdeGetLastError(client_pid);
778 ok(op == NULL, "Expected NULL, got %p\n", op);
779 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
780 todo_wine
782 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
785 res = 0xdeadbeef;
786 DdeGetLastError(client_pid);
787 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, 500, &res);
788 ret = DdeGetLastError(client_pid);
789 ok(op == NULL, "Expected NULL, got %p\n", op);
790 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
791 todo_wine
793 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
796 res = 0xdeadbeef;
797 DdeGetLastError(client_pid);
798 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, 500, &res);
799 ret = DdeGetLastError(client_pid);
800 ok(op == NULL, "Expected NULL, got %p\n", op);
801 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
802 todo_wine
804 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
807 res = 0xdeadbeef;
808 DdeGetLastError(client_pid);
809 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, 500, &res);
810 ret = DdeGetLastError(client_pid);
811 ok(op == NULL, "Expected NULL, got %p\n", op);
812 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
813 todo_wine
815 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
818 res = 0xdeadbeef;
819 DdeGetLastError(client_pid);
820 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, 500, &res);
821 ret = DdeGetLastError(client_pid);
822 ok(op == NULL, "Expected NULL, got %p\n", op);
823 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
824 todo_wine
826 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
829 DdeFreeStringHandle(client_pid, item);
831 ret = DdeDisconnect(conversation);
832 todo_wine
834 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
837 ret = DdeUninitialize(client_pid);
838 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
841 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
843 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
844 HSZ str_handle;
845 WCHAR bufW[256];
846 char buf[256];
847 ATOM atom;
848 int ret;
850 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
851 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
852 DdeGetLastError(dde_inst));
854 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
855 if (codepage == CP_WINANSI)
856 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
857 else
858 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
860 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
861 if (codepage == CP_WINANSI)
863 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
864 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
866 else
868 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
869 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
872 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
873 if (codepage == CP_WINANSI)
875 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
876 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
878 else
880 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
881 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
884 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
885 if (codepage == CP_WINANSI)
887 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
888 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
890 else
892 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
893 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
896 if (codepage == CP_WINANSI)
898 atom = FindAtomA((LPSTR)dde_string);
899 ok(atom != 0, "Expected a valid atom\n");
901 SetLastError(0xdeadbeef);
902 atom = GlobalFindAtomA((LPSTR)dde_string);
903 ok(atom == 0, "Expected 0, got %d\n", atom);
904 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
905 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
907 else
909 atom = FindAtomW(dde_string);
910 ok(atom != 0, "Expected a valid atom\n");
912 SetLastError(0xdeadbeef);
913 atom = GlobalFindAtomW(dde_string);
914 ok(atom == 0, "Expected 0, got %d\n", atom);
915 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
916 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
919 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
922 static void test_DdeCreateStringHandle(void)
924 DWORD dde_inst, ret;
926 dde_inst = 0xdeadbeef;
927 SetLastError(0xdeadbeef);
928 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
929 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
931 trace("Skipping the DDE test on a Win9x platform\n");
932 return;
935 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
936 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
938 dde_inst = 0;
939 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
940 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
941 ret, DdeGetLastError(dde_inst));
943 test_DdeCreateStringHandleW(dde_inst, 0);
944 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
945 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
947 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
950 static void test_FreeDDElParam(void)
952 HGLOBAL val, hglobal;
953 BOOL ret;
955 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
956 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
958 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
959 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
960 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
961 val = GlobalFree(hglobal);
962 ok(val == NULL, "Expected NULL, got %p\n", val);
964 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
965 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
966 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
967 val = GlobalFree(hglobal);
968 ok(val == hglobal, "Expected hglobal, got %p\n", val);
969 ok(GetLastError() == ERROR_INVALID_HANDLE,
970 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
972 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
973 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
974 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
975 val = GlobalFree(hglobal);
976 ok(val == NULL, "Expected NULL, got %p\n", val);
978 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
979 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
980 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
981 val = GlobalFree(hglobal);
982 ok(val == hglobal, "Expected hglobal, got %p\n", val);
983 ok(GetLastError() == ERROR_INVALID_HANDLE,
984 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
986 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
987 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
988 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
989 val = GlobalFree(hglobal);
990 ok(val == hglobal, "Expected hglobal, got %p\n", val);
991 ok(GetLastError() == ERROR_INVALID_HANDLE,
992 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
994 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
995 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
996 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
997 val = GlobalFree(hglobal);
998 ok(val == NULL, "Expected NULL, got %p\n", val);
1000 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1001 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1002 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1003 val = GlobalFree(hglobal);
1004 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1005 ok(GetLastError() == ERROR_INVALID_HANDLE,
1006 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1008 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1009 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1010 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1011 val = GlobalFree(hglobal);
1012 ok(val == NULL, "Expected NULL, got %p\n", val);
1015 static void test_PackDDElParam(void)
1017 UINT_PTR lo, hi, *ptr;
1018 HGLOBAL hglobal;
1019 LPARAM lparam;
1020 BOOL ret;
1022 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1023 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1024 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1025 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1026 ok(GetLastError() == ERROR_INVALID_HANDLE,
1027 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1029 lo = hi = 0;
1030 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1031 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1032 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1033 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1035 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1036 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1038 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1039 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1040 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1041 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1042 ok(GetLastError() == ERROR_INVALID_HANDLE,
1043 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1045 lo = hi = 0;
1046 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1047 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1048 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1049 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1051 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1052 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1054 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1055 ptr = GlobalLock((HGLOBAL)lparam);
1056 ok(ptr != NULL, "Expected non-NULL ptr\n");
1057 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1058 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1060 ret = GlobalUnlock((HGLOBAL)lparam);
1061 ok(ret == 1, "Expected 1, got %d\n", ret);
1063 lo = hi = 0;
1064 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1065 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1066 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1067 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1069 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1070 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1072 hglobal = GlobalFree((HGLOBAL)lparam);
1073 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1074 ok(GetLastError() == ERROR_INVALID_HANDLE,
1075 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1077 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1078 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1079 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1080 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1081 ok(GetLastError() == ERROR_INVALID_HANDLE,
1082 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1084 lo = hi = 0;
1085 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1086 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1087 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1088 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1090 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1091 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1093 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1094 ptr = GlobalLock((HGLOBAL)lparam);
1095 ok(ptr != NULL, "Expected non-NULL ptr\n");
1096 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1097 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1099 ret = GlobalUnlock((HGLOBAL)lparam);
1100 ok(ret == 1, "Expected 1, got %d\n", ret);
1102 lo = hi = 0;
1103 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1104 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1105 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1106 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1108 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1109 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1111 hglobal = GlobalFree((HGLOBAL)lparam);
1112 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1113 ok(GetLastError() == ERROR_INVALID_HANDLE,
1114 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1116 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1117 ptr = GlobalLock((HGLOBAL)lparam);
1118 ok(ptr != NULL, "Expected non-NULL ptr\n");
1119 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1120 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1122 ret = GlobalUnlock((HGLOBAL)lparam);
1123 ok(ret == 1, "Expected 1, got %d\n", ret);
1125 lo = hi = 0;
1126 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1127 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1128 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1129 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1131 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1132 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1134 hglobal = GlobalFree((HGLOBAL)lparam);
1135 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1136 ok(GetLastError() == ERROR_INVALID_HANDLE,
1137 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1139 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1140 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1141 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1142 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1143 ok(GetLastError() == ERROR_INVALID_HANDLE,
1144 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1146 lo = hi = 0;
1147 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
1148 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1149 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1150 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1152 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
1153 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1155 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
1156 ptr = GlobalLock((HGLOBAL)lparam);
1157 ok(ptr != NULL, "Expected non-NULL ptr\n");
1158 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1159 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1161 ret = GlobalUnlock((HGLOBAL)lparam);
1162 ok(ret == 1, "Expected 1, got %d\n", ret);
1164 lo = hi = 0;
1165 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
1166 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1167 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1168 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1170 ret = FreeDDElParam(WM_DDE_POKE, lparam);
1171 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1173 hglobal = GlobalFree((HGLOBAL)lparam);
1174 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1175 ok(GetLastError() == ERROR_INVALID_HANDLE,
1176 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1178 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
1179 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
1180 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1181 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1182 ok(GetLastError() == ERROR_INVALID_HANDLE,
1183 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1185 lo = hi = 0;
1186 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1187 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1188 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1189 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1191 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
1192 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1195 static void test_UnpackDDElParam(void)
1197 UINT_PTR lo, hi, *ptr;
1198 HGLOBAL hglobal;
1199 BOOL ret;
1201 /* NULL lParam */
1202 lo = 0xdead;
1203 hi = 0xbeef;
1204 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
1205 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1206 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1207 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1209 /* NULL lo */
1210 lo = 0xdead;
1211 hi = 0xbeef;
1212 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
1213 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1214 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
1215 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1217 /* NULL hi */
1218 lo = 0xdead;
1219 hi = 0xbeef;
1220 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
1221 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1222 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1223 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1225 lo = 0xdead;
1226 hi = 0xbeef;
1227 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
1228 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1229 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1230 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1232 lo = 0xdead;
1233 hi = 0xbeef;
1234 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
1235 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1236 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1237 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1239 lo = 0xdead;
1240 hi = 0xbeef;
1241 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
1242 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1243 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1244 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1246 lo = 0xdead;
1247 hi = 0xbeef;
1248 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
1249 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1250 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1251 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1253 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
1254 ptr = GlobalLock(hglobal);
1255 ptr[0] = 0xcafebabe;
1256 ptr[1] = 0xdeadbeef;
1257 GlobalUnlock(hglobal);
1259 lo = 0xdead;
1260 hi = 0xbeef;
1261 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
1262 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1263 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1264 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1266 lo = 0xdead;
1267 hi = 0xbeef;
1268 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
1269 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1270 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1271 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1273 lo = 0xdead;
1274 hi = 0xbeef;
1275 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
1276 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1277 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1278 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1280 lo = 0xdead;
1281 hi = 0xbeef;
1282 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
1283 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1284 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1285 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1287 lo = 0xdead;
1288 hi = 0xbeef;
1289 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
1290 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1291 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1292 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1294 lo = 0xdead;
1295 hi = 0xbeef;
1296 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
1297 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1298 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1299 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1301 lo = 0xdead;
1302 hi = 0xbeef;
1303 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
1304 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1305 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
1306 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
1308 lo = 0xdead;
1309 hi = 0xbeef;
1310 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
1311 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1312 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1313 ok(hi == 0, "Expected 0, got %08lx\n", hi);
1315 lo = 0xdead;
1316 hi = 0xbeef;
1317 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
1318 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1319 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
1320 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
1322 lo = 0xdead;
1323 hi = 0xbeef;
1324 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
1325 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1326 ok(lo == 0, "Expected 0, got %08lx\n", lo);
1327 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
1330 START_TEST(dde)
1332 int argc;
1333 char **argv;
1334 char buffer[MAX_PATH];
1335 STARTUPINFO startup;
1336 PROCESS_INFORMATION proc;
1338 argc = winetest_get_mainargs(&argv);
1339 if (argc == 3)
1341 if (!lstrcmpA(argv[2], "ddeml"))
1342 test_ddeml_client();
1344 return;
1347 ZeroMemory(&startup, sizeof(STARTUPINFO));
1348 sprintf(buffer, "%s dde ddeml", argv[0]);
1349 startup.cb = sizeof(startup);
1350 startup.dwFlags = STARTF_USESHOWWINDOW;
1351 startup.wShowWindow = SW_SHOWNORMAL;
1353 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
1354 0, NULL, NULL, &startup, &proc);
1356 test_msg_server(proc.hProcess);
1358 test_dde_aw_transaction();
1360 test_DdeCreateStringHandle();
1361 test_FreeDDElParam();
1362 test_PackDDElParam();
1363 test_UnpackDDElParam();