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_cmdAW
[] = {'A','N','S','I',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
39 static WCHAR exec_cmdW
[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
40 static char exec_cmdWA
[] = "unicode dde command";
42 static WNDPROC old_dde_client_wndproc
;
44 static const DWORD default_timeout
= 200;
46 static void flush_events(void)
49 int diff
= default_timeout
;
51 DWORD time
= GetTickCount() + diff
;
55 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
56 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
57 diff
= time
- GetTickCount();
62 static void create_dde_window(HWND
*hwnd
, LPCSTR name
, WNDPROC wndproc
)
66 memset(&wcA
, 0, sizeof(wcA
));
67 wcA
.lpfnWndProc
= wndproc
;
68 wcA
.lpszClassName
= name
;
69 wcA
.hInstance
= GetModuleHandleA(0);
70 assert(RegisterClassA(&wcA
));
72 *hwnd
= CreateWindowExA(0, name
, NULL
, WS_POPUP
,
73 500, 500, CW_USEDEFAULT
, CW_USEDEFAULT
,
74 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
78 static void destroy_dde_window(HWND
*hwnd
, LPCSTR name
)
81 UnregisterClass(name
, GetModuleHandleA(0));
84 static LRESULT WINAPI
dde_server_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
87 char str
[MAX_PATH
], *ptr
;
93 static int msg_index
= 0;
94 static HWND client
= 0;
95 static BOOL executed
= FALSE
;
97 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
98 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
104 case WM_DDE_INITIATE
:
106 client
= (HWND
)wparam
;
107 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
109 GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
110 ok(!lstrcmpA(str
, "TestDDEService"), "Expected TestDDEService, got %s\n", str
);
112 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
113 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
115 SendMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
122 ok((msg_index
>= 2 && msg_index
<= 4) ||
123 (msg_index
>= 7 && msg_index
<= 8),
124 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index
);
125 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
126 ok(LOWORD(lparam
) == CF_TEXT
, "Expected CF_TEXT, got %d\n", LOWORD(lparam
));
128 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
130 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
132 ok(!lstrcmpA(str
, "executed"), "Expected executed, got %s\n", str
);
137 lstrcpyA(str
, "command executed\r\n");
139 lstrcpyA(str
, "command not executed\r\n");
142 lstrcpyA(str
, "requested data\r\n");
144 size
= sizeof(DDEDATA
) + lstrlenA(str
) + 1;
145 hglobal
= GlobalAlloc(GMEM_MOVEABLE
, size
);
146 ok(hglobal
!= NULL
, "Expected non-NULL hglobal\n");
148 data
= GlobalLock(hglobal
);
149 ZeroMemory(data
, size
);
151 /* setting fResponse to FALSE at this point destroys
152 * the internal messaging state of native dde
154 data
->fResponse
= TRUE
;
157 data
->fRelease
= TRUE
;
158 else if (msg_index
== 3)
159 data
->fAckReq
= TRUE
;
161 data
->cfFormat
= CF_TEXT
;
162 lstrcpyA((LPSTR
)data
->Value
, str
);
163 GlobalUnlock(hglobal
);
165 lparam
= PackDDElParam(WM_DDE_DATA
, (UINT_PTR
)hglobal
, HIWORD(lparam
));
166 PostMessageA(client
, WM_DDE_DATA
, (WPARAM
)hwnd
, lparam
);
173 ok(msg_index
== 5 || msg_index
== 6, "Expected 5 or 6, got %d\n", msg_index
);
174 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
176 UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
178 GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
179 ok(!lstrcmpA(str
, "poker"), "Expected poker, got %s\n", str
);
181 poke
= GlobalLock((HGLOBAL
)lo
);
182 ok(poke
!= NULL
, "Expected non-NULL poke\n");
183 ok(poke
->fReserved
== 0, "Expected 0, got %d\n", poke
->fReserved
);
184 ok(poke
->unused
== 0, "Expected 0, got %d\n", poke
->unused
);
185 ok(poke
->fRelease
== TRUE
, "Expected TRUE, got %d\n", poke
->fRelease
);
186 ok(poke
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", poke
->cfFormat
);
190 size
= GlobalSize((HGLOBAL
)lo
);
191 ok(size
== 4 || broken(size
== 32), /* sizes are rounded up on win9x */ "got %d\n", size
);
194 ok(!lstrcmpA((LPSTR
)poke
->Value
, "poke data\r\n"),
195 "Expected 'poke data\\r\\n', got %s\n", poke
->Value
);
197 GlobalUnlock((HGLOBAL
)lo
);
199 lparam
= PackDDElParam(WM_DDE_ACK
, DDE_FACK
, hi
);
200 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
207 ok(msg_index
== 7, "Expected 7, got %d\n", msg_index
);
208 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
210 ptr
= GlobalLock((HGLOBAL
)lparam
);
211 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr
);
212 GlobalUnlock((HGLOBAL
)lparam
);
216 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, DDE_FACK
, lparam
);
217 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
222 case WM_DDE_TERMINATE
:
224 ok(msg_index
== 9, "Expected 9, got %d\n", msg_index
);
225 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
226 ok(lparam
== 0, "Expected 0, got %08lx\n", lparam
);
228 PostMessageA(client
, WM_DDE_TERMINATE
, (WPARAM
)hwnd
, 0);
233 case WM_DDE_ACK
: /* happens on win9x when fAckReq is TRUE, ignore it */
234 ok(msg_index
== 4, "Expected 4, got %d\n", msg_index
);
239 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
242 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
245 static void test_msg_server(HANDLE hproc
, HANDLE hthread
)
251 create_dde_window(&hwnd
, "dde_server", dde_server_wndproc
);
252 ResumeThread( hthread
);
254 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
256 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
259 destroy_dde_window(&hwnd
, "dde_server");
260 GetExitCodeProcess( hproc
, &res
);
261 ok( !res
, "client failed with %u error(s)\n", res
);
264 static HDDEDATA CALLBACK
client_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
265 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
266 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
268 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
272 static void test_ddeml_client(void)
279 HSZ server
, topic
, item
;
284 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
285 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
287 /* FIXME: make these atoms global and check them in the server */
289 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
290 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
292 DdeGetLastError(client_pid
);
293 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
294 ok(conversation
!= NULL
, "Expected non-NULL conversation\n");
295 ret
= DdeGetLastError(client_pid
);
296 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
298 DdeFreeStringHandle(client_pid
, server
);
300 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
302 /* XTYP_REQUEST, fRelease = TRUE */
304 DdeGetLastError(client_pid
);
305 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
306 ret
= DdeGetLastError(client_pid
);
307 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
308 ok(res
== DDE_FNOTPROCESSED
|| broken(res
== 0xdeadbeef), /* win9x */
309 "Expected DDE_FNOTPROCESSED, got %08x\n", res
);
310 ok( hdata
!= NULL
, "hdata is NULL\n" );
313 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
314 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
315 ok(size
== 19 || broken(size
== 28), /* sizes are rounded up on win9x */
316 "Expected 19, got %d\n", size
);
318 ret
= DdeUnaccessData(hdata
);
319 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
322 /* XTYP_REQUEST, fAckReq = TRUE */
324 DdeGetLastError(client_pid
);
325 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
326 ret
= DdeGetLastError(client_pid
);
327 ok(res
== DDE_FNOTPROCESSED
|| broken(res
== 0xdeadbeef), /* win9x */
328 "Expected DDE_FNOTPROCESSED, got %x\n", res
);
330 ok(ret
== DMLERR_MEMORY_ERROR
|| broken(ret
== 0), /* win9x */
331 "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
332 ok( hdata
!= NULL
, "hdata is NULL\n" );
335 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
336 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
337 ok(size
== 19 || broken(size
== 28), /* sizes are rounded up on win9x */
338 "Expected 19, got %d\n", size
);
340 ret
= DdeUnaccessData(hdata
);
341 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
344 /* XTYP_REQUEST, all params normal */
346 DdeGetLastError(client_pid
);
347 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
348 ret
= DdeGetLastError(client_pid
);
349 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
350 ok(res
== DDE_FNOTPROCESSED
|| broken(res
== 0xdeadbeef), /* win9x */
351 "Expected DDE_FNOTPROCESSED, got %x\n", res
);
353 ok(FALSE
, "hdata is NULL\n");
356 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
357 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
358 ok(size
== 19 || broken(size
== 28), /* sizes are rounded up on win9x */
359 "Expected 19, got %d\n", size
);
361 ret
= DdeUnaccessData(hdata
);
362 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
365 /* XTYP_REQUEST, no item */
367 DdeGetLastError(client_pid
);
368 hdata
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
369 ret
= DdeGetLastError(client_pid
);
370 ok(hdata
== NULL
, "Expected NULL hdata, got %p\n", hdata
);
371 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res
);
372 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
374 DdeFreeStringHandle(client_pid
, item
);
376 item
= DdeCreateStringHandleA(client_pid
, "poker", CP_WINANSI
);
378 lstrcpyA(buffer
, "poke data\r\n");
379 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
380 0, item
, CF_TEXT
, 0);
381 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
383 /* XTYP_POKE, no item */
385 DdeGetLastError(client_pid
);
386 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
387 ret
= DdeGetLastError(client_pid
);
388 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
389 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
390 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
392 /* XTYP_POKE, no data */
394 DdeGetLastError(client_pid
);
395 op
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
396 ret
= DdeGetLastError(client_pid
);
397 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
398 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
399 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
401 /* XTYP_POKE, wrong size */
403 DdeGetLastError(client_pid
);
404 op
= DdeClientTransaction((LPBYTE
)hdata
, 0, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
405 ret
= DdeGetLastError(client_pid
);
406 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
407 ok(res
== DDE_FACK
|| broken(res
== 0xdeadbeef), /* win9x */ "Expected DDE_FACK, got %x\n", res
);
408 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
410 /* XTYP_POKE, correct params */
412 DdeGetLastError(client_pid
);
413 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
414 ret
= DdeGetLastError(client_pid
);
415 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
416 ok(res
== DDE_FACK
|| broken(res
== (0xdead0000 | DDE_FACK
)), /* win9x */
417 "Expected DDE_FACK, got %x\n", res
);
418 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
420 DdeFreeDataHandle(hdata
);
422 lstrcpyA(buffer
, "[Command(Var)]");
423 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
424 0, NULL
, CF_TEXT
, 0);
425 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
427 /* XTYP_EXECUTE, correct params */
429 DdeGetLastError(client_pid
);
430 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
431 ret
= DdeGetLastError(client_pid
);
432 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
433 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
434 ok(res
== DDE_FACK
|| broken(res
== 0xdeadbeef), /* win9x */ "Expected DDE_FACK, got %x\n", res
);
436 /* XTYP_EXECUTE, no data */
438 DdeGetLastError(client_pid
);
439 op
= DdeClientTransaction(NULL
, 0, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
440 ret
= DdeGetLastError(client_pid
);
441 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
442 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
443 ok(ret
== DMLERR_MEMORY_ERROR
, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
445 /* XTYP_EXECUTE, no data, -1 size */
447 DdeGetLastError(client_pid
);
448 op
= DdeClientTransaction(NULL
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
449 ret
= DdeGetLastError(client_pid
);
450 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
451 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
452 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
454 DdeFreeStringHandle(client_pid
, topic
);
455 DdeFreeDataHandle(hdata
);
457 item
= DdeCreateStringHandleA(client_pid
, "executed", CP_WINANSI
);
459 /* verify the execute */
461 DdeGetLastError(client_pid
);
462 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
463 ret
= DdeGetLastError(client_pid
);
464 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
465 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %d\n", res
);
467 ok(FALSE
, "hdata is NULL\n");
470 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
471 ok(!lstrcmpA(str
, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str
);
472 ok(size
== 21, "Expected 21, got %d\n", size
);
474 ret
= DdeUnaccessData(hdata
);
475 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
478 /* invalid transactions */
480 DdeGetLastError(client_pid
);
481 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_ADVREQ
, default_timeout
, &res
);
482 ret
= DdeGetLastError(client_pid
);
483 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
484 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
485 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
488 DdeGetLastError(client_pid
);
489 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_CONNECT
, default_timeout
, &res
);
490 ret
= DdeGetLastError(client_pid
);
491 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
492 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
493 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
496 DdeGetLastError(client_pid
);
497 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_CONNECT_CONFIRM
, default_timeout
, &res
);
498 ret
= DdeGetLastError(client_pid
);
499 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
500 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
501 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
504 DdeGetLastError(client_pid
);
505 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_DISCONNECT
, default_timeout
, &res
);
506 ret
= DdeGetLastError(client_pid
);
507 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
508 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
509 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
512 DdeGetLastError(client_pid
);
513 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_ERROR
, default_timeout
, &res
);
514 ret
= DdeGetLastError(client_pid
);
515 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
516 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
517 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
520 DdeGetLastError(client_pid
);
521 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_MONITOR
, default_timeout
, &res
);
522 ret
= DdeGetLastError(client_pid
);
523 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
524 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
525 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
528 DdeGetLastError(client_pid
);
529 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REGISTER
, default_timeout
, &res
);
530 ret
= DdeGetLastError(client_pid
);
531 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
532 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
533 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
536 DdeGetLastError(client_pid
);
537 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_UNREGISTER
, default_timeout
, &res
);
538 ret
= DdeGetLastError(client_pid
);
539 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
540 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
541 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
544 DdeGetLastError(client_pid
);
545 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_WILDCONNECT
, default_timeout
, &res
);
546 ret
= DdeGetLastError(client_pid
);
547 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
548 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
549 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
552 DdeGetLastError(client_pid
);
553 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_XACT_COMPLETE
, default_timeout
, &res
);
554 ret
= DdeGetLastError(client_pid
);
555 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
556 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
557 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
559 DdeFreeStringHandle(client_pid
, item
);
561 ret
= DdeDisconnect(conversation
);
562 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
564 ret
= DdeUninitialize(client_pid
);
565 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
568 static DWORD server_pid
;
570 static HDDEDATA CALLBACK
server_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
571 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
572 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
574 char str
[MAX_PATH
], *ptr
;
578 static int msg_index
= 0;
579 static HCONV conversation
= 0;
587 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
588 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
589 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
590 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
591 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
592 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
594 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
595 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
596 ok(size
== 13, "Expected 13, got %d\n", size
);
598 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
599 if (!strncmp( str
, "TestDDEServer:(", 15 )) /* win9x style */
601 ok(size
== 16 + 2*sizeof(WORD
), "Got size %d for %s\n", size
, str
);
605 ok(!strncmp(str
, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str
);
606 ok(size
== 17 + 2*sizeof(ULONG_PTR
), "Got size %d for %s\n", size
, str
);
608 ok(str
[size
- 1] == ')', "Expected ')', got %c\n", str
[size
- 1]);
610 return (HDDEDATA
)TRUE
;
615 ok(msg_index
== 2, "Expected 2, got %d\n", msg_index
);
616 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
617 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
618 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
619 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
620 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx\n", dwData2
);
622 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
623 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
624 ok(size
== 12, "Expected 12, got %d\n", size
);
626 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
627 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
628 ok(size
== 13, "Expected 13, got %d\n", size
);
630 return (HDDEDATA
)TRUE
;
633 case XTYP_CONNECT_CONFIRM
:
635 conversation
= hconv
;
637 ok(msg_index
== 3, "Expected 3, got %d\n", msg_index
);
638 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
639 ok(hconv
!= NULL
, "Expected non-NULL hconv\n");
640 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
641 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
642 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx\n", dwData2
);
644 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
645 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
646 ok(size
== 12, "Expected 12, got %d\n", size
);
648 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
649 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
650 ok(size
== 13, "Expected 13, got %d\n", size
);
652 return (HDDEDATA
)TRUE
;
657 ok(msg_index
== 4 || msg_index
== 5 || msg_index
== 6,
658 "Expected 4, 5 or 6, got %d\n", msg_index
);
659 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
660 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
661 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
662 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
665 ok(uFmt
== 0xbeef, "Expected 0xbeef, got %08x\n", uFmt
);
667 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %08x\n", uFmt
);
669 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
670 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
671 ok(size
== 12, "Expected 12, got %d\n", size
);
673 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
678 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
679 ok(size
== 1, "Expected 1, got %d\n", size
);
682 else if (msg_index
== 6)
684 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
685 ok(size
== 7, "Expected 7, got %d\n", size
);
690 lstrcpyA(str
, "requested data\r\n");
691 return DdeCreateDataHandle(server_pid
, (LPBYTE
)str
, lstrlenA(str
) + 1,
692 0, hsz2
, CF_TEXT
, 0);
700 ok(msg_index
== 7 || msg_index
== 8, "Expected 7 or 8, got %d\n", msg_index
);
701 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %d\n", uFmt
);
702 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
703 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
704 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
706 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
707 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
708 ok(size
== 12, "Expected 12, got %d\n", size
);
710 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
711 ok(!lstrcmpA(ptr
, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr
);
712 ok(size
== 12, "Expected 12, got %d\n", size
);
713 DdeUnaccessData(hdata
);
715 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
719 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
720 ok(size
== 1, "Expected 1, got %d\n", size
);
725 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
726 ok(size
== 4, "Expected 4, got %d\n", size
);
729 return (HDDEDATA
)DDE_FACK
;
734 ok(msg_index
>= 9 && msg_index
<= 11, "Expected 9 or 11, got %d\n", msg_index
);
735 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
736 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
737 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
738 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
739 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
741 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
742 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
743 ok(size
== 12, "Expected 12, got %d\n", size
);
745 if (msg_index
== 9 || msg_index
== 11)
747 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
751 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
752 ok(size
== 15, "Expected 15, got %d\n", size
);
753 ret
= (HDDEDATA
)DDE_FACK
;
757 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
758 ok(size
== 18, "Expected 18, got %d\n", size
);
759 ret
= DDE_FNOTPROCESSED
;
762 DdeUnaccessData(hdata
);
764 else if (msg_index
== 10)
769 size
= DdeGetData(hdata
, NULL
, 0, 0);
770 ok(size
== 17, "DdeGetData should have returned 17 not %d\n", size
);
771 ptr
= HeapAlloc(GetProcessHeap(), 0, size
);
772 ok(ptr
!= NULL
,"HeapAlloc should have returned ptr not NULL\n");
773 rsize
= DdeGetData(hdata
, (LPBYTE
)ptr
, size
, 0);
774 ok(rsize
== size
, "DdeGetData did not return %d bytes but %d\n", size
, rsize
);
776 ok(!lstrcmpA(ptr
, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr
);
777 ok(size
== 17, "Expected 17, got %d\n", size
);
778 ret
= (HDDEDATA
)DDE_FACK
;
780 HeapFree(GetProcessHeap(), 0, ptr
);
786 case XTYP_DISCONNECT
:
788 ok(msg_index
== 12, "Expected 12, got %d\n", msg_index
);
789 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
790 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
791 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
792 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
793 ok(hsz1
== 0, "Expected 0, got %p\n", hsz2
);
794 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
800 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
806 static void test_ddeml_server(HANDLE hproc
)
814 /* set up DDE server */
816 res
= DdeInitialize(&server_pid
, server_ddeml_callback
, APPCLASS_STANDARD
, 0);
817 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
819 server
= DdeCreateStringHandle(server_pid
, "TestDDEServer", CP_WINANSI
);
820 ok(server
!= NULL
, "Expected non-NULL string handle\n");
822 hdata
= DdeNameService(server_pid
, server
, 0, DNS_REGISTER
);
823 ok(hdata
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", hdata
);
825 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
827 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
829 ret
= DdeUninitialize(server_pid
);
830 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
831 GetExitCodeProcess( hproc
, &res
);
832 ok( !res
, "client failed with %u error(s)\n", res
);
835 static HWND client_hwnd
, server_hwnd
;
836 static ATOM server
, topic
, item
;
837 static HGLOBAL execute_hglobal
;
839 static LRESULT WINAPI
dde_msg_client_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
848 static int msg_index
= 0;
850 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
851 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
857 case WM_DDE_INITIATE
:
859 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
860 ok(wparam
== (WPARAM
)client_hwnd
, "Expected client hwnd, got %08lx\n", wparam
);
862 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
863 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
864 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
865 ok(size
== 13, "Expected 13, got %d\n", size
);
867 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
868 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
869 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
870 ok(size
== 12, "Expected 12, got %d\n", size
);
877 ok((msg_index
>= 2 && msg_index
<= 4) || (msg_index
>= 6 && msg_index
<= 11),
878 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index
);
882 server_hwnd
= (HWND
)wparam
;
883 ok(wparam
!= 0, "Expected non-NULL wparam, got %08lx\n", wparam
);
885 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
886 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
887 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
888 ok(size
== 13, "Expected 13, got %d\n", size
);
890 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
891 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
892 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
893 ok(size
== 12, "Expected 12, got %d\n", size
);
895 else if (msg_index
>= 9 && msg_index
<= 11)
897 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
899 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
902 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
903 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
904 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
906 ok(hi
== (UINT_PTR
)execute_hglobal
, "Execpted execute hglobal, got %08lx\n", hi
);
907 ptr
= GlobalLock((HGLOBAL
)hi
);
911 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
912 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
913 } else if (msg_index
== 10)
915 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
916 ok(!lstrcmpA(ptr
, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr
);
920 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
921 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
924 GlobalUnlock((HGLOBAL
)hi
);
928 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
930 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
933 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
934 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
935 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
938 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
941 if (msg_index
== 6) todo_wine
942 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
945 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
948 ok(hi
== item
, "Expected item atom, got %08lx\n", hi
);
949 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
950 ok(size
== 7, "Expected 7, got %d\n", size
);
952 else if (msg_index
== 4 || msg_index
== 7)
954 ok(hi
== 0, "Expected 0, got %08lx\n", hi
);
955 ok(size
== 0, "Expected empty string, got %d\n", size
);
959 ok(hi
== item
, "Expected item atom, got %08lx\n", hi
);
960 if (msg_index
== 6) todo_wine
962 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
963 ok(size
== 4, "Expected 4, got %d\n", size
);
973 ok(msg_index
== 5, "Expected 5, got %d\n", msg_index
);
974 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
976 UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
978 data
= GlobalLock((HGLOBAL
)lo
);
979 ok(data
->unused
== 0, "Expected 0, got %d\n", data
->unused
);
980 ok(data
->fResponse
== TRUE
, "Expected TRUE, got %d\n", data
->fResponse
);
983 ok(data
->fRelease
== TRUE
, "Expected TRUE, got %d\n", data
->fRelease
);
985 ok(data
->fAckReq
== 0, "Expected 0, got %d\n", data
->fAckReq
);
986 ok(data
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", data
->cfFormat
);
987 ok(!lstrcmpA((LPSTR
)data
->Value
, "requested data\r\n"),
988 "Expeted 'requested data\\r\\n', got %s\n", data
->Value
);
989 GlobalUnlock((HGLOBAL
)lo
);
991 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
992 ok(hi
== item
, "Expected item atom, got %08x\n", HIWORD(lparam
));
993 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
994 ok(size
== 7, "Expected 7, got %d\n", size
);
996 GlobalFree((HGLOBAL
)lo
);
997 GlobalDeleteAtom(hi
);
1003 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
1006 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1009 static HGLOBAL
create_poke(void)
1015 size
= FIELD_OFFSET(DDEPOKE
, Value
[sizeof("poke data\r\n")]);
1016 hglobal
= GlobalAlloc(GMEM_DDESHARE
, size
);
1017 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
1019 poke
= GlobalLock(hglobal
);
1021 poke
->fRelease
= TRUE
;
1022 poke
->fReserved
= TRUE
;
1023 poke
->cfFormat
= CF_TEXT
;
1024 lstrcpyA((LPSTR
)poke
->Value
, "poke data\r\n");
1025 GlobalUnlock(hglobal
);
1030 static HGLOBAL
create_execute(LPCSTR command
)
1035 hglobal
= GlobalAlloc(GMEM_DDESHARE
, lstrlenA(command
) + 1);
1036 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
1038 ptr
= GlobalLock(hglobal
);
1039 lstrcpyA(ptr
, command
);
1040 GlobalUnlock(hglobal
);
1045 static void test_msg_client(void)
1050 create_dde_window(&client_hwnd
, "dde_client", dde_msg_client_wndproc
);
1052 server
= GlobalAddAtomA("TestDDEServer");
1053 ok(server
!= 0, "Expected non-NULL server\n");
1055 topic
= GlobalAddAtomA("TestDDETopic");
1056 ok(topic
!= 0, "Expected non-NULL topic\n");
1058 SendMessageA(HWND_BROADCAST
, WM_DDE_INITIATE
, (WPARAM
)client_hwnd
, MAKELONG(server
, topic
));
1060 GlobalDeleteAtom(server
);
1061 GlobalDeleteAtom(topic
);
1065 item
= GlobalAddAtom("request");
1066 ok(item
!= 0, "Expected non-NULL item\n");
1068 /* WM_DDE_REQUEST, bad clipboard format */
1069 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xdeadbeef, item
);
1070 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1074 /* WM_DDE_REQUEST, no item */
1075 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, 0);
1076 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1080 /* WM_DDE_REQUEST, no client hwnd */
1081 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1082 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, 0, lparam
);
1086 /* WM_DDE_REQUEST, correct params */
1087 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1088 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1092 GlobalDeleteAtom(item
);
1093 item
= GlobalAddAtomA("poke");
1094 ok(item
!= 0, "Expected non-NULL item\n");
1096 hglobal
= create_poke();
1098 /* WM_DDE_POKE, no ddepoke */
1099 lparam
= PackDDElParam(WM_DDE_POKE
, 0, item
);
1100 /* win9x returns 0 here and crashes in PostMessageA */
1102 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1106 win_skip("no lparam for WM_DDE_POKE\n");
1109 /* WM_DDE_POKE, no item */
1110 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, 0);
1111 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1115 hglobal
= create_poke();
1117 /* WM_DDE_POKE, no client hwnd */
1118 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1119 PostMessageA(server_hwnd
, WM_DDE_POKE
, 0, lparam
);
1123 /* WM_DDE_POKE, all params correct */
1124 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1125 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1129 execute_hglobal
= create_execute("[Command(Var)]");
1131 /* WM_DDE_EXECUTE, no lparam */
1132 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, 0);
1136 /* WM_DDE_EXECUTE, no hglobal */
1137 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, 0);
1138 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1142 /* WM_DDE_EXECUTE, no client hwnd */
1143 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1144 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, 0, lparam
);
1148 /* WM_DDE_EXECUTE, all params correct */
1149 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1150 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1154 GlobalFree(execute_hglobal
);
1155 execute_hglobal
= create_execute("[Command-2(Var)]");
1157 /* WM_DDE_EXECUTE, all params correct */
1158 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1159 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1163 GlobalFree(execute_hglobal
);
1164 execute_hglobal
= create_execute("[BadCommand(Var)]");
1166 /* WM_DDE_EXECUTE that will get rejected */
1167 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1168 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1172 destroy_dde_window(&client_hwnd
, "dde_client");
1175 static LRESULT WINAPI
hook_dde_client_wndprocA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1179 trace("hook_dde_client_wndprocA: %p %04x %08lx %08lx\n", hwnd
, msg
, wparam
, lparam
);
1184 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1185 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo
, (HGLOBAL
)hi
);
1191 return CallWindowProcA(old_dde_client_wndproc
, hwnd
, msg
, wparam
, lparam
);
1194 static LRESULT WINAPI
hook_dde_client_wndprocW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1198 trace("hook_dde_client_wndprocW: %p %04x %08lx %08lx\n", hwnd
, msg
, wparam
, lparam
);
1203 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1204 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo
, (HGLOBAL
)hi
);
1210 return CallWindowProcW(old_dde_client_wndproc
, hwnd
, msg
, wparam
, lparam
);
1213 static LRESULT WINAPI
dde_server_wndprocA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1215 static BOOL client_unicode
, conv_unicode
;
1220 case WM_DDE_INITIATE
:
1222 ATOM aService
= GlobalAddAtomW(TEST_DDE_SERVICE
);
1224 trace("server A: got WM_DDE_INITIATE from %p (%s) with %08lx\n",
1225 (HWND
)wparam
, client_unicode
? "Unicode" : "ANSI", lparam
);
1227 if (LOWORD(lparam
) == aService
)
1229 client_unicode
= IsWindowUnicode((HWND
)wparam
);
1230 conv_unicode
= client_unicode
;
1231 if (step
>= 10) client_unicode
= !client_unicode
; /* change the client window type */
1234 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrW((HWND
)wparam
, GWLP_WNDPROC
,
1235 (ULONG_PTR
)hook_dde_client_wndprocW
);
1237 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrA((HWND
)wparam
, GWLP_WNDPROC
,
1238 (ULONG_PTR
)hook_dde_client_wndprocA
);
1239 trace("server: sending WM_DDE_ACK to %p\n", (HWND
)wparam
);
1240 SendMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, PackDDElParam(WM_DDE_ACK
, aService
, 0));
1243 GlobalDeleteAtom(aService
);
1247 case WM_DDE_EXECUTE
:
1254 trace("server A: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1256 UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1257 trace("%08lx => lo %04lx hi %04lx\n", lparam
, lo
, hi
);
1259 ack
.bAppReturnCode
= 0;
1262 /* We have to send a negative acknowledge even if we don't
1263 * accept the command, otherwise Windows goes mad and next time
1264 * we send an acknowledge DDEML drops the connection.
1265 * Not sure how to call it: a bug or a feature.
1269 if ((cmd
= GlobalLock((HGLOBAL
)hi
)))
1271 ack
.fAck
= !lstrcmpA(cmd
, exec_cmdA
) || !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
);
1275 case 0: /* bad command */
1276 trace( "server A got unhandled command\n" );
1279 case 1: /* ANSI command */
1281 ok( !lstrcmpA(cmd
, exec_cmdA
), "server A got wrong command '%s'\n", cmd
);
1282 else /* we get garbage as the A command was mapped W->A */
1283 ok( cmd
[0] == '?', "server A got wrong command '%s'\n", cmd
);
1286 case 2: /* ANSI command in Unicode format */
1288 ok( !lstrcmpA(cmd
, exec_cmdA
), "server A got wrong command '%s'\n", cmd
);
1290 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server A got wrong command '%s'\n", cmd
);
1293 case 3: /* Unicode command */
1295 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server A got wrong command '%s'\n", cmd
);
1296 else /* correctly mapped W->A */
1297 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server A got wrong command '%s'\n", cmd
);
1300 case 4: /* Unicode command in ANSI format */
1302 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server A got wrong command '%s'\n", cmd
);
1303 else /* we get garbage as the A command was mapped W->A */
1304 ok( cmd
[0] == '?', "server A got wrong command '%s'\n", cmd
);
1307 GlobalUnlock((HGLOBAL
)hi
);
1309 else ok( 0, "bad command data %lx\n", hi
);
1312 trace("server A: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1314 status
= *((WORD
*)&ack
);
1315 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, status
, hi
);
1317 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1321 case WM_DDE_TERMINATE
:
1326 trace("server A: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1328 ack
.bAppReturnCode
= 0;
1333 trace("server A: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1335 status
= *((WORD
*)&ack
);
1336 lparam
= PackDDElParam(WM_DDE_ACK
, status
, 0);
1338 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1346 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1349 static LRESULT WINAPI
dde_server_wndprocW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1351 static BOOL client_unicode
, conv_unicode
;
1356 case WM_DDE_INITIATE
:
1358 ATOM aService
= GlobalAddAtomW(TEST_DDE_SERVICE
);
1360 if (LOWORD(lparam
) == aService
)
1362 client_unicode
= IsWindowUnicode((HWND
)wparam
);
1363 conv_unicode
= client_unicode
;
1364 if (step
>= 10) client_unicode
= !client_unicode
; /* change the client window type */
1367 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrW((HWND
)wparam
, GWLP_WNDPROC
,
1368 (ULONG_PTR
)hook_dde_client_wndprocW
);
1370 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrA((HWND
)wparam
, GWLP_WNDPROC
,
1371 (ULONG_PTR
)hook_dde_client_wndprocA
);
1372 trace("server W: sending WM_DDE_ACK to %p\n", (HWND
)wparam
);
1373 SendMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, PackDDElParam(WM_DDE_ACK
, aService
, 0));
1376 GlobalDeleteAtom(aService
);
1378 trace("server W: got WM_DDE_INITIATE from %p with %08lx (client %s conv %s)\n", (HWND
)wparam
,
1379 lparam
, client_unicode
? "Unicode" : "ANSI", conv_unicode
? "Unicode" : "ANSI" );
1384 case WM_DDE_EXECUTE
:
1391 trace("server W: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1393 UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1394 trace("%08lx => lo %04lx hi %04lx\n", lparam
, lo
, hi
);
1396 ack
.bAppReturnCode
= 0;
1399 /* We have to send a negative acknowledge even if we don't
1400 * accept the command, otherwise Windows goes mad and next time
1401 * we send an acknowledge DDEML drops the connection.
1402 * Not sure how to call it: a bug or a feature.
1406 if ((cmd
= GlobalLock((HGLOBAL
)hi
)))
1408 ack
.fAck
= !lstrcmpA(cmd
, exec_cmdA
) || !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
);
1412 case 0: /* bad command */
1413 trace( "server W got unhandled command\n" );
1416 case 1: /* ANSI command */
1417 if (conv_unicode
&& !client_unicode
) /* W->A mapping -> garbage */
1418 ok( cmd
[0] == '?', "server W got wrong command '%s'\n", cmd
);
1419 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1420 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server W got wrong command '%s'\n", cmd
);
1422 ok( !lstrcmpA(cmd
, exec_cmdA
), "server W got wrong command '%s'\n", cmd
);
1425 case 2: /* ANSI command in Unicode format */
1426 if (conv_unicode
&& !client_unicode
) /* W->A mapping */
1427 ok( !lstrcmpA(cmd
, exec_cmdA
), "server W got wrong command '%s'\n", cmd
);
1428 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1429 ok( *(WCHAR
*)cmd
== exec_cmdAW
[0], "server W got wrong command '%s'\n", cmd
);
1431 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server W got wrong command '%s'\n", cmd
);
1434 case 3: /* Unicode command */
1435 if (conv_unicode
&& !client_unicode
) /* W->A mapping */
1436 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server W got wrong command '%s'\n", cmd
);
1437 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1438 ok( *(WCHAR
*)cmd
== exec_cmdW
[0], "server W got wrong command '%s'\n", cmd
);
1440 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server W got wrong command '%s'\n", cmd
);
1443 case 4: /* Unicode command in ANSI format */
1444 if (conv_unicode
&& !client_unicode
) /* W->A mapping -> garbage */
1445 ok( cmd
[0] == '?', "server W got wrong command '%s'\n", cmd
);
1446 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1447 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server W got wrong command '%s'\n", cmd
);
1449 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server W got wrong command '%s'\n", cmd
);
1452 GlobalUnlock((HGLOBAL
)hi
);
1454 else ok( 0, "bad command data %lx\n", hi
);
1457 trace("server W: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1459 status
= *((WORD
*)&ack
);
1460 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, status
, hi
);
1462 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1466 case WM_DDE_TERMINATE
:
1471 trace("server W: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1473 ack
.bAppReturnCode
= 0;
1478 trace("server W: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1480 status
= *((WORD
*)&ack
);
1481 lparam
= PackDDElParam(WM_DDE_ACK
, status
, 0);
1483 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1491 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
1494 static HWND
create_dde_server( BOOL unicode
)
1499 static const char server_class_nameA
[] = "dde_server_windowA";
1500 static const WCHAR server_class_nameW
[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w','W',0};
1504 memset(&wcW
, 0, sizeof(wcW
));
1505 wcW
.lpfnWndProc
= dde_server_wndprocW
;
1506 wcW
.lpszClassName
= server_class_nameW
;
1507 wcW
.hInstance
= GetModuleHandleA(0);
1508 RegisterClassW(&wcW
);
1510 server
= CreateWindowExW(0, server_class_nameW
, NULL
, WS_POPUP
,
1511 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1512 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
1516 memset(&wcA
, 0, sizeof(wcA
));
1517 wcA
.lpfnWndProc
= dde_server_wndprocA
;
1518 wcA
.lpszClassName
= server_class_nameA
;
1519 wcA
.hInstance
= GetModuleHandleA(0);
1520 RegisterClassA(&wcA
);
1522 server
= CreateWindowExA(0, server_class_nameA
, NULL
, WS_POPUP
,
1523 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1524 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
1526 ok(!IsWindowUnicode(server
) == !unicode
, "wrong unicode type\n");
1530 static HDDEDATA CALLBACK
client_dde_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
1531 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
1532 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
1534 static const char * const cmd_type
[15] = {
1535 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1536 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1537 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1538 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1540 const char *cmd_name
;
1542 type
= (uType
& XTYP_MASK
) >> XTYP_SHIFT
;
1543 cmd_name
= (type
<= 14) ? cmd_type
[type
] : "unknown";
1545 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1546 uType
, cmd_name
, uFmt
, hconv
, hsz1
, hsz2
, hdata
, dwData1
, dwData2
);
1550 static void test_dde_aw_transaction( BOOL client_unicode
, BOOL server_unicode
)
1553 DWORD dde_inst
, ret
, err
;
1558 BOOL conv_unicode
= client_unicode
;
1559 static char test_cmd
[] = "test dde command";
1561 if (!(hwnd_server
= create_dde_server( server_unicode
))) return;
1565 ret
= DdeInitializeW(&dde_inst
, client_dde_callback
, APPCMD_CLIENTONLY
, 0);
1567 ret
= DdeInitializeA(&dde_inst
, client_dde_callback
, APPCMD_CLIENTONLY
, 0);
1568 ok(ret
== DMLERR_NO_ERROR
, "DdeInitializeA failed with error %04x (%x)\n",
1569 ret
, DdeGetLastError(dde_inst
));
1571 hsz_server
= DdeCreateStringHandleW(dde_inst
, TEST_DDE_SERVICE
, CP_WINUNICODE
);
1573 hconv
= DdeConnect(dde_inst
, hsz_server
, 0, NULL
);
1574 ok(hconv
!= 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst
));
1575 err
= DdeGetLastError(dde_inst
);
1576 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1578 info
.cb
= sizeof(info
);
1579 ret
= DdeQueryConvInfo(hconv
, QID_SYNC
, &info
);
1580 ok(ret
, "wrong info size %d, DdeQueryConvInfo error %x\n", ret
, DdeGetLastError(dde_inst
));
1581 ok(info
.ConvCtxt
.iCodePage
== client_unicode
? CP_WINUNICODE
: CP_WINANSI
,
1582 "wrong iCodePage %d\n", info
.ConvCtxt
.iCodePage
);
1583 ok(!info
.hConvPartner
, "unexpected info.hConvPartner: %p\n", info
.hConvPartner
);
1585 ok((info
.wStatus
& DDE_FACK
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1587 ok((info
.wStatus
& (ST_CONNECTED
| ST_CLIENT
)) == (ST_CONNECTED
| ST_CLIENT
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1588 ok(info
.wConvst
== XST_CONNECTED
, "unexpected info.wConvst: %04x\n", info
.wConvst
);
1589 ok(info
.wType
== 0, "unexpected info.wType: %04x\n", info
.wType
);
1591 client_unicode
= IsWindowUnicode( info
.hwnd
);
1592 trace("hwnd %p, hwndPartner %p, unicode %u\n", info
.hwnd
, info
.hwndPartner
, client_unicode
);
1594 trace("sending test client transaction command\n");
1596 hdata
= DdeClientTransaction((LPBYTE
)test_cmd
, strlen(test_cmd
) + 1, hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
1597 ok(!hdata
, "DdeClientTransaction succeeded\n");
1598 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1599 err
= DdeGetLastError(dde_inst
);
1600 ok(err
== DMLERR_NOTPROCESSED
, "wrong dde error %x\n", err
);
1602 trace("sending ANSI client transaction command\n");
1604 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdA
, lstrlenA(exec_cmdA
) + 1, hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1605 err
= DdeGetLastError(dde_inst
);
1606 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> garbage */
1608 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1609 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1610 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1612 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> wrong cmd */
1614 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1615 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1616 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1618 else /* no mapping */
1620 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1621 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1622 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1625 trace("sending ANSI-as-Unicode client transaction command\n");
1627 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdAW
, (lstrlenW(exec_cmdAW
) + 1) * sizeof(WCHAR
),
1628 hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1629 err
= DdeGetLastError(dde_inst
);
1630 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping */
1632 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1633 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1634 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1636 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> garbage */
1638 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1639 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1640 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1642 else /* no mapping */
1644 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1645 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1646 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1649 trace("sending unicode client transaction command\n");
1651 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdW
, (lstrlenW(exec_cmdW
) + 1) * sizeof(WCHAR
), hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1652 err
= DdeGetLastError(dde_inst
);
1653 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> wrong cmd */
1655 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1656 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1657 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1659 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> garbage */
1661 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1662 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1663 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1665 else /* no mapping */
1667 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1668 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1669 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1672 trace("sending Unicode-as-ANSI client transaction command\n");
1674 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdWA
, lstrlenA(exec_cmdWA
) + 1, hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1675 err
= DdeGetLastError(dde_inst
);
1676 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> garbage */
1678 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1679 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1680 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1682 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping */
1684 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1685 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1686 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1688 else /* no mapping */
1690 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1691 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1692 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1695 ok(DdeDisconnect(hconv
), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst
));
1697 info
.cb
= sizeof(info
);
1698 ret
= DdeQueryConvInfo(hconv
, QID_SYNC
, &info
);
1699 ok(!ret
, "DdeQueryConvInfo should fail\n");
1700 err
= DdeGetLastError(dde_inst
);
1702 ok(err
== DMLERR_INVALIDPARAMETER
, "wrong dde error %x\n", err
);
1705 ok(DdeFreeStringHandle(dde_inst
, hsz_server
), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst
));
1707 /* This call hangs on win2k SP4 and XP SP1.
1708 DdeUninitialize(dde_inst);*/
1710 DestroyWindow(hwnd_server
);
1713 static void test_initialisation(void)
1718 HSZ server
, topic
, item
;
1722 /* Initialise without a valid server window. */
1724 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1725 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
1728 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
1729 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
1731 DdeGetLastError(client_pid
);
1733 /* There is no server window so no conversation can be extracted */
1734 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
1735 ok(conversation
== NULL
, "Expected NULL conversation, %p\n", conversation
);
1736 ret
= DdeGetLastError(client_pid
);
1737 ok(ret
== DMLERR_NO_CONV_ESTABLISHED
, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret
);
1739 DdeFreeStringHandle(client_pid
, server
);
1741 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
1743 /* There is no converstation so an invalild parameter results */
1745 DdeGetLastError(client_pid
);
1746 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
1747 ok(hdata
== NULL
, "Expected NULL, got %p\n", hdata
);
1748 ret
= DdeGetLastError(client_pid
);
1750 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
1751 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res
);
1753 DdeFreeStringHandle(client_pid
, server
);
1754 ret
= DdeDisconnect(conversation
);
1755 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1757 ret
= DdeUninitialize(client_pid
);
1758 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1761 static void test_DdeCreateStringHandleW(DWORD dde_inst
, int codepage
)
1763 static const WCHAR dde_string
[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1770 str_handle
= DdeCreateStringHandleW(dde_inst
, dde_string
, codepage
);
1771 ok(str_handle
!= 0, "DdeCreateStringHandleW failed with error %08x\n",
1772 DdeGetLastError(dde_inst
));
1774 ret
= DdeQueryStringW(dde_inst
, str_handle
, NULL
, 0, codepage
);
1775 if (codepage
== CP_WINANSI
)
1776 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1778 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1780 ret
= DdeQueryStringW(dde_inst
, str_handle
, bufW
, 256, codepage
);
1781 if (codepage
== CP_WINANSI
)
1783 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1784 ok(!lstrcmpA("D", (LPCSTR
)bufW
), "DdeQueryStringW returned wrong string\n");
1788 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1789 ok(!lstrcmpW(dde_string
, bufW
), "DdeQueryStringW returned wrong string\n");
1792 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINANSI
);
1793 if (codepage
== CP_WINANSI
)
1795 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1796 ok(!lstrcmpA("D", buf
), "DdeQueryStringW returned wrong string\n");
1800 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1801 ok(!lstrcmpA("DDE String", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1804 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINUNICODE
);
1805 if (codepage
== CP_WINANSI
)
1807 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1808 ok(!lstrcmpA("D", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1812 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1813 ok(!lstrcmpW(dde_string
, (LPCWSTR
)buf
), "DdeQueryStringW returned wrong string\n");
1816 if (codepage
== CP_WINANSI
)
1818 atom
= FindAtomA((LPSTR
)dde_string
);
1819 ok(atom
!= 0, "Expected a valid atom\n");
1821 SetLastError(0xdeadbeef);
1822 atom
= GlobalFindAtomA((LPSTR
)dde_string
);
1823 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1824 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1825 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1829 atom
= FindAtomW(dde_string
);
1830 ok(atom
!= 0, "Expected a valid atom\n");
1832 SetLastError(0xdeadbeef);
1833 atom
= GlobalFindAtomW(dde_string
);
1834 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1835 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1836 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1839 ok(DdeFreeStringHandle(dde_inst
, str_handle
), "DdeFreeStringHandle failed\n");
1842 static void test_DdeCreateDataHandle(void)
1845 DWORD dde_inst
, dde_inst2
;
1851 WCHAR item_str
[] = {'i','t','e','m',0};
1855 res
= DdeInitializeA(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1856 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1858 res
= DdeInitializeA(&dde_inst2
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1859 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1862 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1863 * is invalid then the lastError of all instances is set to the error. There are two instances
1864 * created, lastError is cleared, an error is generated and then both instances are checked to
1865 * ensure that they both have the same error set
1867 item
= DdeCreateStringHandleA(0, "item", CP_WINANSI
);
1868 ok(item
== NULL
, "Expected NULL hsz got %p\n", item
);
1869 err
= DdeGetLastError(dde_inst
);
1870 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1871 err
= DdeGetLastError(dde_inst2
);
1872 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1873 item
= DdeCreateStringHandleW(0, item_str
, CP_WINUNICODE
);
1874 ok(item
== NULL
, "Expected NULL hsz got %p\n", item
);
1875 err
= DdeGetLastError(dde_inst
);
1876 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1877 err
= DdeGetLastError(dde_inst2
);
1878 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1880 item
= DdeCreateStringHandleA(dde_inst
, "item", CP_WINANSI
);
1881 ok(item
!= NULL
, "Expected non-NULL hsz\n");
1882 item
= DdeCreateStringHandleA(dde_inst2
, "item", CP_WINANSI
);
1883 ok(item
!= NULL
, "Expected non-NULL hsz\n");
1886 /* do not test with an invalid instance id: that crashes on win9x */
1887 hdata
= DdeCreateDataHandle(0xdeadbeef, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1891 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1892 * is invalid then the lastError of all instances is set to the error. There are two instances
1893 * created, lastError is cleared, an error is generated and then both instances are checked to
1894 * ensure that they both have the same error set
1896 DdeGetLastError(dde_inst
);
1897 DdeGetLastError(dde_inst2
);
1898 hdata
= DdeCreateDataHandle(0, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1899 err
= DdeGetLastError(dde_inst
);
1900 ok(hdata
== NULL
, "Expected NULL, got %p\n", hdata
);
1901 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1902 err
= DdeGetLastError(dde_inst2
);
1903 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1905 ret
= DdeUninitialize(dde_inst2
);
1906 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1910 DdeGetLastError(dde_inst
);
1911 hdata
= DdeCreateDataHandle(dde_inst
, NULL
, MAX_PATH
, 0, item
, CF_TEXT
, 0);
1912 err
= DdeGetLastError(dde_inst
);
1913 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1914 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1916 ptr
= DdeAccessData(hdata
, &size
);
1917 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1918 ok(size
== 260, "Expected 260, got %d\n", size
);
1920 ret
= DdeUnaccessData(hdata
);
1921 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1923 ret
= DdeFreeDataHandle(hdata
);
1924 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1927 DdeGetLastError(dde_inst
);
1928 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", 0, 0, item
, CF_TEXT
, 0);
1929 err
= DdeGetLastError(dde_inst
);
1930 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1931 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1933 ptr
= DdeAccessData(hdata
, &size
);
1934 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1935 ok(size
== 0, "Expected 0, got %d\n", size
);
1937 ret
= DdeUnaccessData(hdata
);
1938 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1940 ret
= DdeFreeDataHandle(hdata
);
1941 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1943 /* cbOff is non-zero */
1944 DdeGetLastError(dde_inst
);
1945 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 2, item
, CF_TEXT
, 0);
1946 err
= DdeGetLastError(dde_inst
);
1947 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1948 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1950 ptr
= DdeAccessData(hdata
, &size
);
1951 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1952 ok(size
== 262, "Expected 262, got %d\n", size
);
1955 ok(lstrlenA((LPSTR
)ptr
) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR
)ptr
));
1958 ret
= DdeUnaccessData(hdata
);
1959 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1961 ret
= DdeFreeDataHandle(hdata
);
1962 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1965 DdeGetLastError(dde_inst
);
1966 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, 0, CF_TEXT
, 0);
1967 err
= DdeGetLastError(dde_inst
);
1968 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1969 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1971 ptr
= DdeAccessData(hdata
, &size
);
1972 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1973 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1974 ok(size
== 260, "Expected 260, got %d\n", size
);
1976 ret
= DdeUnaccessData(hdata
);
1977 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1979 ret
= DdeFreeDataHandle(hdata
);
1980 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1983 DdeGetLastError(dde_inst
);
1984 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, (HSZ
)0xdeadbeef, CF_TEXT
, 0);
1985 err
= DdeGetLastError(dde_inst
);
1986 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1987 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1989 ptr
= DdeAccessData(hdata
, &size
);
1990 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1991 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1992 ok(size
== 260, "Expected 260, got %d\n", size
);
1994 ret
= DdeUnaccessData(hdata
);
1995 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1997 ret
= DdeFreeDataHandle(hdata
);
1998 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2000 /* invalid clipboard format */
2001 DdeGetLastError(dde_inst
);
2002 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, item
, 0xdeadbeef, 0);
2003 err
= DdeGetLastError(dde_inst
);
2004 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
2005 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
2007 ptr
= DdeAccessData(hdata
, &size
);
2008 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2009 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
2010 ok(size
== 260, "Expected 260, got %d\n", size
);
2012 ret
= DdeUnaccessData(hdata
);
2013 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2015 ret
= DdeFreeDataHandle(hdata
);
2016 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2018 ret
= DdeUninitialize(dde_inst
);
2019 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
2022 static void test_DdeCreateStringHandle(void)
2024 DWORD dde_inst
, ret
;
2026 dde_inst
= 0xdeadbeef;
2027 SetLastError(0xdeadbeef);
2028 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2029 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
2031 win_skip("DdeInitializeW is unimplemented\n");
2035 ok(ret
== DMLERR_INVALIDPARAMETER
, "DdeInitializeW should fail, but got %04x instead\n", ret
);
2036 ok(DdeGetLastError(dde_inst
) == DMLERR_INVALIDPARAMETER
, "expected DMLERR_INVALIDPARAMETER\n");
2039 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2040 ok(ret
== DMLERR_NO_ERROR
, "DdeInitializeW failed with error %04x (%08x)\n",
2041 ret
, DdeGetLastError(dde_inst
));
2043 test_DdeCreateStringHandleW(dde_inst
, 0);
2044 test_DdeCreateStringHandleW(dde_inst
, CP_WINUNICODE
);
2045 test_DdeCreateStringHandleW(dde_inst
, CP_WINANSI
);
2047 ok(DdeUninitialize(dde_inst
), "DdeUninitialize failed\n");
2050 static void test_FreeDDElParam(void)
2052 HGLOBAL val
, hglobal
;
2055 ret
= FreeDDElParam(WM_DDE_INITIATE
, 0);
2056 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2058 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2059 ret
= FreeDDElParam(WM_DDE_INITIATE
, (LPARAM
)hglobal
);
2060 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2061 val
= GlobalFree(hglobal
);
2062 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2064 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2065 ret
= FreeDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
);
2066 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2068 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2069 ret
= FreeDDElParam(WM_DDE_UNADVISE
, (LPARAM
)hglobal
);
2070 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2071 val
= GlobalFree(hglobal
);
2072 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2074 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2075 ret
= FreeDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
);
2076 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2078 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2079 ret
= FreeDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
);
2080 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2082 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2083 ret
= FreeDDElParam(WM_DDE_REQUEST
, (LPARAM
)hglobal
);
2084 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2085 val
= GlobalFree(hglobal
);
2086 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2088 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2089 ret
= FreeDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
);
2090 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2092 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2093 ret
= FreeDDElParam(WM_DDE_EXECUTE
, (LPARAM
)hglobal
);
2094 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2095 val
= GlobalFree(hglobal
);
2096 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2099 static void test_PackDDElParam(void)
2101 UINT_PTR lo
, hi
, *ptr
;
2105 lparam
= PackDDElParam(WM_DDE_INITIATE
, 0xcafe, 0xbeef);
2106 /* value gets sign-extended despite being an LPARAM */
2107 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2110 ret
= UnpackDDElParam(WM_DDE_INITIATE
, lparam
, &lo
, &hi
);
2111 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2112 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2113 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2115 ret
= FreeDDElParam(WM_DDE_INITIATE
, lparam
);
2116 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2118 lparam
= PackDDElParam(WM_DDE_TERMINATE
, 0xcafe, 0xbeef);
2119 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2122 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, lparam
, &lo
, &hi
);
2123 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2124 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2125 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2127 ret
= FreeDDElParam(WM_DDE_TERMINATE
, lparam
);
2128 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2130 lparam
= PackDDElParam(WM_DDE_ADVISE
, 0xcafe, 0xbeef);
2131 /* win9x returns 0 here */
2133 ptr
= GlobalLock((HGLOBAL
)lparam
);
2134 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2135 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2136 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2138 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2139 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2142 ret
= UnpackDDElParam(WM_DDE_ADVISE
, lparam
, &lo
, &hi
);
2143 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2144 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2145 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2148 win_skip("no lparam for WM_DDE_ADVISE\n");
2150 ret
= FreeDDElParam(WM_DDE_ADVISE
, lparam
);
2151 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2153 lparam
= PackDDElParam(WM_DDE_UNADVISE
, 0xcafe, 0xbeef);
2154 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2157 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, lparam
, &lo
, &hi
);
2158 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2159 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2160 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2162 ret
= FreeDDElParam(WM_DDE_UNADVISE
, lparam
);
2163 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2165 lparam
= PackDDElParam(WM_DDE_ACK
, 0xcafe, 0xbeef);
2166 /* win9x returns the input (0xbeef<<16 | 0xcafe) here */
2167 if (lparam
!= (int)0xbeefcafe) {
2168 ptr
= GlobalLock((HGLOBAL
)lparam
);
2169 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2170 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2171 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2173 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2174 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2177 ret
= UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
2178 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2179 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2180 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2182 ret
= FreeDDElParam(WM_DDE_ACK
, lparam
);
2183 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2186 win_skip("got lparam 0x%lx for WM_DDE_ACK\n", lparam
);
2188 lparam
= PackDDElParam(WM_DDE_DATA
, 0xcafe, 0xbeef);
2189 /* win9x returns 0 here */
2191 ptr
= GlobalLock((HGLOBAL
)lparam
);
2192 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2193 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2194 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2196 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2197 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2200 ret
= UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
2201 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2202 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2203 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2206 win_skip("no lparam for WM_DDE_DATA\n");
2208 ret
= FreeDDElParam(WM_DDE_DATA
, lparam
);
2209 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2211 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xcafe, 0xbeef);
2212 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2215 ret
= UnpackDDElParam(WM_DDE_REQUEST
, lparam
, &lo
, &hi
);
2216 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2217 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2218 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2220 ret
= FreeDDElParam(WM_DDE_REQUEST
, lparam
);
2221 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2223 lparam
= PackDDElParam(WM_DDE_POKE
, 0xcafe, 0xbeef);
2224 /* win9x returns 0 here */
2226 ptr
= GlobalLock((HGLOBAL
)lparam
);
2227 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2228 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2229 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2231 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2232 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2235 ret
= UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
2236 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2237 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2238 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2241 win_skip("no lparam for WM_DDE_POKE\n");
2243 ret
= FreeDDElParam(WM_DDE_POKE
, lparam
);
2244 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2246 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0xcafe, 0xbeef);
2247 ok(lparam
== 0xbeef, "Expected 0xbeef, got %08lx\n", lparam
);
2250 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
2251 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2252 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2253 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2255 ret
= FreeDDElParam(WM_DDE_EXECUTE
, lparam
);
2256 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2259 static void test_UnpackDDElParam(void)
2261 UINT_PTR lo
, hi
, *ptr
;
2268 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0, &lo
, &hi
);
2269 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2270 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2271 ok(hi
== 0, "Expected 0, got %08lx\n", hi
);
2276 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, NULL
, &hi
);
2277 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2278 ok(lo
== 0xdead, "Expected 0xdead, got %08lx\n", lo
);
2279 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2284 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, NULL
);
2285 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2286 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2287 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2291 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, &hi
);
2292 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2293 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2294 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2298 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, 0xcafebabe, &lo
, &hi
);
2299 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2300 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2301 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2305 ret
= UnpackDDElParam(WM_DDE_ADVISE
, 0, &lo
, &hi
);
2306 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2308 broken(lo
== 0xdead), /* win2k */
2309 "Expected 0, got %08lx\n", lo
);
2311 broken(hi
== 0xbeef), /* win2k */
2312 "Expected 0, got %08lx\n", hi
);
2314 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 2 * sizeof(*ptr
));
2315 ptr
= GlobalLock(hglobal
);
2316 ptr
[0] = 0xcafebabe;
2317 ptr
[1] = 0xdeadbeef;
2318 GlobalUnlock(hglobal
);
2322 ret
= UnpackDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
, &lo
, &hi
);
2323 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2324 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2325 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2329 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, 0xcafebabe, &lo
, &hi
);
2330 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2331 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2332 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2336 ret
= UnpackDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
, &lo
, &hi
);
2337 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2338 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2339 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2343 ret
= UnpackDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
, &lo
, &hi
);
2344 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2345 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2346 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2350 ret
= UnpackDDElParam(WM_DDE_REQUEST
, 0xcafebabe, &lo
, &hi
);
2351 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2352 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2353 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2357 ret
= UnpackDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
, &lo
, &hi
);
2358 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2359 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2360 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2364 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, 0xcafebabe, &lo
, &hi
);
2365 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2366 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2367 ok(hi
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi
);
2369 GlobalFree(hglobal
);
2372 static HDDEDATA CALLBACK
server_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2373 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2374 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2378 static int msg_index
= 0;
2379 static HCONV conversation
= 0;
2380 static char test_cmd_w_to_a
[] = "test dde command";
2381 static char test_cmd_a_to_a
[] = "Test dde command";
2382 static WCHAR test_cmd_w_to_w
[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2383 static WCHAR test_cmd_a_to_w
[] = {'T','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2384 static char test_service
[] = "TestDDEService";
2385 static char test_topic
[] = "TestDDETopic";
2393 ok(msg_index
== 1 || msg_index
== 7 || msg_index
== 13 || msg_index
== 19,
2394 "Expected 1, 7, 13 or 19, got %d\n", msg_index
);
2395 return (HDDEDATA
)TRUE
;
2400 ok(msg_index
== 2 || msg_index
== 8 || msg_index
== 14 || msg_index
== 20,
2401 "Expected 2, 8, 14 or 20, got %d\n", msg_index
);
2402 ok(uFmt
== 0, "Expected 0, got %d, msg_index=%d\n", uFmt
, msg_index
);
2403 ok(hconv
== 0, "Expected 0, got %p, msg_index=%d\n", hconv
, msg_index
);
2404 ok(hdata
== 0, "Expected 0, got %p, msg_index=%d\n", hdata
, msg_index
);
2405 ok(dwData1
!= 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1
, msg_index
);
2406 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2
, msg_index
);
2408 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2409 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2410 test_topic
, str
, msg_index
);
2411 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2413 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
2414 ok(!lstrcmpA(str
, test_service
), "Expected %s, got %s, msg_index=%d\n",
2415 test_service
, str
, msg_index
);
2416 ok(size
== 14, "Expected 14, got %d, msg_index=%d\n", size
, msg_index
);
2418 return (HDDEDATA
) TRUE
;
2420 case XTYP_CONNECT_CONFIRM
:
2422 ok(msg_index
== 3 || msg_index
== 9 || msg_index
== 15 || msg_index
== 21,
2423 "Expected 3, 9, 15 or 21 got %d\n", msg_index
);
2424 conversation
= hconv
;
2425 return (HDDEDATA
) TRUE
;
2429 BYTE
*buffer
= NULL
;
2431 ok(msg_index
== 4 || msg_index
== 5 || msg_index
== 10 || msg_index
== 11 ||
2432 msg_index
== 16 || msg_index
== 17 || msg_index
== 22 || msg_index
== 23,
2433 "Expected 4, 5, 10, 11, 16, 17, 22 or 23, got %d\n", msg_index
);
2434 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
2435 ok(hconv
== conversation
, "Expected conversation handle, got %p, msg_index=%d\n",
2437 ok(dwData1
== 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1
, msg_index
);
2438 ok(dwData2
== 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2
, msg_index
);
2439 ok(hsz2
== 0, "Expected 0, got %p, msg_index=%d\n", hsz2
, msg_index
);
2440 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2441 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2442 test_topic
, str
, msg_index
);
2443 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2444 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2446 size
= DdeGetData(hdata
, NULL
, 0, 0);
2447 if (msg_index
== 10 || msg_index
==11 || msg_index
== 16 || msg_index
==17)
2448 if (msg_index
== 10 || msg_index
== 16)
2450 ok(size
== 34, "Expected that size should be 34 not %d, msg_index=%d\n",
2453 ok(size
== 34, "Expected that size should be 34 not %d, msg_index=%d\n",
2457 ok(size
== 8 || size
== 9, "Expected that size should be 8 or 9 not %d, msg_index=%d\n",
2462 ok(size
== 17, "Expected that size should be 17 not %d, msg_index=%d\n",
2465 ok(size
== 17, "Expected that size should be 17 not %d, msg_index=%d\n",
2467 ok((buffer
= HeapAlloc(GetProcessHeap(), 0, size
)) != NULL
, "should not be null\n");
2468 rsize
= DdeGetData(hdata
, buffer
, size
, 0);
2469 if (msg_index
== 10 || msg_index
== 11 || msg_index
== 16 || msg_index
==17)
2471 ok(rsize
== size
, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2472 size
, rsize
, msg_index
);
2473 if (msg_index
== 10 || msg_index
== 16)
2475 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_a_to_w
),
2476 "Expected \"Test dde command\", msg_index=%d\n",
2478 ok(size
== 34, "Expected 34, got %d, msg_index=%d\n", size
, msg_index
);
2481 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_w_to_w
),
2482 "Expected \"test dde command\", msg_index=%d\n",
2484 ok(size
== 34, "Expected 34, got %d, msg_index=%d\n", size
, msg_index
);
2486 }else if (msg_index
== 22)
2488 ok(rsize
== size
, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2489 size
, rsize
, msg_index
);
2492 ok(rsize
== size
, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2493 size
, rsize
, msg_index
);
2496 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2497 test_cmd_w_to_a
, buffer
, msg_index
);
2498 ok(size
== 17, "Expected size should be 17, got %d, msg_index=%d\n", size
, msg_index
);
2500 else if (msg_index
== 23)
2502 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2503 test_cmd_w_to_a
, buffer
, msg_index
);
2504 ok(size
== 17, "Expected size should be 17, got %d, msg_index=%d\n", size
, msg_index
);
2508 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_a_to_a
), "Expected %s, got %s, msg_index=%d\n",
2509 test_cmd_a_to_a
, buffer
, msg_index
);
2510 ok(size
== 17, "Expected size should be 17, got %d, msg_index=%d\n", size
, msg_index
);
2515 return (HDDEDATA
) DDE_FACK
;
2517 case XTYP_DISCONNECT
:
2518 return (HDDEDATA
) TRUE
;
2521 ok(FALSE
, "Unhandled msg: %08x, msg_index=%d\n", uType
, msg_index
);
2527 static HDDEDATA CALLBACK
client_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2528 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2529 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2533 case XTYP_DISCONNECT
:
2534 return (HDDEDATA
) TRUE
;
2537 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
2543 static void test_end_to_end_client(BOOL type_a
)
2546 DWORD client_pid
= 0;
2550 static char test_cmd
[] = "Test dde command";
2551 static WCHAR test_cmd_w
[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2552 static char test_service
[] = "TestDDEService";
2553 static WCHAR test_service_w
[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2554 static char test_topic
[] = "TestDDETopic";
2555 static WCHAR test_topic_w
[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2557 trace("Start end to end client %s\n", type_a
? "ASCII" : "UNICODE");
2560 ret
= DdeInitializeA(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2562 ret
= DdeInitializeW(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2563 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %x\n", ret
);
2567 server
= DdeCreateStringHandleA(client_pid
, test_service
, CP_WINANSI
);
2568 topic
= DdeCreateStringHandleA(client_pid
, test_topic
, CP_WINANSI
);
2571 server
= DdeCreateStringHandleW(client_pid
, test_service_w
, CP_WINUNICODE
);
2572 topic
= DdeCreateStringHandleW(client_pid
, test_topic_w
, CP_WINUNICODE
);
2575 DdeGetLastError(client_pid
);
2576 hconv
= DdeConnect(client_pid
, server
, topic
, NULL
);
2577 ok(hconv
!= NULL
, "Expected non-NULL conversation\n");
2578 ret
= DdeGetLastError(client_pid
);
2579 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %x\n", ret
);
2580 DdeFreeStringHandle(client_pid
, server
);
2582 /* Test both A and W data being passed to DdeClientTransaction */
2583 hdata
= DdeClientTransaction((LPBYTE
)test_cmd
, strlen(test_cmd
) + 1,
2584 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2585 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2586 ok(ret
== DDE_FACK
, "wrong status code %x\n", ret
);
2587 err
= DdeGetLastError(client_pid
);
2588 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
2590 hdata
= DdeClientTransaction((LPBYTE
)test_cmd_w
, lstrlenW(test_cmd_w
) * sizeof(WCHAR
) + 2,
2591 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2592 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2593 ok(ret
== DDE_FACK
, "wrong status code %x\n", ret
);
2594 err
= DdeGetLastError(client_pid
);
2595 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
2597 DdeFreeStringHandle(client_pid
, topic
);
2598 ret
= DdeDisconnect(hconv
);
2599 ok(ret
== TRUE
, "Expected TRUE, got %x\n", ret
);
2601 ret
= DdeUninitialize(client_pid
);
2602 ok(ret
== TRUE
, "Expected TRUE, got %x\n", ret
);
2606 static void test_end_to_end_server(HANDLE hproc
, HANDLE hthread
, BOOL type_a
)
2613 static CHAR test_service
[] = "TestDDEService";
2615 trace("start end to end server %s\n", type_a
? "ASCII" : "UNICODE");
2619 res
= DdeInitializeA(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2621 res
= DdeInitializeW(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2622 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
2624 server
= DdeCreateStringHandleA(server_pid
, test_service
, CP_WINANSI
);
2625 ok(server
!= NULL
, "Expected non-NULL string handle\n");
2627 hdata
= DdeNameService(server_pid
, server
, 0, DNS_REGISTER
);
2628 ok(hdata
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", hdata
);
2629 ResumeThread( hthread
);
2632 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
2634 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2637 ret
= DdeUninitialize(server_pid
);
2638 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2639 GetExitCodeProcess( hproc
, &res
);
2640 ok( !res
, "client failed with %u error(s)\n", res
);
2647 char buffer
[MAX_PATH
];
2648 STARTUPINFO startup
;
2649 PROCESS_INFORMATION proc
;
2651 argc
= winetest_get_mainargs(&argv
);
2654 if (!lstrcmpA(argv
[2], "ddeml"))
2655 test_ddeml_client();
2656 else if (!lstrcmpA(argv
[2], "msg"))
2658 else if (!lstrcmpA(argv
[2], "enda"))
2659 test_end_to_end_client(TRUE
);
2660 else if (!lstrcmpA(argv
[2], "endw"))
2661 test_end_to_end_client(FALSE
);
2666 test_initialisation();
2668 ZeroMemory(&startup
, sizeof(STARTUPINFO
));
2669 sprintf(buffer
, "%s dde ddeml", argv
[0]);
2670 startup
.cb
= sizeof(startup
);
2671 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
2672 startup
.wShowWindow
= SW_SHOWNORMAL
;
2674 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2675 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2677 test_msg_server(proc
.hProcess
, proc
.hThread
);
2679 sprintf(buffer
, "%s dde msg", argv
[0]);
2680 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2681 0, NULL
, NULL
, &startup
, &proc
);
2683 test_ddeml_server(proc
.hProcess
);
2685 /* Test the combinations of A and W interfaces with A and W data
2686 end to end to ensure that data conversions are accurate */
2687 sprintf(buffer
, "%s dde enda", argv
[0]);
2688 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2689 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2691 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, TRUE
);
2693 /* Don't bother testing W interfaces on Win9x/WinMe */
2694 SetLastError(0xdeadbeef);
2695 lstrcmpW(NULL
, NULL
);
2696 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
2698 win_skip("Skipping W-interface tests\n");
2702 sprintf(buffer
, "%s dde endw", argv
[0]);
2703 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2704 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2706 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, FALSE
);
2708 sprintf(buffer
, "%s dde enda", argv
[0]);
2709 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2710 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2712 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, FALSE
);
2714 sprintf(buffer
, "%s dde endw", argv
[0]);
2715 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2716 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2718 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, TRUE
);
2720 test_dde_aw_transaction( FALSE
, TRUE
);
2721 test_dde_aw_transaction( TRUE
, FALSE
);
2722 test_dde_aw_transaction( TRUE
, TRUE
);
2723 test_dde_aw_transaction( FALSE
, FALSE
);
2725 test_dde_aw_transaction( FALSE
, TRUE
);
2726 test_dde_aw_transaction( TRUE
, FALSE
);
2727 test_dde_aw_transaction( TRUE
, TRUE
);
2729 test_dde_aw_transaction( FALSE
, FALSE
);
2731 test_DdeCreateDataHandle();
2732 test_DdeCreateStringHandle();
2733 test_FreeDDElParam();
2734 test_PackDDElParam();
2735 test_UnpackDDElParam();