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 const DWORD default_timeout
= 200;
44 static void flush_events(void)
47 int diff
= default_timeout
;
49 DWORD time
= GetTickCount() + diff
;
53 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
54 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
55 diff
= time
- GetTickCount();
60 static void create_dde_window(HWND
*hwnd
, LPCSTR name
, WNDPROC wndproc
)
64 memset(&wcA
, 0, sizeof(wcA
));
65 wcA
.lpfnWndProc
= wndproc
;
66 wcA
.lpszClassName
= name
;
67 wcA
.hInstance
= GetModuleHandleA(0);
68 assert(RegisterClassA(&wcA
));
70 *hwnd
= CreateWindowExA(0, name
, NULL
, WS_POPUP
,
71 500, 500, CW_USEDEFAULT
, CW_USEDEFAULT
,
72 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
76 static void destroy_dde_window(HWND
*hwnd
, LPCSTR name
)
79 UnregisterClass(name
, GetModuleHandleA(0));
82 static LRESULT WINAPI
dde_server_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
85 char str
[MAX_PATH
], *ptr
;
91 static int msg_index
= 0;
92 static HWND client
= 0;
93 static BOOL executed
= FALSE
;
95 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
96 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
102 case WM_DDE_INITIATE
:
104 client
= (HWND
)wparam
;
105 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
107 GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
108 ok(!lstrcmpA(str
, "TestDDEService"), "Expected TestDDEService, got %s\n", str
);
110 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
111 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
113 SendMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
120 ok((msg_index
>= 2 && msg_index
<= 4) ||
121 (msg_index
>= 7 && msg_index
<= 8),
122 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index
);
123 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
124 ok(LOWORD(lparam
) == CF_TEXT
, "Expected CF_TEXT, got %d\n", LOWORD(lparam
));
126 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
128 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
130 ok(!lstrcmpA(str
, "executed"), "Expected executed, got %s\n", str
);
135 lstrcpyA(str
, "command executed\r\n");
137 lstrcpyA(str
, "command not executed\r\n");
140 lstrcpyA(str
, "requested data\r\n");
142 size
= sizeof(DDEDATA
) + lstrlenA(str
) + 1;
143 hglobal
= GlobalAlloc(GMEM_MOVEABLE
, size
);
144 ok(hglobal
!= NULL
, "Expected non-NULL hglobal\n");
146 data
= GlobalLock(hglobal
);
147 ZeroMemory(data
, size
);
149 /* setting fResponse to FALSE at this point destroys
150 * the internal messaging state of native dde
152 data
->fResponse
= TRUE
;
155 data
->fRelease
= TRUE
;
156 else if (msg_index
== 3)
157 data
->fAckReq
= TRUE
;
159 data
->cfFormat
= CF_TEXT
;
160 lstrcpyA((LPSTR
)data
->Value
, str
);
161 GlobalUnlock(hglobal
);
163 lparam
= PackDDElParam(WM_DDE_ACK
, (UINT
)hglobal
, HIWORD(lparam
));
164 PostMessageA(client
, WM_DDE_DATA
, (WPARAM
)hwnd
, lparam
);
171 ok(msg_index
== 5 || msg_index
== 6, "Expected 5 or 6, got %d\n", msg_index
);
172 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
174 UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
176 GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
177 ok(!lstrcmpA(str
, "poker"), "Expected poker, got %s\n", str
);
179 poke
= GlobalLock((HGLOBAL
)lo
);
180 ok(poke
!= NULL
, "Expected non-NULL poke\n");
181 ok(poke
->fReserved
== 0, "Expected 0, got %d\n", poke
->fReserved
);
182 ok(poke
->unused
== 0, "Expected 0, got %d\n", poke
->unused
);
183 ok(poke
->fRelease
== TRUE
, "Expected TRUE, got %d\n", poke
->fRelease
);
184 ok(poke
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", poke
->cfFormat
);
188 size
= GlobalSize((HGLOBAL
)lo
);
189 ok(size
== 4, "got %d\n", size
);
192 ok(!lstrcmpA((LPSTR
)poke
->Value
, "poke data\r\n"),
193 "Expected 'poke data\\r\\n', got %s\n", poke
->Value
);
195 GlobalUnlock((HGLOBAL
)lo
);
197 lparam
= PackDDElParam(WM_DDE_ACK
, DDE_FACK
, hi
);
198 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
205 ok(msg_index
== 7, "Expected 7, got %d\n", msg_index
);
206 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
208 ptr
= GlobalLock((HGLOBAL
)lparam
);
209 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr
);
210 GlobalUnlock((HGLOBAL
)lparam
);
214 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, DDE_FACK
, HIWORD(lparam
));
215 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
220 case WM_DDE_TERMINATE
:
222 ok(msg_index
== 9, "Expected 9, got %d\n", msg_index
);
223 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
224 ok(lparam
== 0, "Expected 0, got %08lx\n", lparam
);
226 PostMessageA(client
, WM_DDE_TERMINATE
, (WPARAM
)hwnd
, 0);
232 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
235 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
238 static void test_msg_server(HANDLE hproc
, HANDLE hthread
)
244 create_dde_window(&hwnd
, "dde_server", dde_server_wndproc
);
245 ResumeThread( hthread
);
247 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
249 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
252 destroy_dde_window(&hwnd
, "dde_server");
253 GetExitCodeProcess( hproc
, &res
);
254 ok( !res
, "client failed with %u error(s)\n", res
);
257 static HDDEDATA CALLBACK
client_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
258 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
259 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
261 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
265 static void test_ddeml_client(void)
272 HSZ server
, topic
, item
;
277 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
278 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
280 /* FIXME: make these atoms global and check them in the server */
282 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
283 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
285 DdeGetLastError(client_pid
);
286 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
287 ok(conversation
!= NULL
, "Expected non-NULL conversation\n");
288 ret
= DdeGetLastError(client_pid
);
289 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
291 DdeFreeStringHandle(client_pid
, server
);
293 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
295 /* XTYP_REQUEST, fRelease = TRUE */
297 DdeGetLastError(client_pid
);
298 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
299 ret
= DdeGetLastError(client_pid
);
300 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
301 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %08x\n", res
);
303 ok(FALSE
, "hdata is NULL\n");
306 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
307 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
308 ok(size
== 19, "Expected 19, got %d\n", size
);
310 ret
= DdeUnaccessData(hdata
);
311 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
314 /* XTYP_REQUEST, fAckReq = TRUE */
316 DdeGetLastError(client_pid
);
317 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
318 ret
= DdeGetLastError(client_pid
);
319 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %d\n", res
);
321 ok(ret
== DMLERR_MEMORY_ERROR
, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
323 ok(FALSE
, "hdata is NULL\n");
326 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
327 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
328 ok(size
== 19, "Expected 19, got %d\n", size
);
330 ret
= DdeUnaccessData(hdata
);
331 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
334 /* XTYP_REQUEST, all params normal */
336 DdeGetLastError(client_pid
);
337 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
338 ret
= DdeGetLastError(client_pid
);
339 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
340 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %d\n", res
);
342 ok(FALSE
, "hdata is NULL\n");
345 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
346 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
347 ok(size
== 19, "Expected 19, got %d\n", size
);
349 ret
= DdeUnaccessData(hdata
);
350 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
353 /* XTYP_REQUEST, no item */
355 DdeGetLastError(client_pid
);
356 hdata
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
357 ret
= DdeGetLastError(client_pid
);
358 ok(hdata
== NULL
, "Expected NULL hdata, got %p\n", hdata
);
359 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res
);
360 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
362 DdeFreeStringHandle(client_pid
, item
);
364 item
= DdeCreateStringHandleA(client_pid
, "poker", CP_WINANSI
);
366 lstrcpyA(buffer
, "poke data\r\n");
367 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
368 0, item
, CF_TEXT
, 0);
369 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
371 /* XTYP_POKE, no item */
373 DdeGetLastError(client_pid
);
374 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
375 ret
= DdeGetLastError(client_pid
);
376 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
377 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
378 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
380 /* XTYP_POKE, no data */
382 DdeGetLastError(client_pid
);
383 op
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
384 ret
= DdeGetLastError(client_pid
);
385 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
386 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
387 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
389 /* XTYP_POKE, wrong size */
391 DdeGetLastError(client_pid
);
392 op
= DdeClientTransaction((LPBYTE
)hdata
, 0, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
393 ret
= DdeGetLastError(client_pid
);
394 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
395 ok(res
== DDE_FACK
, "Expected DDE_FACK, got %d\n", res
);
396 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
398 /* XTYP_POKE, correct params */
400 DdeGetLastError(client_pid
);
401 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
402 ret
= DdeGetLastError(client_pid
);
403 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
404 ok(res
== DDE_FACK
, "Expected DDE_FACK, got %d\n", res
);
405 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
407 DdeFreeDataHandle(hdata
);
409 lstrcpyA(buffer
, "[Command(Var)]");
410 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
411 0, NULL
, CF_TEXT
, 0);
412 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
414 /* XTYP_EXECUTE, correct params */
416 DdeGetLastError(client_pid
);
417 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
418 ret
= DdeGetLastError(client_pid
);
419 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
420 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
421 ok(res
== DDE_FACK
, "Expected DDE_FACK, got %d\n", res
);
423 /* XTYP_EXECUTE, no data */
425 DdeGetLastError(client_pid
);
426 op
= DdeClientTransaction(NULL
, 0, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
427 ret
= DdeGetLastError(client_pid
);
428 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
429 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
432 ok(ret
== DMLERR_MEMORY_ERROR
, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
435 /* XTYP_EXECUTE, no data, -1 size */
437 DdeGetLastError(client_pid
);
438 op
= DdeClientTransaction(NULL
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
439 ret
= DdeGetLastError(client_pid
);
440 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
441 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
442 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
444 DdeFreeStringHandle(client_pid
, topic
);
445 DdeFreeDataHandle(hdata
);
447 item
= DdeCreateStringHandleA(client_pid
, "executed", CP_WINANSI
);
449 /* verify the execute */
451 DdeGetLastError(client_pid
);
452 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
453 ret
= DdeGetLastError(client_pid
);
454 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
455 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %d\n", res
);
457 ok(FALSE
, "hdata is NULL\n");
460 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
461 ok(!lstrcmpA(str
, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str
);
462 ok(size
== 21, "Expected 21, got %d\n", size
);
464 ret
= DdeUnaccessData(hdata
);
465 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
468 /* invalid transactions */
470 DdeGetLastError(client_pid
);
471 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_ADVREQ
, default_timeout
, &res
);
472 ret
= DdeGetLastError(client_pid
);
473 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
474 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
475 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
478 DdeGetLastError(client_pid
);
479 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_CONNECT
, default_timeout
, &res
);
480 ret
= DdeGetLastError(client_pid
);
481 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
482 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
483 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
486 DdeGetLastError(client_pid
);
487 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_CONNECT_CONFIRM
, default_timeout
, &res
);
488 ret
= DdeGetLastError(client_pid
);
489 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
490 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
491 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
494 DdeGetLastError(client_pid
);
495 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_DISCONNECT
, default_timeout
, &res
);
496 ret
= DdeGetLastError(client_pid
);
497 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
498 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
499 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
502 DdeGetLastError(client_pid
);
503 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_ERROR
, default_timeout
, &res
);
504 ret
= DdeGetLastError(client_pid
);
505 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
506 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
507 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
510 DdeGetLastError(client_pid
);
511 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_MONITOR
, default_timeout
, &res
);
512 ret
= DdeGetLastError(client_pid
);
513 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
514 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
515 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
518 DdeGetLastError(client_pid
);
519 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REGISTER
, default_timeout
, &res
);
520 ret
= DdeGetLastError(client_pid
);
521 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
522 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
523 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
526 DdeGetLastError(client_pid
);
527 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_UNREGISTER
, default_timeout
, &res
);
528 ret
= DdeGetLastError(client_pid
);
529 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
530 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
531 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
534 DdeGetLastError(client_pid
);
535 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_WILDCONNECT
, default_timeout
, &res
);
536 ret
= DdeGetLastError(client_pid
);
537 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
538 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
539 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
542 DdeGetLastError(client_pid
);
543 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_XACT_COMPLETE
, default_timeout
, &res
);
544 ret
= DdeGetLastError(client_pid
);
545 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
546 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
547 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
549 DdeFreeStringHandle(client_pid
, item
);
551 ret
= DdeDisconnect(conversation
);
552 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
554 ret
= DdeUninitialize(client_pid
);
555 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
558 static DWORD server_pid
;
560 static HDDEDATA CALLBACK
server_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
561 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
562 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
564 char str
[MAX_PATH
], *ptr
;
568 static int msg_index
= 0;
569 static HCONV conversation
= 0;
577 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
578 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
579 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
580 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
581 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
582 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
584 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
585 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
586 ok(size
== 13, "Expected 13, got %d\n", size
);
588 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
589 ok(!strncmp(str
, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str
);
590 ok(str
[size
- 1] == ')', "Expected ')', got %c\n", str
[size
- 1]);
591 ok(size
== 25, "Expected 25, got %d\n", size
);
593 return (HDDEDATA
)TRUE
;
598 ok(msg_index
== 2, "Expected 2, got %d\n", msg_index
);
599 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
600 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
601 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
602 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
603 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx\n", dwData2
);
605 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
606 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
607 ok(size
== 12, "Expected 12, got %d\n", size
);
609 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
610 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
611 ok(size
== 13, "Expected 13, got %d\n", size
);
613 return (HDDEDATA
)TRUE
;
616 case XTYP_CONNECT_CONFIRM
:
618 conversation
= hconv
;
620 ok(msg_index
== 3, "Expected 3, got %d\n", msg_index
);
621 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
622 ok(hconv
!= NULL
, "Expected non-NULL hconv\n");
623 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
624 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
625 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx\n", dwData2
);
627 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
628 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
629 ok(size
== 12, "Expected 12, got %d\n", size
);
631 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
632 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
633 ok(size
== 13, "Expected 13, got %d\n", size
);
635 return (HDDEDATA
)TRUE
;
640 ok(msg_index
== 4 || msg_index
== 5 || msg_index
== 6,
641 "Expected 4, 5 or 6, got %d\n", msg_index
);
642 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
643 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
644 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
645 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
648 ok(uFmt
== 0xbeef, "Expected 0xbeef, got %08x\n", uFmt
);
650 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %08x\n", uFmt
);
652 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
653 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
654 ok(size
== 12, "Expected 12, got %d\n", size
);
656 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
661 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
662 ok(size
== 1, "Expected 1, got %d\n", size
);
665 else if (msg_index
== 6)
667 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
668 ok(size
== 7, "Expected 7, got %d\n", size
);
673 lstrcpyA(str
, "requested data\r\n");
674 return DdeCreateDataHandle(server_pid
, (LPBYTE
)str
, lstrlenA(str
) + 1,
675 0, hsz2
, CF_TEXT
, 0);
683 ok(msg_index
== 7 || msg_index
== 8, "Expected 7 or 8, got %d\n", msg_index
);
684 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %d\n", uFmt
);
685 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
686 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
687 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
689 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
690 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
691 ok(size
== 12, "Expected 12, got %d\n", size
);
693 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
694 ok(!lstrcmpA(ptr
, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr
);
695 ok(size
== 12, "Expected 12, got %d\n", size
);
696 DdeUnaccessData(hdata
);
698 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
702 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
703 ok(size
== 1, "Expected 1, got %d\n", size
);
708 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
709 ok(size
== 4, "Expected 4, got %d\n", size
);
712 return (HDDEDATA
)DDE_FACK
;
717 ok(msg_index
== 9 || msg_index
== 10, "Expected 9 or 10, got %d\n", msg_index
);
718 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
719 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
720 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
721 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
722 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
724 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
725 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
726 ok(size
== 12, "Expected 12, got %d\n", size
);
728 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
732 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
733 ok(size
== 15, "Expected 15, got %d\n", size
);
734 ret
= (HDDEDATA
)DDE_FACK
;
738 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
739 ok(size
== 18, "Expected 18, got %d\n", size
);
740 ret
= (HDDEDATA
)DDE_FNOTPROCESSED
;
743 DdeUnaccessData(hdata
);
748 case XTYP_DISCONNECT
:
750 ok(msg_index
== 11, "Expected 11, got %d\n", msg_index
);
751 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
752 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
753 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
754 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
755 ok(hsz1
== 0, "Expected 0, got %p\n", hsz2
);
756 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
762 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
768 static void test_ddeml_server(HANDLE hproc
)
776 /* set up DDE server */
778 res
= DdeInitialize(&server_pid
, server_ddeml_callback
, APPCLASS_STANDARD
, 0);
779 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
781 server
= DdeCreateStringHandle(server_pid
, "TestDDEServer", CP_WINANSI
);
782 ok(server
!= NULL
, "Expected non-NULL string handle\n");
784 hdata
= DdeNameService(server_pid
, server
, 0, DNS_REGISTER
);
785 ok(hdata
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", hdata
);
787 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
789 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
791 ret
= DdeUninitialize(server_pid
);
792 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
793 GetExitCodeProcess( hproc
, &res
);
794 ok( !res
, "client failed with %u error(s)\n", res
);
797 static HWND client_hwnd
, server_hwnd
;
798 static ATOM server
, topic
, item
;
799 static HGLOBAL execute_hglobal
;
801 static LRESULT WINAPI
dde_msg_client_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
810 static int msg_index
= 0;
812 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
813 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
819 case WM_DDE_INITIATE
:
821 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
822 ok(wparam
== (WPARAM
)client_hwnd
, "Expected client hwnd, got %08lx\n", wparam
);
824 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
825 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
826 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
827 ok(size
== 13, "Expected 13, got %d\n", size
);
829 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
830 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
831 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
832 ok(size
== 12, "Expected 12, got %d\n", size
);
839 ok((msg_index
>= 2 && msg_index
<= 4) || (msg_index
>= 6 && msg_index
<= 10),
840 "Expected 2, 3, 4, 6, 7, 8, 9 or 10, got %d\n", msg_index
);
844 server_hwnd
= (HWND
)wparam
;
845 ok(wparam
!= 0, "Expected non-NULL wparam, got %08lx\n", wparam
);
847 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
848 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
849 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
850 ok(size
== 13, "Expected 13, got %d\n", size
);
852 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
853 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
854 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
855 ok(size
== 12, "Expected 12, got %d\n", size
);
857 else if (msg_index
== 9 || msg_index
== 10)
859 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
861 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
864 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
865 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
866 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
868 ok(hi
== (UINT_PTR
)execute_hglobal
, "Execpted execute hglobal, got %08lx\n", hi
);
869 ptr
= GlobalLock((HGLOBAL
)hi
);
873 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
874 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
878 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
879 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
882 GlobalUnlock((HGLOBAL
)hi
);
886 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
888 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
891 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
892 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
893 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
896 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
899 if (msg_index
== 6) todo_wine
900 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
903 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
906 ok(hi
== item
, "Expected item atom, got %08lx\n", hi
);
907 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
908 ok(size
== 7, "Expected 7, got %d\n", size
);
910 else if (msg_index
== 4 || msg_index
== 7)
912 ok(hi
== 0, "Expected 0, got %08lx\n", hi
);
913 ok(size
== 0, "Expected empty string, got %d\n", size
);
917 ok(hi
== item
, "Expected item atom, got %08lx\n", hi
);
918 if (msg_index
== 6) todo_wine
920 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
921 ok(size
== 4, "Expected 4, got %d\n", size
);
931 ok(msg_index
== 5, "Expected 5, got %d\n", msg_index
);
932 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
934 UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
936 data
= GlobalLock((HGLOBAL
)lo
);
937 ok(data
->unused
== 0, "Expected 0, got %d\n", data
->unused
);
938 ok(data
->fResponse
== TRUE
, "Expected TRUE, got %d\n", data
->fResponse
);
941 ok(data
->fRelease
== TRUE
, "Expected TRUE, got %d\n", data
->fRelease
);
943 ok(data
->fAckReq
== 0, "Expected 0, got %d\n", data
->fAckReq
);
944 ok(data
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", data
->cfFormat
);
945 ok(!lstrcmpA((LPSTR
)data
->Value
, "requested data\r\n"),
946 "Expeted 'requested data\\r\\n', got %s\n", data
->Value
);
947 GlobalUnlock((HGLOBAL
)lo
);
949 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
950 ok(hi
== item
, "Expected item atom, got %08x\n", HIWORD(lparam
));
951 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
952 ok(size
== 7, "Expected 7, got %d\n", size
);
954 GlobalFree((HGLOBAL
)lo
);
955 GlobalDeleteAtom(hi
);
961 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
964 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
967 static HGLOBAL
create_poke()
973 size
= FIELD_OFFSET(DDEPOKE
, Value
[sizeof("poke data\r\n")]);
974 hglobal
= GlobalAlloc(GMEM_DDESHARE
, size
);
975 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
977 poke
= GlobalLock(hglobal
);
979 poke
->fRelease
= TRUE
;
980 poke
->fReserved
= TRUE
;
981 poke
->cfFormat
= CF_TEXT
;
982 lstrcpyA((LPSTR
)poke
->Value
, "poke data\r\n");
983 GlobalUnlock(hglobal
);
988 static HGLOBAL
create_execute(LPCSTR command
)
993 hglobal
= GlobalAlloc(GMEM_DDESHARE
, lstrlenA(command
) + 1);
994 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
996 ptr
= GlobalLock(hglobal
);
997 lstrcpyA(ptr
, command
);
998 GlobalUnlock(hglobal
);
1003 static void test_msg_client()
1008 create_dde_window(&client_hwnd
, "dde_client", dde_msg_client_wndproc
);
1010 server
= GlobalAddAtomA("TestDDEServer");
1011 ok(server
!= 0, "Expected non-NULL server\n");
1013 topic
= GlobalAddAtomA("TestDDETopic");
1014 ok(topic
!= 0, "Expected non-NULL topic\n");
1016 SendMessageA(HWND_BROADCAST
, WM_DDE_INITIATE
, (WPARAM
)client_hwnd
, MAKELONG(server
, topic
));
1018 GlobalDeleteAtom(server
);
1019 GlobalDeleteAtom(topic
);
1023 item
= GlobalAddAtom("request");
1024 ok(item
!= 0, "Expected non-NULL item\n");
1026 /* WM_DDE_REQUEST, bad clipboard format */
1027 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xdeadbeef, item
);
1028 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1032 /* WM_DDE_REQUEST, no item */
1033 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, 0);
1034 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1038 /* WM_DDE_REQUEST, no client hwnd */
1039 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1040 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, 0, lparam
);
1044 /* WM_DDE_REQUEST, correct params */
1045 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1046 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1050 GlobalDeleteAtom(item
);
1051 item
= GlobalAddAtomA("poke");
1052 ok(item
!= 0, "Expected non-NULL item\n");
1054 hglobal
= create_poke();
1056 /* WM_DDE_POKE, no ddepoke */
1057 lparam
= PackDDElParam(WM_DDE_POKE
, 0, item
);
1058 /* win9x returns 0 here and crashes in PostMessageA */
1060 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1064 win_skip("no lparam for WM_DDE_POKE\n");
1067 /* WM_DDE_POKE, no item */
1068 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, 0);
1069 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1073 hglobal
= create_poke();
1075 /* WM_DDE_POKE, no client hwnd */
1076 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1077 PostMessageA(server_hwnd
, WM_DDE_POKE
, 0, lparam
);
1081 /* WM_DDE_POKE, all params correct */
1082 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1083 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1087 execute_hglobal
= create_execute("[Command(Var)]");
1089 /* WM_DDE_EXECUTE, no lparam */
1090 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, 0);
1094 /* WM_DDE_EXECUTE, no hglobal */
1095 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, 0);
1096 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1100 /* WM_DDE_EXECUTE, no client hwnd */
1101 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1102 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, 0, lparam
);
1106 /* WM_DDE_EXECUTE, all params correct */
1107 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1108 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1112 GlobalFree(execute_hglobal
);
1113 execute_hglobal
= create_execute("[BadCommand(Var)]");
1115 /* WM_DDE_EXECUTE that will get rejected */
1116 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1117 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1121 destroy_dde_window(&client_hwnd
, "dde_client");
1124 static LRESULT WINAPI
hook_dde_client_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1128 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd
, msg
, wparam
, lparam
);
1133 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1134 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo
, (HGLOBAL
)hi
);
1140 return CallWindowProcA(old_dde_client_wndproc
, hwnd
, msg
, wparam
, lparam
);
1143 static LRESULT WINAPI
dde_server_wndprocW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1145 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd
, msg
, wparam
, lparam
);
1149 case WM_DDE_INITIATE
:
1151 ATOM aService
= GlobalAddAtomW(TEST_DDE_SERVICE
);
1153 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1155 if (LOWORD(lparam
) == aService
)
1157 ok(!IsWindowUnicode((HWND
)wparam
), "client should be an ANSI window\n");
1158 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrA((HWND
)wparam
, GWLP_WNDPROC
, (ULONG_PTR
)hook_dde_client_wndproc
);
1159 trace("server: sending WM_DDE_ACK to %p\n", (HWND
)wparam
);
1160 SendMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, MAKELPARAM(aService
, 0));
1163 GlobalDeleteAtom(aService
);
1167 case WM_DDE_EXECUTE
:
1174 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1176 UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1177 trace("%08lx => lo %04lx hi %04lx\n", lparam
, lo
, hi
);
1179 ack
.bAppReturnCode
= 0;
1183 cmd
= GlobalLock((HGLOBAL
)hi
);
1184 if (!cmd
|| (lstrcmpA(cmd
, exec_cmdA
) && lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
)))
1186 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1187 /* We have to send a negative acknowledge even if we don't
1188 * accept the command, otherwise Windows goes mad and next time
1189 * we send an acknowledge DDEML drops the connection.
1190 * Not sure how to call it: a bug or a feature.
1196 GlobalUnlock((HGLOBAL
)hi
);
1198 trace("server: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1200 status
= *((WORD
*)&ack
);
1201 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, status
, hi
);
1203 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1207 case WM_DDE_TERMINATE
:
1212 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1214 ack
.bAppReturnCode
= 0;
1219 trace("server: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1221 status
= *((WORD
*)&ack
);
1222 lparam
= PackDDElParam(WM_DDE_ACK
, status
, 0);
1224 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1232 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
1235 static LRESULT WINAPI
dde_client_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1237 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1240 static BOOL
create_dde_windows(HWND
*client
, HWND
*server
)
1244 static const WCHAR server_class_name
[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1245 static const char client_class_name
[] = "dde_client_window";
1247 memset(&wcW
, 0, sizeof(wcW
));
1248 wcW
.lpfnWndProc
= dde_server_wndprocW
;
1249 wcW
.lpszClassName
= server_class_name
;
1250 wcW
.hInstance
= GetModuleHandleA(0);
1251 if (!RegisterClassW(&wcW
)) return FALSE
;
1253 memset(&wcA
, 0, sizeof(wcA
));
1254 wcA
.lpfnWndProc
= dde_client_wndproc
;
1255 wcA
.lpszClassName
= client_class_name
;
1256 wcA
.hInstance
= GetModuleHandleA(0);
1257 assert(RegisterClassA(&wcA
));
1259 *server
= CreateWindowExW(0, server_class_name
, NULL
,
1261 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1262 GetDesktopWindow(), 0,
1263 GetModuleHandleA(0), NULL
);
1266 *client
= CreateWindowExA(0, client_class_name
, NULL
,
1268 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1269 GetDesktopWindow(), 0,
1270 GetModuleHandleA(0), NULL
);
1273 trace("server hwnd %p, client hwnd %p\n", *server
, *client
);
1275 ok(IsWindowUnicode(*server
), "server has to be a unicode window\n");
1276 ok(!IsWindowUnicode(*client
), "client has to be an ANSI window\n");
1281 static HDDEDATA CALLBACK
client_dde_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
1282 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
1283 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
1285 static const char * const cmd_type
[15] = {
1286 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1287 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1288 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1289 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1291 const char *cmd_name
;
1293 type
= (uType
& XTYP_MASK
) >> XTYP_SHIFT
;
1294 cmd_name
= (type
<= 14) ? cmd_type
[type
] : "unknown";
1296 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1297 uType
, cmd_name
, uFmt
, hconv
, hsz1
, hsz2
, hdata
, dwData1
, dwData2
);
1301 static void test_dde_aw_transaction(void)
1304 DWORD dde_inst
, ret
, err
;
1306 HWND hwnd_client
, hwnd_server
;
1309 static char test_cmd
[] = "test dde command";
1311 /* server: unicode, client: ansi */
1312 if (!create_dde_windows(&hwnd_client
, &hwnd_server
)) return;
1315 ret
= DdeInitializeA(&dde_inst
, client_dde_callback
, APPCMD_CLIENTONLY
, 0);
1316 ok(ret
== DMLERR_NO_ERROR
, "DdeInitializeA failed with error %04x (%x)\n",
1317 ret
, DdeGetLastError(dde_inst
));
1319 hsz_server
= DdeCreateStringHandleW(dde_inst
, TEST_DDE_SERVICE
, CP_WINUNICODE
);
1321 hconv
= DdeConnect(dde_inst
, hsz_server
, 0, NULL
);
1322 ok(hconv
!= 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst
));
1323 err
= DdeGetLastError(dde_inst
);
1324 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1326 info
.cb
= sizeof(info
);
1327 ret
= DdeQueryConvInfo(hconv
, QID_SYNC
, &info
);
1328 ok(ret
, "wrong info size %d, DdeQueryConvInfo error %x\n", ret
, DdeGetLastError(dde_inst
));
1329 /* should be CP_WINANSI since we used DdeInitializeA */
1330 ok(info
.ConvCtxt
.iCodePage
== CP_WINANSI
, "wrong iCodePage %d\n", info
.ConvCtxt
.iCodePage
);
1331 ok(!info
.hConvPartner
, "unexpected info.hConvPartner: %p\n", info
.hConvPartner
);
1333 ok((info
.wStatus
& DDE_FACK
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1335 ok((info
.wStatus
& (ST_CONNECTED
| ST_CLIENT
)) == (ST_CONNECTED
| ST_CLIENT
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1336 ok(info
.wConvst
== XST_CONNECTED
, "unexpected info.wConvst: %04x\n", info
.wConvst
);
1337 ok(info
.wType
== 0, "unexpected info.wType: %04x\n", info
.wType
);
1339 trace("hwnd %p, hwndPartner %p\n", info
.hwnd
, info
.hwndPartner
);
1341 trace("sending test client transaction command\n");
1343 hdata
= DdeClientTransaction((LPBYTE
)test_cmd
, strlen(test_cmd
) + 1, hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
1344 ok(!hdata
, "DdeClientTransaction succeeded\n");
1345 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1346 err
= DdeGetLastError(dde_inst
);
1347 ok(err
== DMLERR_NOTPROCESSED
, "wrong dde error %x\n", err
);
1349 trace("sending ANSI client transaction command\n");
1351 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdA
, lstrlenA(exec_cmdA
) + 1, hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1352 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, DdeGetLastError(dde_inst
));
1353 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1355 err
= DdeGetLastError(dde_inst
);
1356 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1358 trace("sending unicode client transaction command\n");
1360 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdW
, (lstrlenW(exec_cmdW
) + 1) * sizeof(WCHAR
), hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1361 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, DdeGetLastError(dde_inst
));
1362 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1363 err
= DdeGetLastError(dde_inst
);
1364 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1366 ok(DdeDisconnect(hconv
), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst
));
1368 info
.cb
= sizeof(info
);
1369 ret
= DdeQueryConvInfo(hconv
, QID_SYNC
, &info
);
1370 ok(!ret
, "DdeQueryConvInfo should fail\n");
1371 err
= DdeGetLastError(dde_inst
);
1373 ok(err
== DMLERR_INVALIDPARAMETER
, "wrong dde error %x\n", err
);
1376 ok(DdeFreeStringHandle(dde_inst
, hsz_server
), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst
));
1378 /* This call hangs on win2k SP4 and XP SP1.
1379 DdeUninitialize(dde_inst);*/
1381 DestroyWindow(hwnd_client
);
1382 DestroyWindow(hwnd_server
);
1385 static void test_initialisation(void)
1390 HSZ server
, topic
, item
;
1394 /* Initialise without a valid server window. */
1396 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1397 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
1400 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
1401 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
1403 DdeGetLastError(client_pid
);
1405 /* There is no server window so no conversation can be extracted */
1406 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
1407 ok(conversation
== NULL
, "Expected NULL conversation, %p\n", conversation
);
1408 ret
= DdeGetLastError(client_pid
);
1409 ok(ret
== DMLERR_NO_CONV_ESTABLISHED
, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret
);
1411 DdeFreeStringHandle(client_pid
, server
);
1413 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
1415 /* There is no converstation so an invalild parameter results */
1417 DdeGetLastError(client_pid
);
1418 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
1419 ret
= DdeGetLastError(client_pid
);
1421 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
1422 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res
);
1424 DdeFreeStringHandle(client_pid
, server
);
1425 ret
= DdeDisconnect(conversation
);
1426 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1428 ret
= DdeUninitialize(client_pid
);
1429 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1432 static void test_DdeCreateStringHandleW(DWORD dde_inst
, int codepage
)
1434 static const WCHAR dde_string
[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1441 str_handle
= DdeCreateStringHandleW(dde_inst
, dde_string
, codepage
);
1442 ok(str_handle
!= 0, "DdeCreateStringHandleW failed with error %08x\n",
1443 DdeGetLastError(dde_inst
));
1445 ret
= DdeQueryStringW(dde_inst
, str_handle
, NULL
, 0, codepage
);
1446 if (codepage
== CP_WINANSI
)
1447 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1449 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1451 ret
= DdeQueryStringW(dde_inst
, str_handle
, bufW
, 256, codepage
);
1452 if (codepage
== CP_WINANSI
)
1454 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1455 ok(!lstrcmpA("D", (LPCSTR
)bufW
), "DdeQueryStringW returned wrong string\n");
1459 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1460 ok(!lstrcmpW(dde_string
, bufW
), "DdeQueryStringW returned wrong string\n");
1463 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINANSI
);
1464 if (codepage
== CP_WINANSI
)
1466 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1467 ok(!lstrcmpA("D", buf
), "DdeQueryStringW returned wrong string\n");
1471 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1472 ok(!lstrcmpA("DDE String", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1475 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINUNICODE
);
1476 if (codepage
== CP_WINANSI
)
1478 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1479 ok(!lstrcmpA("D", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1483 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1484 ok(!lstrcmpW(dde_string
, (LPCWSTR
)buf
), "DdeQueryStringW returned wrong string\n");
1487 if (codepage
== CP_WINANSI
)
1489 atom
= FindAtomA((LPSTR
)dde_string
);
1490 ok(atom
!= 0, "Expected a valid atom\n");
1492 SetLastError(0xdeadbeef);
1493 atom
= GlobalFindAtomA((LPSTR
)dde_string
);
1494 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1495 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1496 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1500 atom
= FindAtomW(dde_string
);
1501 ok(atom
!= 0, "Expected a valid atom\n");
1503 SetLastError(0xdeadbeef);
1504 atom
= GlobalFindAtomW(dde_string
);
1505 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1506 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1507 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1510 ok(DdeFreeStringHandle(dde_inst
, str_handle
), "DdeFreeStringHandle failed\n");
1513 static void test_DdeCreateDataHandle(void)
1524 res
= DdeInitializeA(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1525 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1527 item
= DdeCreateStringHandleA(dde_inst
, "item", CP_WINANSI
);
1528 ok(item
!= NULL
, "Expected non-NULL hsz\n");
1531 /* do not test with an invalid instance id: that crashes on win9x */
1532 hdata
= DdeCreateDataHandle(0xdeadbeef, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1536 DdeGetLastError(dde_inst
);
1537 hdata
= DdeCreateDataHandle(0, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1538 err
= DdeGetLastError(dde_inst
);
1541 ok(hdata
== NULL
, "Expected NULL, got %p\n", hdata
);
1542 ok(err
== DMLERR_INVALIDPARAMETER
,
1543 "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1547 DdeGetLastError(dde_inst
);
1548 hdata
= DdeCreateDataHandle(dde_inst
, NULL
, MAX_PATH
, 0, item
, CF_TEXT
, 0);
1549 err
= DdeGetLastError(dde_inst
);
1550 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1551 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1553 ptr
= GlobalLock(hdata
);
1556 ok(ptr
== NULL
, "Expected NULL, got %p\n", ptr
);
1559 ptr
= DdeAccessData(hdata
, &size
);
1560 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1561 ok(size
== 260, "Expected 260, got %d\n", size
);
1563 ret
= DdeUnaccessData(hdata
);
1564 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1566 ret
= DdeFreeDataHandle(hdata
);
1567 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1570 DdeGetLastError(dde_inst
);
1571 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", 0, 0, item
, CF_TEXT
, 0);
1572 err
= DdeGetLastError(dde_inst
);
1573 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1574 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1576 ptr
= GlobalLock(hdata
);
1579 ok(ptr
== NULL
, "Expected NULL, got %p\n", ptr
);
1582 ptr
= DdeAccessData(hdata
, &size
);
1583 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1584 ok(size
== 0, "Expected 0, got %d\n", size
);
1586 ret
= DdeUnaccessData(hdata
);
1587 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1589 ret
= DdeFreeDataHandle(hdata
);
1590 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1592 /* cbOff is non-zero */
1593 DdeGetLastError(dde_inst
);
1594 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 2, item
, CF_TEXT
, 0);
1595 err
= DdeGetLastError(dde_inst
);
1596 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1597 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1599 ptr
= GlobalLock(hdata
);
1602 ok(ptr
== NULL
, "Expected NULL, got %p\n", ptr
);
1605 ptr
= DdeAccessData(hdata
, &size
);
1606 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1607 ok(size
== 262, "Expected 262, got %d\n", size
);
1610 ok(lstrlenA((LPSTR
)ptr
) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR
)ptr
));
1613 ret
= DdeUnaccessData(hdata
);
1614 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1616 ret
= DdeFreeDataHandle(hdata
);
1617 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1620 DdeGetLastError(dde_inst
);
1621 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, 0, CF_TEXT
, 0);
1622 err
= DdeGetLastError(dde_inst
);
1623 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1624 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1626 ptr
= GlobalLock(hdata
);
1629 ok(ptr
== NULL
, "Expected NULL, got %p\n", ptr
);
1632 ptr
= DdeAccessData(hdata
, &size
);
1633 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1634 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1635 ok(size
== 260, "Expected 260, got %d\n", size
);
1637 ret
= DdeUnaccessData(hdata
);
1638 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1640 ret
= DdeFreeDataHandle(hdata
);
1641 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1644 DdeGetLastError(dde_inst
);
1645 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, (HSZ
)0xdeadbeef, CF_TEXT
, 0);
1646 err
= DdeGetLastError(dde_inst
);
1647 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1648 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1650 ptr
= GlobalLock(hdata
);
1653 ok(ptr
== NULL
, "Expected NULL, got %p\n", ptr
);
1656 ptr
= DdeAccessData(hdata
, &size
);
1657 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1658 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1659 ok(size
== 260, "Expected 260, got %d\n", size
);
1661 ret
= DdeUnaccessData(hdata
);
1662 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1664 ret
= DdeFreeDataHandle(hdata
);
1665 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1667 /* invalid clipboard format */
1668 DdeGetLastError(dde_inst
);
1669 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, item
, 0xdeadbeef, 0);
1670 err
= DdeGetLastError(dde_inst
);
1671 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1672 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1674 ptr
= GlobalLock(hdata
);
1677 ok(ptr
== NULL
, "Expected NULL, got %p\n", ptr
);
1680 ptr
= DdeAccessData(hdata
, &size
);
1681 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1682 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1683 ok(size
== 260, "Expected 260, got %d\n", size
);
1685 ret
= DdeUnaccessData(hdata
);
1686 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1688 ret
= DdeFreeDataHandle(hdata
);
1689 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1691 ret
= DdeUninitialize(dde_inst
);
1692 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1695 static void test_DdeCreateStringHandle(void)
1697 DWORD dde_inst
, ret
;
1699 dde_inst
= 0xdeadbeef;
1700 SetLastError(0xdeadbeef);
1701 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1702 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1704 win_skip("DdeInitializeW is unimplemented\n");
1708 ok(ret
== DMLERR_INVALIDPARAMETER
, "DdeInitializeW should fail, but got %04x instead\n", ret
);
1709 ok(DdeGetLastError(dde_inst
) == DMLERR_INVALIDPARAMETER
, "expected DMLERR_INVALIDPARAMETER\n");
1712 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1713 ok(ret
== DMLERR_NO_ERROR
, "DdeInitializeW failed with error %04x (%08x)\n",
1714 ret
, DdeGetLastError(dde_inst
));
1716 test_DdeCreateStringHandleW(dde_inst
, 0);
1717 test_DdeCreateStringHandleW(dde_inst
, CP_WINUNICODE
);
1718 test_DdeCreateStringHandleW(dde_inst
, CP_WINANSI
);
1720 ok(DdeUninitialize(dde_inst
), "DdeUninitialize failed\n");
1723 static void test_FreeDDElParam(void)
1725 HGLOBAL val
, hglobal
;
1728 ret
= FreeDDElParam(WM_DDE_INITIATE
, 0);
1729 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1731 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1732 ret
= FreeDDElParam(WM_DDE_INITIATE
, (LPARAM
)hglobal
);
1733 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1734 val
= GlobalFree(hglobal
);
1735 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
1737 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1738 ret
= FreeDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
);
1739 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1740 val
= GlobalFree(hglobal
);
1741 ok(val
== hglobal
, "Expected hglobal, got %p\n", val
);
1742 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1743 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1745 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1746 ret
= FreeDDElParam(WM_DDE_UNADVISE
, (LPARAM
)hglobal
);
1747 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1748 val
= GlobalFree(hglobal
);
1749 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
1751 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1752 ret
= FreeDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
);
1753 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1754 val
= GlobalFree(hglobal
);
1755 ok(val
== hglobal
, "Expected hglobal, got %p\n", val
);
1756 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1757 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1759 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1760 ret
= FreeDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
);
1761 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1762 val
= GlobalFree(hglobal
);
1763 ok(val
== hglobal
, "Expected hglobal, got %p\n", val
);
1764 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1765 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1767 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1768 ret
= FreeDDElParam(WM_DDE_REQUEST
, (LPARAM
)hglobal
);
1769 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1770 val
= GlobalFree(hglobal
);
1771 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
1773 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1774 ret
= FreeDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
);
1775 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1776 val
= GlobalFree(hglobal
);
1777 ok(val
== hglobal
, "Expected hglobal, got %p\n", val
);
1778 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1779 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1781 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
1782 ret
= FreeDDElParam(WM_DDE_EXECUTE
, (LPARAM
)hglobal
);
1783 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1784 val
= GlobalFree(hglobal
);
1785 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
1788 static void test_PackDDElParam(void)
1790 UINT_PTR lo
, hi
, *ptr
;
1795 lparam
= PackDDElParam(WM_DDE_INITIATE
, 0xcafe, 0xbeef);
1796 ok(lparam
== 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
1797 ok(GlobalLock((HGLOBAL
)lparam
) == NULL
,
1798 "Expected NULL, got %p\n", GlobalLock((HGLOBAL
)lparam
));
1799 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1800 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1803 ret
= UnpackDDElParam(WM_DDE_INITIATE
, lparam
, &lo
, &hi
);
1804 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1805 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1806 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1808 ret
= FreeDDElParam(WM_DDE_INITIATE
, lparam
);
1809 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1811 lparam
= PackDDElParam(WM_DDE_TERMINATE
, 0xcafe, 0xbeef);
1812 ok(lparam
== 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
1813 ok(GlobalLock((HGLOBAL
)lparam
) == NULL
,
1814 "Expected NULL, got %p\n", GlobalLock((HGLOBAL
)lparam
));
1815 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1816 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1819 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, lparam
, &lo
, &hi
);
1820 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1821 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1822 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1824 ret
= FreeDDElParam(WM_DDE_TERMINATE
, lparam
);
1825 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1827 lparam
= PackDDElParam(WM_DDE_ADVISE
, 0xcafe, 0xbeef);
1828 /* win9x returns 0 here */
1830 ptr
= GlobalLock((HGLOBAL
)lparam
);
1831 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1832 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
1833 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
1835 ret
= GlobalUnlock((HGLOBAL
)lparam
);
1836 ok(ret
== 1, "Expected 1, got %d\n", ret
);
1839 ret
= UnpackDDElParam(WM_DDE_ADVISE
, lparam
, &lo
, &hi
);
1840 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1841 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1842 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1845 win_skip("no lparam for WM_DDE_ADVISE\n");
1847 ret
= FreeDDElParam(WM_DDE_ADVISE
, lparam
);
1848 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1850 hglobal
= GlobalFree((HGLOBAL
)lparam
);
1851 ok(hglobal
== (HGLOBAL
)lparam
, "Expected lparam, got %d\n", ret
);
1852 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1853 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1855 lparam
= PackDDElParam(WM_DDE_UNADVISE
, 0xcafe, 0xbeef);
1856 ok(lparam
== 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
1857 ok(GlobalLock((HGLOBAL
)lparam
) == NULL
,
1858 "Expected NULL, got %p\n", GlobalLock((HGLOBAL
)lparam
));
1859 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1860 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1863 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, lparam
, &lo
, &hi
);
1864 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1865 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1866 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1868 ret
= FreeDDElParam(WM_DDE_UNADVISE
, lparam
);
1869 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1871 lparam
= PackDDElParam(WM_DDE_ACK
, 0xcafe, 0xbeef);
1872 /* win9x returns the input (0xbeef<<16 | 0xcafe) here */
1873 if (lparam
!= 0xbeefcafe) {
1874 ptr
= GlobalLock((HGLOBAL
)lparam
);
1875 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1876 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
1877 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
1879 ret
= GlobalUnlock((HGLOBAL
)lparam
);
1880 ok(ret
== 1, "Expected 1, got %d\n", ret
);
1883 ret
= UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1884 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1885 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1886 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1888 ret
= FreeDDElParam(WM_DDE_ACK
, lparam
);
1889 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1891 hglobal
= GlobalFree((HGLOBAL
)lparam
);
1892 ok(hglobal
== (HGLOBAL
)lparam
, "Expected lparam, got %d\n", ret
);
1893 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1894 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1897 win_skip("got lparam 0x%lx for WM_DDE_ACK\n", lparam
);
1899 lparam
= PackDDElParam(WM_DDE_DATA
, 0xcafe, 0xbeef);
1900 /* win9x returns 0 here */
1902 ptr
= GlobalLock((HGLOBAL
)lparam
);
1903 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1904 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
1905 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
1907 ret
= GlobalUnlock((HGLOBAL
)lparam
);
1908 ok(ret
== 1, "Expected 1, got %d\n", ret
);
1911 ret
= UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
1912 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1913 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1914 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1917 win_skip("no lparam for WM_DDE_DATA\n");
1919 ret
= FreeDDElParam(WM_DDE_DATA
, lparam
);
1920 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1922 hglobal
= GlobalFree((HGLOBAL
)lparam
);
1923 ok(hglobal
== (HGLOBAL
)lparam
, "Expected lparam, got %d\n", ret
);
1924 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1925 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1927 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xcafe, 0xbeef);
1928 ok(lparam
== 0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
1929 ok(GlobalLock((HGLOBAL
)lparam
) == NULL
,
1930 "Expected NULL, got %p\n", GlobalLock((HGLOBAL
)lparam
));
1931 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1932 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1935 ret
= UnpackDDElParam(WM_DDE_REQUEST
, lparam
, &lo
, &hi
);
1936 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1937 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1938 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1940 ret
= FreeDDElParam(WM_DDE_REQUEST
, lparam
);
1941 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1943 lparam
= PackDDElParam(WM_DDE_POKE
, 0xcafe, 0xbeef);
1944 /* win9x returns 0 here */
1946 ptr
= GlobalLock((HGLOBAL
)lparam
);
1947 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1948 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
1949 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
1951 ret
= GlobalUnlock((HGLOBAL
)lparam
);
1952 ok(ret
== 1, "Expected 1, got %d\n", ret
);
1955 ret
= UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
1956 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1957 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
1958 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1961 win_skip("no lparam for WM_DDE_POKE\n");
1963 ret
= FreeDDElParam(WM_DDE_POKE
, lparam
);
1964 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1966 hglobal
= GlobalFree((HGLOBAL
)lparam
);
1967 ok(hglobal
== (HGLOBAL
)lparam
, "Expected lparam, got %d\n", ret
);
1968 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1969 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1971 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0xcafe, 0xbeef);
1972 ok(lparam
== 0xbeef, "Expected 0xbeef, got %08lx\n", lparam
);
1973 ok(GlobalLock((HGLOBAL
)lparam
) == NULL
,
1974 "Expected NULL, got %p\n", GlobalLock((HGLOBAL
)lparam
));
1975 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1976 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1979 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1980 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1981 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
1982 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
1984 ret
= FreeDDElParam(WM_DDE_EXECUTE
, lparam
);
1985 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1988 static void test_UnpackDDElParam(void)
1990 UINT_PTR lo
, hi
, *ptr
;
1997 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0, &lo
, &hi
);
1998 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1999 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2000 ok(hi
== 0, "Expected 0, got %08lx\n", hi
);
2005 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, NULL
, &hi
);
2006 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2007 ok(lo
== 0xdead, "Expected 0xdead, got %08lx\n", lo
);
2008 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2013 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, NULL
);
2014 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2015 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2016 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2020 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, &hi
);
2021 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2022 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2023 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2027 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, 0xcafebabe, &lo
, &hi
);
2028 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2029 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2030 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2034 ret
= UnpackDDElParam(WM_DDE_ADVISE
, 0, &lo
, &hi
);
2035 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2037 broken(lo
== 0xdead), /* win2k */
2038 "Expected 0, got %08lx\n", lo
);
2040 broken(hi
== 0xbeef), /* win2k */
2041 "Expected 0, got %08lx\n", hi
);
2045 ret
= UnpackDDElParam(WM_DDE_ADVISE
, 0xcafebabe, &lo
, &hi
);
2046 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2048 broken(lo
== 0xdead), /* win2k */
2049 "Expected 0, got %08lx\n", lo
);
2051 broken(hi
== 0xbeef), /* win2k */
2052 "Expected 0, got %08lx\n", hi
);
2054 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 2);
2055 ptr
= GlobalLock(hglobal
);
2056 ptr
[0] = 0xcafebabe;
2057 ptr
[1] = 0xdeadbeef;
2058 GlobalUnlock(hglobal
);
2062 ret
= UnpackDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
, &lo
, &hi
);
2063 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2064 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2065 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2069 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, 0xcafebabe, &lo
, &hi
);
2070 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2071 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2072 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2076 ret
= UnpackDDElParam(WM_DDE_ACK
, 0xcafebabe, &lo
, &hi
);
2077 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2079 broken(lo
== 0xdead), /* win2k */
2080 "Expected 0, got %08lx\n", lo
);
2082 broken(hi
== 0xbeef), /* win2k */
2083 "Expected 0, got %08lx\n", hi
);
2087 ret
= UnpackDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
, &lo
, &hi
);
2088 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2089 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2090 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2094 ret
= UnpackDDElParam(WM_DDE_DATA
, 0xcafebabe, &lo
, &hi
);
2095 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2097 broken(lo
== 0xdead), /* win2k */
2098 "Expected 0, got %08lx\n", lo
);
2100 broken(hi
== 0xbeef), /* win2k */
2101 "Expected 0, got %08lx\n", hi
);
2105 ret
= UnpackDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
, &lo
, &hi
);
2106 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2107 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2108 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2112 ret
= UnpackDDElParam(WM_DDE_REQUEST
, 0xcafebabe, &lo
, &hi
);
2113 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2114 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2115 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2119 ret
= UnpackDDElParam(WM_DDE_POKE
, 0xcafebabe, &lo
, &hi
);
2120 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2122 broken(lo
== 0xdead), /* win2k */
2123 "Expected 0, got %08lx\n", lo
);
2125 broken(hi
== 0xbeef), /* win2k */
2126 "Expected 0, got %08lx\n", hi
);
2130 ret
= UnpackDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
, &lo
, &hi
);
2131 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2132 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2133 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2137 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, 0xcafebabe, &lo
, &hi
);
2138 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2139 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2140 ok(hi
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi
);
2143 static HDDEDATA CALLBACK
server_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2144 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2145 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2149 static int msg_index
= 0;
2150 static HCONV conversation
= 0;
2151 static char test_cmd
[] = "test dde command";
2152 static WCHAR test_cmd_w
[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2153 static char test_service
[] = "TestDDEService";
2154 static char test_topic
[] = "TestDDETopic";
2162 ok(msg_index
== 1 || msg_index
== 7 || msg_index
== 13 || msg_index
== 19,
2163 "Expected 1, 7, 13 or 19, got %d\n", msg_index
);
2164 return (HDDEDATA
)TRUE
;
2169 ok(msg_index
== 2 || msg_index
== 8 || msg_index
== 14 || msg_index
== 20,
2170 "Expected 2, 8, 14 or 20, got %d\n", msg_index
);
2171 ok(uFmt
== 0, "Expected 0, got %d, msg_index=%d\n", uFmt
, msg_index
);
2172 ok(hconv
== 0, "Expected 0, got %p, msg_index=%d\n", hconv
, msg_index
);
2173 ok(hdata
== 0, "Expected 0, got %p, msg_index=%d\n", hdata
, msg_index
);
2174 ok(dwData1
!= 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1
, msg_index
);
2175 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2
, msg_index
);
2177 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2178 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2179 test_topic
, str
, msg_index
);
2180 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2182 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
2183 ok(!lstrcmpA(str
, test_service
), "Expected %s, got %s, msg_index=%d\n",
2184 test_service
, str
, msg_index
);
2185 ok(size
== 14, "Expected 14, got %d, msg_index=%d\n", size
, msg_index
);
2187 return (HDDEDATA
) TRUE
;
2189 case XTYP_CONNECT_CONFIRM
:
2191 ok(msg_index
== 3 || msg_index
== 9 || msg_index
== 15 || msg_index
== 21,
2192 "Expected 3, 9, 15 or 21 got %d\n", msg_index
);
2193 conversation
= hconv
;
2194 return (HDDEDATA
) TRUE
;
2198 BYTE
*buffer
= NULL
;
2200 ok(msg_index
== 4 || msg_index
== 5 || msg_index
== 10 || msg_index
== 11 ||
2201 msg_index
== 16 || msg_index
== 17 || msg_index
== 22 || msg_index
== 23,
2202 "Expected 4, 5, 10, 11, 16, 17, 22 or 23, got %d\n", msg_index
);
2203 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
2204 ok(hconv
== conversation
, "Expected conversation handle, got %p, msg_index=%d\n",
2206 ok(dwData1
== 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1
, msg_index
);
2207 ok(dwData2
== 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2
, msg_index
);
2208 ok(hsz2
== 0, "Expected 0, got %p, msg_index=%d\n", hsz2
, msg_index
);
2209 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2210 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2211 test_topic
, str
, msg_index
);
2212 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2213 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2215 size
= DdeGetData(hdata
, NULL
, 0, 0);
2216 if (msg_index
== 10 || msg_index
==11 || msg_index
== 16 || msg_index
==17)
2217 if (msg_index
== 10 || msg_index
== 16)
2219 ok(size
== 34, "Expected that size should be 34 not %d, msg_index=%d\n",
2222 ok(size
== 34, "Expected that size should be 34 not %d, msg_index=%d\n",
2227 ok(size
== 9, "Expected that size should be 9 not %d, msg_index=%d\n",
2232 ok(size
== 17, "Expected that size should be 17 not %d, msg_index=%d\n",
2235 ok(size
== 17, "Expected that size should be 17 not %d, msg_index=%d\n",
2237 ok((buffer
= HeapAlloc(GetProcessHeap(), 0, size
)) != NULL
, "should not be null\n");
2238 rsize
= DdeGetData(hdata
, buffer
, size
, 0);
2239 if (msg_index
== 10 || msg_index
== 11 || msg_index
== 16 || msg_index
==17)
2241 ok(rsize
== size
, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2242 size
, rsize
, msg_index
);
2243 if (msg_index
== 10 || msg_index
== 16)
2245 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_w
),
2246 "Expected \"Test dde command\", msg_index=%d\n",
2248 ok(size
== 34, "Expected 34, got %d, msg_index=%d\n", size
, msg_index
);
2251 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_w
),
2252 "Expected \"Test dde command\", msg_index=%d\n",
2254 ok(size
== 34, "Expected 34, got %d, msg_index=%d\n", size
, msg_index
);
2256 }else if (msg_index
== 22)
2258 ok(rsize
== size
, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2259 size
, rsize
, msg_index
);
2262 ok(rsize
== size
, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2263 size
, rsize
, msg_index
);
2266 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd
), "Expected %s, got %s, msg_index=%d\n",
2267 test_cmd
, buffer
, msg_index
);
2268 ok(size
== 17, "Expected size should be 17, got %d, msg_index=%d\n", size
, msg_index
);
2272 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd
), "Expected %s, got %s, msg_index=%d\n",
2273 test_cmd
, buffer
, msg_index
);
2274 ok(size
== 17, "Expected size should be 17, got %d, msg_index=%d\n", size
, msg_index
);
2279 return (HDDEDATA
) DDE_FACK
;
2281 case XTYP_DISCONNECT
:
2282 return (HDDEDATA
) TRUE
;
2285 ok(FALSE
, "Unhandled msg: %08x, msg_index=%d\n", uType
, msg_index
);
2291 static HDDEDATA CALLBACK
client_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2292 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2293 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2297 case XTYP_DISCONNECT
:
2298 return (HDDEDATA
) TRUE
;
2301 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
2307 static void test_end_to_end_client(BOOL type_a
)
2310 DWORD client_pid
= 0;
2314 static char test_cmd
[] = "test dde command";
2315 static WCHAR test_cmd_w
[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2316 static char test_service
[] = "TestDDEService";
2317 static WCHAR test_service_w
[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2318 static char test_topic
[] = "TestDDETopic";
2319 static WCHAR test_topic_w
[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2321 trace("Start end to end client %d\n", type_a
);
2324 ret
= DdeInitializeA(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2326 ret
= DdeInitializeW(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2327 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %x\n", ret
);
2331 server
= DdeCreateStringHandleA(client_pid
, test_service
, CP_WINANSI
);
2332 topic
= DdeCreateStringHandleA(client_pid
, test_topic
, CP_WINANSI
);
2335 server
= DdeCreateStringHandleW(client_pid
, test_service_w
, CP_WINUNICODE
);
2336 topic
= DdeCreateStringHandleW(client_pid
, test_topic_w
, CP_WINUNICODE
);
2339 DdeGetLastError(client_pid
);
2340 hconv
= DdeConnect(client_pid
, server
, topic
, NULL
);
2341 ok(hconv
!= NULL
, "Expected non-NULL conversation\n");
2342 ret
= DdeGetLastError(client_pid
);
2343 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %x\n", ret
);
2344 DdeFreeStringHandle(client_pid
, server
);
2346 /* Test both A and W data being passed to DdeClientTransaction */
2347 hdata
= DdeClientTransaction((LPBYTE
)test_cmd
, strlen(test_cmd
) + 1,
2348 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2349 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2350 ok(ret
== DDE_FACK
, "wrong status code %x\n", ret
);
2351 err
= DdeGetLastError(client_pid
);
2352 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
2354 hdata
= DdeClientTransaction((LPBYTE
)test_cmd_w
, lstrlenW(test_cmd_w
) * sizeof(WCHAR
) + 2,
2355 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2356 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2357 ok(ret
== DDE_FACK
, "wrong status code %x\n", ret
);
2358 err
= DdeGetLastError(client_pid
);
2359 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
2361 DdeFreeStringHandle(client_pid
, topic
);
2362 ret
= DdeDisconnect(hconv
);
2363 ok(ret
== TRUE
, "Expected TRUE, got %x\n", ret
);
2365 ret
= DdeUninitialize(client_pid
);
2366 ok(ret
== TRUE
, "Expected TRUE, got %x\n", ret
);
2370 static void test_end_to_end_server(HANDLE hproc
, HANDLE hthread
, BOOL type_a
)
2377 static CHAR test_service
[] = "TestDDEService";
2379 trace("start end to end server %d\n", type_a
);
2383 res
= DdeInitializeA(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2385 res
= DdeInitializeW(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2386 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
2388 server
= DdeCreateStringHandleA(server_pid
, test_service
, CP_WINANSI
);
2389 ok(server
!= NULL
, "Expected non-NULL string handle\n");
2391 hdata
= DdeNameService(server_pid
, server
, 0, DNS_REGISTER
);
2392 ok(hdata
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", hdata
);
2393 ResumeThread( hthread
);
2396 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
2398 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2401 ret
= DdeUninitialize(server_pid
);
2402 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2403 GetExitCodeProcess( hproc
, &res
);
2404 ok( !res
, "client failed with %u error(s)\n", res
);
2411 char buffer
[MAX_PATH
];
2412 STARTUPINFO startup
;
2413 PROCESS_INFORMATION proc
;
2415 argc
= winetest_get_mainargs(&argv
);
2418 if (!lstrcmpA(argv
[2], "ddeml"))
2419 test_ddeml_client();
2420 else if (!lstrcmpA(argv
[2], "msg"))
2422 else if (!lstrcmpA(argv
[2], "enda"))
2423 test_end_to_end_client(TRUE
);
2424 else if (!lstrcmpA(argv
[2], "endw"))
2425 test_end_to_end_client(FALSE
);
2430 test_initialisation();
2432 ZeroMemory(&startup
, sizeof(STARTUPINFO
));
2433 sprintf(buffer
, "%s dde ddeml", argv
[0]);
2434 startup
.cb
= sizeof(startup
);
2435 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
2436 startup
.wShowWindow
= SW_SHOWNORMAL
;
2438 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2439 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2441 test_msg_server(proc
.hProcess
, proc
.hThread
);
2443 sprintf(buffer
, "%s dde msg", argv
[0]);
2444 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2445 0, NULL
, NULL
, &startup
, &proc
);
2447 test_ddeml_server(proc
.hProcess
);
2449 /* Test the combinations of A and W interfaces with A and W data
2450 end to end to ensure that data conversions are accurate */
2451 sprintf(buffer
, "%s dde enda", argv
[0]);
2452 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2453 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2455 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, TRUE
);
2457 sprintf(buffer
, "%s dde endw", argv
[0]);
2458 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2459 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2461 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, FALSE
);
2463 sprintf(buffer
, "%s dde enda", argv
[0]);
2464 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2465 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2467 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, FALSE
);
2469 sprintf(buffer
, "%s dde endw", argv
[0]);
2470 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2471 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2473 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, TRUE
);
2475 test_dde_aw_transaction();
2477 test_DdeCreateDataHandle();
2478 test_DdeCreateStringHandle();
2479 test_FreeDDElParam();
2480 test_PackDDElParam();
2481 test_UnpackDDElParam();