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
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
)
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
);
58 static LRESULT WINAPI
dde_server_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
61 char str
[MAX_PATH
], *ptr
;
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
);
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
);
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
);
104 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
106 ok(!lstrcmpA(str
, "executed"), "Expected executed, got %s\n", str
);
111 lstrcpyA(str
, "command executed\r\n");
113 lstrcpyA(str
, "command not executed\r\n");
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
;
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
);
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
);
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
);
166 ok(lstrcmpA((LPSTR
)poke
->Value
, "poke data\r\n"),
167 "Expected 'poke data\\r\\n', got %s\n", poke
->Value
);
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
);
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
);
191 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, DDE_FACK
, HIWORD(lparam
));
192 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
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);
209 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
212 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
215 static void test_msg_server(HANDLE hproc
)
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
);
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
);
238 static LRESULT WINAPI
hook_dde_client_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
242 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd
, msg
, wparam
, lparam
);
247 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
248 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo
, (HGLOBAL
)hi
);
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
);
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));
277 GlobalDeleteAtom(aService
);
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;
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.
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
);
322 case WM_DDE_TERMINATE
:
327 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND
)wparam
, lparam
);
329 ack
.bAppReturnCode
= 0;
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
);
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
)
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
,
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
,
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");
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" };
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
);
416 static void test_dde_aw_transaction(void)
419 DWORD dde_inst
, ret
, err
;
421 HWND hwnd_client
, hwnd_server
;
424 static char test_cmd
[] = "test dde command";
426 /* server: unicode, client: ansi */
427 if (!create_dde_windows(&hwnd_client
, &hwnd_server
)) return;
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
);
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");
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");
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");
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
);
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)
506 HSZ server
, topic
, item
;
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 */
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 */
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");
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 */
558 DdeGetLastError(client_pid
);
559 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, 500, &res
);
560 ret
= DdeGetLastError(client_pid
);
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
);
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 */
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
);
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 */
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
);
608 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
611 /* XTYP_POKE, no data */
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
);
620 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
623 /* XTYP_POKE, wrong size */
625 DdeGetLastError(client_pid
);
626 op
= DdeClientTransaction((LPBYTE
)hdata
, 0, conversation
, item
, CF_TEXT
, XTYP_POKE
, 500, &res
);
627 ret
= DdeGetLastError(client_pid
);
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 */
637 DdeGetLastError(client_pid
);
638 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, item
, CF_TEXT
, XTYP_POKE
, 500, &res
);
639 ret
= DdeGetLastError(client_pid
);
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 */
656 DdeGetLastError(client_pid
);
657 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, 5000, &res
);
658 ret
= DdeGetLastError(client_pid
);
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 */
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
);
675 ok(ret
== DMLERR_MEMORY_ERROR
, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
678 /* XTYP_EXECUTE, no data, -1 size */
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
);
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 */
697 DdeGetLastError(client_pid
);
698 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, 500, &res
);
699 ret
= DdeGetLastError(client_pid
);
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
);
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 */
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
);
727 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
738 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
749 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
760 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
771 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
782 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
793 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
804 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
815 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
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
);
826 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
829 DdeFreeStringHandle(client_pid
, item
);
831 ret
= DdeDisconnect(conversation
);
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};
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
);
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");
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");
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
);
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());
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)
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");
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");
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
;
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
;
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());
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());
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
);
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());
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
);
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
);
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());
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
);
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());
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
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
1334 char buffer
[MAX_PATH
];
1335 STARTUPINFO startup
;
1336 PROCESS_INFORMATION proc
;
1338 argc
= winetest_get_mainargs(&argv
);
1341 if (!lstrcmpA(argv
[2], "ddeml"))
1342 test_ddeml_client();
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();