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);
402 ok(val == hglobal, "Expected hglobal, got %p\n", val);
403 ok(GetLastError() == ERROR_INVALID_HANDLE,
404 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
406 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
407 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
408 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
409 val = GlobalFree(hglobal);
410 ok(val == NULL, "Expected NULL, got %p\n", val);
412 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
413 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
414 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
415 val = GlobalFree(hglobal);
416 ok(val == hglobal, "Expected hglobal, got %p\n", val);
417 ok(GetLastError() == ERROR_INVALID_HANDLE,
418 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
420 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
421 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
422 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
423 val = GlobalFree(hglobal);
424 ok(val == hglobal, "Expected hglobal, got %p\n", val);
425 ok(GetLastError() == ERROR_INVALID_HANDLE,
426 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
428 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
429 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
430 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
431 val = GlobalFree(hglobal);
432 ok(val == NULL, "Expected NULL, got %p\n", val);
434 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
435 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
436 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
437 val = GlobalFree(hglobal);
438 ok(val == hglobal, "Expected hglobal, got %p\n", val);
439 ok(GetLastError() == ERROR_INVALID_HANDLE,
440 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
442 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
443 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
444 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
445 val = GlobalFree(hglobal);
446 ok(val == NULL, "Expected NULL, got %p\n", val);
449 static void test_PackDDElParam(void)
451 UINT_PTR lo, hi, *ptr;
456 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
457 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
458 ok(GlobalLock((HGLOBAL)lparam) == NULL,
459 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
460 ok(GetLastError() == ERROR_INVALID_HANDLE,
461 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
464 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
465 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
466 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
467 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
469 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
470 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
472 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
473 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
474 ok(GlobalLock((HGLOBAL)lparam) == NULL,
475 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
476 ok(GetLastError() == ERROR_INVALID_HANDLE,
477 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
480 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
481 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
482 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
483 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
485 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
486 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
488 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
489 ptr = GlobalLock((HGLOBAL)lparam);
490 ok(ptr != NULL, "Expected non-NULL ptr\n");
491 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
492 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
494 ret = GlobalUnlock((HGLOBAL)lparam);
497 ok(ret == 1, "Expected 1, got %d\n", ret);
501 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
502 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
503 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
504 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
506 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
507 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
509 hglobal = GlobalFree((HGLOBAL)lparam);
510 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
511 ok(GetLastError() == ERROR_INVALID_HANDLE,
512 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
514 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
515 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
516 ok(GlobalLock((HGLOBAL)lparam) == NULL,
517 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
518 ok(GetLastError() == ERROR_INVALID_HANDLE,
519 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
522 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
523 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
524 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
525 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
527 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
528 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
530 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
531 ptr = GlobalLock((HGLOBAL)lparam);
532 ok(ptr != NULL, "Expected non-NULL ptr\n");
533 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
534 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
536 ret = GlobalUnlock((HGLOBAL)lparam);
539 ok(ret == 1, "Expected 1, got %d\n", ret);
543 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
544 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
545 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
546 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
548 ret = FreeDDElParam(WM_DDE_ACK, lparam);
549 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
551 hglobal = GlobalFree((HGLOBAL)lparam);
552 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
553 ok(GetLastError() == ERROR_INVALID_HANDLE,
554 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
556 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
557 ptr = GlobalLock((HGLOBAL)lparam);
558 ok(ptr != NULL, "Expected non-NULL ptr\n");
559 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
560 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
562 ret = GlobalUnlock((HGLOBAL)lparam);
565 ok(ret == 1, "Expected 1, got %d\n", ret);
569 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
570 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
571 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
572 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
574 ret = FreeDDElParam(WM_DDE_DATA, lparam);
575 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
577 hglobal = GlobalFree((HGLOBAL)lparam);
578 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
579 ok(GetLastError() == ERROR_INVALID_HANDLE,
580 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
582 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
583 ok(lparam == 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
584 ok(GlobalLock((HGLOBAL)lparam) == NULL,
585 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
586 ok(GetLastError() == ERROR_INVALID_HANDLE,
587 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
590 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
591 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
592 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
593 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
595 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
596 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
598 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
599 ptr = GlobalLock((HGLOBAL)lparam);
600 ok(ptr != NULL, "Expected non-NULL ptr\n");
601 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
602 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
604 ret = GlobalUnlock((HGLOBAL)lparam);
607 ok(ret == 1, "Expected 1, got %d\n", ret);
611 ret = UnpackDDElParam(WM_DDE_POKE, 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_POKE, lparam);
617 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
619 hglobal = GlobalFree((HGLOBAL)lparam);
620 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
621 ok(GetLastError() == ERROR_INVALID_HANDLE,
622 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
624 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
625 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
626 ok(GlobalLock((HGLOBAL)lparam) == NULL,
627 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
628 ok(GetLastError() == ERROR_INVALID_HANDLE,
629 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
632 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
633 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
634 ok(lo == 0, "Expected 0, got %08lx\n", lo);
635 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
637 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
638 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
641 static void test_UnpackDDElParam(void)
643 UINT_PTR lo, hi, *ptr;
650 ret = UnpackDDElParam(WM_DDE_INITIATE, (LPARAM)NULL, &lo, &hi);
651 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
652 ok(lo == 0, "Expected 0, got %08lx\n", lo);
653 ok(hi == 0, "Expected 0, got %08lx\n", hi);
658 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
659 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
660 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
661 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
666 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
667 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
668 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
669 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
673 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
674 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
675 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
676 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
680 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
681 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
682 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
683 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
687 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)NULL, &lo, &hi);
688 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
689 ok(lo == 0, "Expected 0, got %08lx\n", lo);
690 ok(hi == 0, "Expected 0, got %08lx\n", hi);
694 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
695 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
696 ok(lo == 0, "Expected 0, got %08lx\n", lo);
697 ok(hi == 0, "Expected 0, got %08lx\n", hi);
699 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
700 ptr = GlobalLock(hglobal);
703 GlobalUnlock(hglobal);
707 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
708 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
709 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
710 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
714 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
715 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
716 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
717 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
721 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
722 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
723 ok(lo == 0, "Expected 0, got %08lx\n", lo);
724 ok(hi == 0, "Expected 0, got %08lx\n", hi);
728 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
729 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
730 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
731 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
735 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
736 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
737 ok(lo == 0, "Expected 0, got %08lx\n", lo);
738 ok(hi == 0, "Expected 0, got %08lx\n", hi);
742 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
743 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
744 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
745 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
749 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
750 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
751 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
752 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
756 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
757 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
758 ok(lo == 0, "Expected 0, got %08lx\n", lo);
759 ok(hi == 0, "Expected 0, got %08lx\n", hi);
763 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
764 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
765 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
766 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
770 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
771 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
772 ok(lo == 0, "Expected 0, got %08lx\n", lo);
773 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
778 test_dde_transaction();
779 test_DdeCreateStringHandle();
780 test_FreeDDElParam();
781 test_PackDDElParam();
782 test_UnpackDDElParam();