2 * Unit tests for DDE functions
4 * Copyright (c) 2004 Dmitry Timoshkov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
30 static const WCHAR TEST_DDE_SERVICE[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
32 static char exec_cmdA[] = "ANSI dde command";
33 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
35 static WNDPROC old_dde_client_wndproc;
37 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
41 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
46 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
47 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
53 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
56 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
58 trace("dde_server_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
64 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
66 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
68 if (LOWORD(lparam) == aService)
70 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
71 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
72 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
73 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
76 GlobalDeleteAtom(aService);
87 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
89 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
90 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
92 ack.bAppReturnCode = 0;
96 cmd = GlobalLock((HGLOBAL)hi);
98 if (!cmd || (lstrcmpW((LPCWSTR)cmd, exec_cmdW) && lstrcmpA(cmd, exec_cmdA)))
100 trace("ignoring unknown WM_DDE_EXECUTE command\n");
101 /* We have to send a negative acknowledge even if we don't
102 * accept the command, otherwise Windows goes mad and next time
103 * we send an acknowledge DDEML drops the connection.
104 * Not sure how to call it: a bug or a feature.
110 GlobalUnlock((HGLOBAL)hi);
112 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
114 status = *((WORD *)&ack);
115 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
117 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
121 case WM_DDE_TERMINATE:
126 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
128 ack.bAppReturnCode = 0;
133 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
135 status = *((WORD *)&ack);
136 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
138 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
146 return DefWindowProcW(hwnd, msg, wparam, lparam);
149 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
151 return DefWindowProcA(hwnd, msg, wparam, lparam);
154 static BOOL create_dde_windows(HWND *hwnd_client, HWND *hwnd_server)
158 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
159 static const char client_class_name[] = "dde_client_window";
161 memset(&wcW, 0, sizeof(wcW));
162 wcW.lpfnWndProc = dde_server_wndproc;
163 wcW.lpszClassName = server_class_name;
164 wcW.hInstance = GetModuleHandleA(0);
165 if (!RegisterClassW(&wcW)) return FALSE;
167 memset(&wcA, 0, sizeof(wcA));
168 wcA.lpfnWndProc = dde_client_wndproc;
169 wcA.lpszClassName = client_class_name;
170 wcA.hInstance = GetModuleHandleA(0);
171 assert(RegisterClassA(&wcA));
173 *hwnd_server = CreateWindowExW(0, server_class_name, NULL,
175 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
176 GetDesktopWindow(), 0,
177 GetModuleHandleA(0), NULL);
178 assert(*hwnd_server);
180 *hwnd_client = CreateWindowExA(0, client_class_name, NULL,
182 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
183 GetDesktopWindow(), 0,
184 GetModuleHandleA(0), NULL);
185 assert(*hwnd_client);
187 trace("server hwnd %p, client hwnd %p\n", *hwnd_server, *hwnd_client);
189 ok(IsWindowUnicode(*hwnd_server), "server has to be a unicode window\n");
190 ok(!IsWindowUnicode(*hwnd_client), "client has to be an ANSI window\n");
195 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
196 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
197 ULONG_PTR dwData1, ULONG_PTR dwData2)
199 static const char * const cmd_type[15] = {
200 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
201 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
202 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
203 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
205 const char *cmd_name;
207 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
208 cmd_name = (type >= 0 && type <= 14) ? cmd_type[type] : "unknown";
210 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
211 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
215 static void test_dde_transaction(void)
218 DWORD dde_inst, ret, err;
220 HWND hwnd_client, hwnd_server;
223 static char test_cmd[] = "test dde command";
225 /* server: unicode, client: ansi */
226 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
229 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
230 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%x)\n",
231 ret, DdeGetLastError(dde_inst));
233 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
235 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
236 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
237 err = DdeGetLastError(dde_inst);
238 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
240 info.cb = sizeof(info);
241 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
242 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
243 /* should be CP_WINANSI since we used DdeInitializeA */
244 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
245 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
247 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
249 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
250 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
251 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
253 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
255 trace("sending test client transaction command\n");
257 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
258 ok(!hdata, "DdeClientTransaction succeeded\n");
259 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
260 err = DdeGetLastError(dde_inst);
261 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
263 trace("sending ANSI client transaction command\n");
265 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
266 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
267 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
269 err = DdeGetLastError(dde_inst);
270 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
272 trace("sending unicode client transaction command\n");
274 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
275 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
276 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
277 err = DdeGetLastError(dde_inst);
278 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
280 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
282 info.cb = sizeof(info);
283 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
284 ok(!ret, "DdeQueryConvInfo should fail\n");
285 err = DdeGetLastError(dde_inst);
287 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
290 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
292 /* This call hangs on win2k SP4 and XP SP1.
293 DdeUninitialize(dde_inst);*/
295 DestroyWindow(hwnd_client);
296 DestroyWindow(hwnd_server);
299 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
301 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
307 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
308 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
309 DdeGetLastError(dde_inst));
311 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
312 if (codepage == CP_WINANSI)
313 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
315 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
317 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
318 if (codepage == CP_WINANSI)
320 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
321 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
325 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
326 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
329 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
330 if (codepage == CP_WINANSI)
332 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
333 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
337 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
338 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
341 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
342 if (codepage == CP_WINANSI)
344 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
345 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
349 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
350 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
353 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
356 static void test_DdeCreateStringHandle(void)
360 dde_inst = 0xdeadbeef;
361 SetLastError(0xdeadbeef);
362 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
363 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
365 trace("Skipping the DDE test on a Win9x platform\n");
369 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
370 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
373 ret = DdeInitializeW(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
374 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
375 ret, DdeGetLastError(dde_inst));
377 test_DdeCreateStringHandleW(dde_inst, 0);
378 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
379 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
381 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
384 static void test_FreeDDElParam(void)
386 HGLOBAL val, hglobal;
389 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)NULL);
390 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
392 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
393 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
394 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
395 val = GlobalFree(hglobal);
396 ok(val == NULL, "Expected NULL, got %p\n", val);
398 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
399 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
400 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
401 val = GlobalFree(hglobal);
404 ok(val == hglobal, "Expected hglobal, got %p\n", val);
405 ok(GetLastError() == ERROR_INVALID_HANDLE,
406 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
409 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
410 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
411 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
412 val = GlobalFree(hglobal);
413 ok(val == NULL, "Expected NULL, got %p\n", val);
415 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
416 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
417 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
418 val = GlobalFree(hglobal);
421 ok(val == hglobal, "Expected hglobal, got %p\n", val);
422 ok(GetLastError() == ERROR_INVALID_HANDLE,
423 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
426 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
427 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
428 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
429 val = GlobalFree(hglobal);
432 ok(val == hglobal, "Expected hglobal, got %p\n", val);
433 ok(GetLastError() == ERROR_INVALID_HANDLE,
434 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
437 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
438 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
439 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
440 val = GlobalFree(hglobal);
441 ok(val == NULL, "Expected NULL, got %p\n", val);
443 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
444 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
445 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
446 val = GlobalFree(hglobal);
449 ok(val == hglobal, "Expected hglobal, got %p\n", val);
450 ok(GetLastError() == ERROR_INVALID_HANDLE,
451 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
454 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
455 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
456 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
457 val = GlobalFree(hglobal);
458 ok(val == NULL, "Expected NULL, got %p\n", val);
461 static void test_PackDDElParam(void)
463 UINT_PTR lo, hi, *ptr;
468 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
469 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
470 ok(GlobalLock((HGLOBAL)lparam) == NULL,
471 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
472 ok(GetLastError() == ERROR_INVALID_HANDLE,
473 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
476 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
477 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
478 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
479 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
481 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
482 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
484 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
485 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
486 ok(GlobalLock((HGLOBAL)lparam) == NULL,
487 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
488 ok(GetLastError() == ERROR_INVALID_HANDLE,
489 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
492 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
493 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
494 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
495 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
497 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
498 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
500 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
501 ptr = GlobalLock((HGLOBAL)lparam);
502 ok(ptr != NULL, "Expected non-NULL ptr\n");
503 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
504 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
506 ret = GlobalUnlock((HGLOBAL)lparam);
509 ok(ret == 1, "Expected 1, got %d\n", ret);
513 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
514 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
515 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
516 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
518 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
519 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
521 hglobal = GlobalFree((HGLOBAL)lparam);
524 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
525 ok(GetLastError() == ERROR_INVALID_HANDLE,
526 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
529 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
530 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
531 ok(GlobalLock((HGLOBAL)lparam) == NULL,
532 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
533 ok(GetLastError() == ERROR_INVALID_HANDLE,
534 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
537 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
538 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
539 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
540 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
542 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
543 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
545 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
546 ptr = GlobalLock((HGLOBAL)lparam);
547 ok(ptr != NULL, "Expected non-NULL ptr\n");
548 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
549 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
551 ret = GlobalUnlock((HGLOBAL)lparam);
554 ok(ret == 1, "Expected 1, got %d\n", ret);
558 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
559 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
560 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
561 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
563 ret = FreeDDElParam(WM_DDE_ACK, lparam);
564 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
566 hglobal = GlobalFree((HGLOBAL)lparam);
569 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
570 ok(GetLastError() == ERROR_INVALID_HANDLE,
571 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
574 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
575 ptr = GlobalLock((HGLOBAL)lparam);
576 ok(ptr != NULL, "Expected non-NULL ptr\n");
577 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
578 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
580 ret = GlobalUnlock((HGLOBAL)lparam);
583 ok(ret == 1, "Expected 1, got %d\n", ret);
587 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
588 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
589 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
590 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
592 ret = FreeDDElParam(WM_DDE_DATA, lparam);
593 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
595 hglobal = GlobalFree((HGLOBAL)lparam);
598 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
599 ok(GetLastError() == ERROR_INVALID_HANDLE,
600 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
603 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
604 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
605 ok(GlobalLock((HGLOBAL)lparam) == NULL,
606 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
607 ok(GetLastError() == ERROR_INVALID_HANDLE,
608 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
611 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
612 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
613 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
614 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
616 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
617 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
619 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
620 ptr = GlobalLock((HGLOBAL)lparam);
621 ok(ptr != NULL, "Expected non-NULL ptr\n");
622 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
623 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
625 ret = GlobalUnlock((HGLOBAL)lparam);
628 ok(ret == 1, "Expected 1, got %d\n", ret);
632 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
633 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
634 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
635 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
637 ret = FreeDDElParam(WM_DDE_POKE, lparam);
638 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
640 hglobal = GlobalFree((HGLOBAL)lparam);
643 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
644 ok(GetLastError() == ERROR_INVALID_HANDLE,
645 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
648 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
649 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
650 ok(GlobalLock((HGLOBAL)lparam) == NULL,
651 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
652 ok(GetLastError() == ERROR_INVALID_HANDLE,
653 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
656 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
657 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
658 ok(lo == 0, "Expected 0, got %08lx\n", lo);
659 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
661 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
662 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
665 static void test_UnpackDDElParam(void)
667 UINT_PTR lo, hi, *ptr;
674 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
675 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
676 ok(lo == 0, "Expected 0, got %08lx\n", lo);
677 ok(hi == 0, "Expected 0, got %08lx\n", hi);
682 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
683 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
684 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
685 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
690 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
691 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
692 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
693 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
697 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
698 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
699 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
700 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
704 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
705 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
706 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
707 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
711 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
712 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
715 ok(lo == 0, "Expected 0, got %08lx\n", lo);
716 ok(hi == 0, "Expected 0, got %08lx\n", hi);
721 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
722 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
725 ok(lo == 0, "Expected 0, got %08lx\n", lo);
726 ok(hi == 0, "Expected 0, got %08lx\n", hi);
729 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
730 ptr = GlobalLock(hglobal);
733 GlobalUnlock(hglobal);
737 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
738 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
739 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
740 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
744 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
745 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
746 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
747 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
751 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
752 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
755 ok(lo == 0, "Expected 0, got %08lx\n", lo);
756 ok(hi == 0, "Expected 0, got %08lx\n", hi);
761 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
762 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
763 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
764 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
768 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
769 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
772 ok(lo == 0, "Expected 0, got %08lx\n", lo);
773 ok(hi == 0, "Expected 0, got %08lx\n", hi);
778 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
779 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
780 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
781 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
785 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
786 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
787 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
788 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
792 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
793 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
796 ok(lo == 0, "Expected 0, got %08lx\n", lo);
797 ok(hi == 0, "Expected 0, got %08lx\n", hi);
802 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
803 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
804 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
805 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
809 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
810 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
811 ok(lo == 0, "Expected 0, got %08lx\n", lo);
812 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
817 test_dde_transaction();
818 test_DdeCreateStringHandle();
819 test_FreeDDElParam();
820 test_PackDDElParam();
821 test_UnpackDDElParam();