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 HANDLE
create_process(const char *arg
)
48 STARTUPINFOA si
= {.cb
= sizeof(si
)};
49 PROCESS_INFORMATION pi
;
54 winetest_get_mainargs(&argv
);
55 sprintf(cmdline
, "\"%s\" %s %s", argv
[0], argv
[1], arg
);
56 ret
= CreateProcessA(argv
[0], cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
57 ok(ret
, "CreateProcess failed: %lu\n", GetLastError());
58 CloseHandle(pi
.hThread
);
62 static BOOL
is_cjk(void)
64 int lang_id
= PRIMARYLANGID(GetUserDefaultLangID());
66 if (lang_id
== LANG_CHINESE
|| lang_id
== LANG_JAPANESE
|| lang_id
== LANG_KOREAN
)
71 static void flush_events(void)
74 int diff
= default_timeout
;
76 DWORD time
= GetTickCount() + diff
;
80 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
81 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
82 diff
= time
- GetTickCount();
87 static void create_dde_window(HWND
*hwnd
, LPCSTR name
, WNDPROC wndproc
)
92 memset(&wcA
, 0, sizeof(wcA
));
93 wcA
.lpfnWndProc
= wndproc
;
94 wcA
.lpszClassName
= name
;
95 wcA
.hInstance
= GetModuleHandleA(0);
96 aclass
= RegisterClassA(&wcA
);
97 ok (aclass
, "RegisterClass failed\n");
99 *hwnd
= CreateWindowExA(0, name
, NULL
, WS_POPUP
,
100 500, 500, CW_USEDEFAULT
, CW_USEDEFAULT
,
101 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
102 ok(*hwnd
!= NULL
, "CreateWindowExA failed\n");
105 static void destroy_dde_window(HWND
*hwnd
, LPCSTR name
)
107 DestroyWindow(*hwnd
);
108 UnregisterClassA(name
, GetModuleHandleA(NULL
));
111 static LRESULT WINAPI
dde_server_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
114 char str
[MAX_PATH
], *ptr
;
120 static int msg_index
= 0;
121 static HWND client
= 0;
122 static BOOL executed
= FALSE
;
124 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
125 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
131 case WM_DDE_INITIATE
:
133 client
= (HWND
)wparam
;
134 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
136 GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
137 ok(!lstrcmpA(str
, "TestDDEService"), "Expected TestDDEService, got %s\n", str
);
139 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
140 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
142 SendMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
149 ok((msg_index
>= 2 && msg_index
<= 4) ||
150 (msg_index
>= 7 && msg_index
<= 8),
151 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index
);
152 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08Ix\n", wparam
);
153 ok(LOWORD(lparam
) == CF_TEXT
, "Expected CF_TEXT, got %d\n", LOWORD(lparam
));
155 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
157 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
159 ok(!lstrcmpA(str
, "executed"), "Expected executed, got %s\n", str
);
164 lstrcpyA(str
, "command executed\r\n");
166 lstrcpyA(str
, "command not executed\r\n");
169 lstrcpyA(str
, "requested data\r\n");
171 size
= FIELD_OFFSET(DDEDATA
, Value
[lstrlenA(str
) + 1]);
172 hglobal
= GlobalAlloc(GMEM_MOVEABLE
, size
);
173 ok(hglobal
!= NULL
, "Expected non-NULL hglobal\n");
175 data
= GlobalLock(hglobal
);
176 ZeroMemory(data
, size
);
178 /* setting fResponse to FALSE at this point destroys
179 * the internal messaging state of native dde
181 data
->fResponse
= TRUE
;
184 data
->fRelease
= TRUE
;
185 else if (msg_index
== 3)
186 data
->fAckReq
= TRUE
;
188 data
->cfFormat
= CF_TEXT
;
189 lstrcpyA((LPSTR
)data
->Value
, str
);
190 GlobalUnlock(hglobal
);
192 lparam
= PackDDElParam(WM_DDE_DATA
, (UINT_PTR
)hglobal
, HIWORD(lparam
));
193 PostMessageA(client
, WM_DDE_DATA
, (WPARAM
)hwnd
, lparam
);
200 ok(msg_index
== 5 || msg_index
== 6, "Expected 5 or 6, got %d\n", msg_index
);
201 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08Ix\n", wparam
);
203 UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
205 GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
206 ok(!lstrcmpA(str
, "poker"), "Expected poker, got %s\n", str
);
208 poke
= GlobalLock((HGLOBAL
)lo
);
209 ok(poke
!= NULL
, "Expected non-NULL poke\n");
210 ok(poke
->fReserved
== 0, "Expected 0, got %d\n", poke
->fReserved
);
211 ok(poke
->unused
== 0, "Expected 0, got %d\n", poke
->unused
);
212 ok(poke
->fRelease
== TRUE
, "Expected TRUE, got %d\n", poke
->fRelease
);
213 ok(poke
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", poke
->cfFormat
);
217 size
= GlobalSize((HGLOBAL
)lo
);
218 ok(size
== 4, "got %ld\n", size
);
221 ok(!lstrcmpA((LPSTR
)poke
->Value
, "poke data\r\n"),
222 "Expected 'poke data\\r\\n', got %s\n", poke
->Value
);
224 GlobalUnlock((HGLOBAL
)lo
);
226 lparam
= PackDDElParam(WM_DDE_ACK
, DDE_FACK
, hi
);
227 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
234 ok(msg_index
== 7, "Expected 7, got %d\n", msg_index
);
235 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08Ix\n", wparam
);
237 ptr
= GlobalLock((HGLOBAL
)lparam
);
238 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr
);
239 GlobalUnlock((HGLOBAL
)lparam
);
243 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, DDE_FACK
, lparam
);
244 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
249 case WM_DDE_TERMINATE
:
251 ok(msg_index
== 9, "Expected 9, got %d\n", msg_index
);
252 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08Ix\n", wparam
);
253 ok(lparam
== 0, "Expected 0, got %08Ix\n", lparam
);
255 PostMessageA(client
, WM_DDE_TERMINATE
, (WPARAM
)hwnd
, 0);
261 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
264 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
267 static void test_msg_server(void)
274 create_dde_window(&hwnd
, "dde_server", dde_server_wndproc
);
275 client
= create_process("ddeml");
277 while (MsgWaitForMultipleObjects(1, &client
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
279 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
282 destroy_dde_window(&hwnd
, "dde_server");
283 GetExitCodeProcess(client
, &res
);
284 ok( !res
, "client failed with %lu error(s)\n", res
);
288 static HDDEDATA CALLBACK
client_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
289 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
290 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
292 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
296 static void test_ddeml_client(void)
303 HSZ server
, topic
, item
;
308 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
309 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
311 /* FIXME: make these atoms global and check them in the server */
313 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
314 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
316 DdeGetLastError(client_pid
);
317 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
318 if (broken(!conversation
)) /* Windows 10 version 1607 */
320 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(client_pid
));
321 DdeUninitialize(client_pid
);
324 ret
= DdeGetLastError(client_pid
);
325 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
327 DdeFreeStringHandle(client_pid
, server
);
329 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
331 /* XTYP_REQUEST, fRelease = TRUE */
333 DdeGetLastError(client_pid
);
334 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
335 ret
= DdeGetLastError(client_pid
);
336 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
337 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %08lx\n", res
);
338 ok( hdata
!= NULL
, "hdata is NULL\n" );
341 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
342 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
343 ok(size
== 17, "Expected 17, got %ld\n", size
);
345 ret
= DdeUnaccessData(hdata
);
346 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
349 /* XTYP_REQUEST, fAckReq = TRUE */
351 DdeGetLastError(client_pid
);
352 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
353 ret
= DdeGetLastError(client_pid
);
354 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %lx\n", res
);
356 ok(ret
== DMLERR_MEMORY_ERROR
, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
357 ok( hdata
!= NULL
, "hdata is NULL\n" );
360 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
361 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
362 ok(size
== 17, "Expected 17, got %ld\n", size
);
364 ret
= DdeUnaccessData(hdata
);
365 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
368 /* XTYP_REQUEST, all params normal */
370 DdeGetLastError(client_pid
);
371 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
372 ret
= DdeGetLastError(client_pid
);
373 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
374 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %lx\n", res
);
376 ok(FALSE
, "hdata is NULL\n");
379 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
380 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
381 ok(size
== 17, "Expected 17, got %ld\n", size
);
383 ret
= DdeUnaccessData(hdata
);
384 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
387 /* XTYP_REQUEST, no item */
389 DdeGetLastError(client_pid
);
390 hdata
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
391 ret
= DdeGetLastError(client_pid
);
392 ok(hdata
== NULL
, "Expected NULL hdata, got %p\n", hdata
);
393 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", res
);
394 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
396 DdeFreeStringHandle(client_pid
, item
);
398 item
= DdeCreateStringHandleA(client_pid
, "poker", CP_WINANSI
);
400 lstrcpyA(buffer
, "poke data\r\n");
401 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
402 0, item
, CF_TEXT
, 0);
403 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
405 /* XTYP_POKE, no item */
407 DdeGetLastError(client_pid
);
408 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
409 ret
= DdeGetLastError(client_pid
);
410 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
411 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", res
);
412 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
414 /* XTYP_POKE, no data */
416 DdeGetLastError(client_pid
);
417 op
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
418 ret
= DdeGetLastError(client_pid
);
419 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
420 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", res
);
421 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
423 /* XTYP_POKE, wrong size */
425 DdeGetLastError(client_pid
);
426 op
= DdeClientTransaction((LPBYTE
)hdata
, 0, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
427 ret
= DdeGetLastError(client_pid
);
428 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
429 ok(res
== DDE_FACK
, "Expected DDE_FACK, got %lx\n", res
);
430 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
432 /* XTYP_POKE, correct params */
434 DdeGetLastError(client_pid
);
435 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
436 ret
= DdeGetLastError(client_pid
);
437 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
438 ok(res
== DDE_FACK
, "Expected DDE_FACK, got %lx\n", res
);
439 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
441 DdeFreeDataHandle(hdata
);
443 lstrcpyA(buffer
, "[Command(Var)]");
444 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
445 0, NULL
, CF_TEXT
, 0);
446 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
448 /* XTYP_EXECUTE, correct params */
450 DdeGetLastError(client_pid
);
451 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
452 ret
= DdeGetLastError(client_pid
);
453 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
454 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
455 ok(res
== DDE_FACK
, "Expected DDE_FACK, got %lx\n", res
);
457 /* XTYP_EXECUTE, no data */
459 DdeGetLastError(client_pid
);
460 op
= DdeClientTransaction(NULL
, 0, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
461 ret
= DdeGetLastError(client_pid
);
462 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
463 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", res
);
464 ok(ret
== DMLERR_MEMORY_ERROR
, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
466 /* XTYP_EXECUTE, no data, -1 size */
468 DdeGetLastError(client_pid
);
469 op
= DdeClientTransaction(NULL
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
470 ret
= DdeGetLastError(client_pid
);
471 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
472 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", res
);
473 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
475 DdeFreeStringHandle(client_pid
, topic
);
476 DdeFreeDataHandle(hdata
);
478 item
= DdeCreateStringHandleA(client_pid
, "executed", CP_WINANSI
);
480 /* verify the execute */
482 DdeGetLastError(client_pid
);
483 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
484 ret
= DdeGetLastError(client_pid
);
485 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
486 ok(res
== DDE_FNOTPROCESSED
, "Expected DDE_FNOTPROCESSED, got %ld\n", res
);
487 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
488 ok(!strcmp(str
, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str
);
489 ok(size
== 19, "Expected 19, got %ld\n", size
);
491 ret
= DdeUnaccessData(hdata
);
492 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
494 /* invalid transactions */
496 DdeGetLastError(client_pid
);
497 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_ADVREQ
, 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 %ld\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_CONNECT
, 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 %ld\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_CONNECT_CONFIRM
, 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 %ld\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_DISCONNECT
, 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 %ld\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_ERROR
, 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 %ld\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_MONITOR
, 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 %ld\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_REGISTER
, 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 %ld\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_UNREGISTER
, 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 %ld\n", res
);
557 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
560 DdeGetLastError(client_pid
);
561 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_WILDCONNECT
, default_timeout
, &res
);
562 ret
= DdeGetLastError(client_pid
);
563 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
564 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", res
);
565 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
568 DdeGetLastError(client_pid
);
569 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_XACT_COMPLETE
, default_timeout
, &res
);
570 ret
= DdeGetLastError(client_pid
);
571 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
572 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", res
);
573 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
575 DdeFreeStringHandle(client_pid
, item
);
577 ret
= DdeDisconnect(conversation
);
578 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
580 ret
= DdeUninitialize(client_pid
);
581 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
584 static DWORD server_pid
;
586 static HDDEDATA CALLBACK
server_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
587 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
588 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
590 char str
[MAX_PATH
], *ptr
;
594 static int msg_index
= 0;
595 static HCONV conversation
= 0;
603 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
604 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
605 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
606 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
607 ok(dwData1
== 0, "Expected 0, got %08Ix\n", dwData1
);
608 ok(dwData2
== 0, "Expected 0, got %08Ix\n", dwData2
);
610 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
611 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
612 ok(size
== 13, "Expected 13, got %ld\n", size
);
614 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
615 ok(!strncmp(str
, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str
);
616 ok(size
== 17 + 2*sizeof(ULONG_PTR
), "Got size %ld for %s\n", size
, str
);
617 ok(str
[size
- 1] == ')', "Expected ')', got %c\n", str
[size
- 1]);
619 return (HDDEDATA
)TRUE
;
624 ok(msg_index
== 2, "Expected 2, got %d\n", msg_index
);
625 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
626 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
627 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
628 ok(dwData1
== 0, "Expected 0, got %08Ix\n", dwData1
);
629 ok(dwData2
== FALSE
, "Expected FALSE, got %08Ix\n", dwData2
);
631 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
632 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
633 ok(size
== 12, "Expected 12, got %ld\n", size
);
635 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
636 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
637 ok(size
== 13, "Expected 13, got %ld\n", size
);
639 return (HDDEDATA
)TRUE
;
642 case XTYP_CONNECT_CONFIRM
:
644 conversation
= hconv
;
646 ok(msg_index
== 3, "Expected 3, got %d\n", msg_index
);
647 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
648 ok(hconv
!= NULL
, "Expected non-NULL hconv\n");
649 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
650 ok(dwData1
== 0, "Expected 0, got %08Ix\n", dwData1
);
651 ok(dwData2
== FALSE
, "Expected FALSE, got %08Ix\n", dwData2
);
653 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
654 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
655 ok(size
== 12, "Expected 12, got %ld\n", size
);
657 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
658 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
659 ok(size
== 13, "Expected 13, got %ld\n", size
);
661 return (HDDEDATA
)TRUE
;
666 ok(msg_index
== 4 || msg_index
== 5 || msg_index
== 6,
667 "Expected 4, 5 or 6, got %d\n", msg_index
);
668 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
669 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
670 ok(dwData1
== 0, "Expected 0, got %08Ix\n", dwData1
);
671 ok(dwData2
== 0, "Expected 0, got %08Ix\n", dwData2
);
674 ok(uFmt
== 0xbeef, "Expected 0xbeef, got %08x\n", uFmt
);
676 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %08x\n", uFmt
);
678 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
679 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
680 ok(size
== 12, "Expected 12, got %ld\n", size
);
682 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
687 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
688 ok(size
== 1, "Expected 1, got %ld\n", size
);
691 else if (msg_index
== 6)
693 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
694 ok(size
== 7, "Expected 7, got %ld\n", size
);
699 lstrcpyA(str
, "requested data\r\n");
700 return DdeCreateDataHandle(server_pid
, (LPBYTE
)str
, lstrlenA(str
) + 1,
701 0, hsz2
, CF_TEXT
, 0);
709 ok(msg_index
== 7 || msg_index
== 8, "Expected 7 or 8, got %d\n", msg_index
);
710 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %d\n", uFmt
);
711 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
712 ok(dwData1
== 0, "Expected 0, got %08Ix\n", dwData1
);
713 ok(dwData2
== 0, "Expected 0, got %08Ix\n", dwData2
);
715 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
716 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
717 ok(size
== 12, "Expected 12, got %ld\n", size
);
719 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
720 ok(!lstrcmpA(ptr
, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr
);
721 ok(size
== 12, "Expected 12, got %ld\n", size
);
722 DdeUnaccessData(hdata
);
724 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
728 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
729 ok(size
== 1, "Expected 1, got %ld\n", size
);
734 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
735 ok(size
== 4, "Expected 4, got %ld\n", size
);
738 return (HDDEDATA
)DDE_FACK
;
743 ok(msg_index
>= 9 && msg_index
<= 11, "Expected 9 or 11, got %d\n", msg_index
);
744 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
745 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
746 ok(dwData1
== 0, "Expected 0, got %08Ix\n", dwData1
);
747 ok(dwData2
== 0, "Expected 0, got %08Ix\n", dwData2
);
748 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
750 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
751 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
752 ok(size
== 12, "Expected 12, got %ld\n", size
);
754 if (msg_index
== 9 || msg_index
== 11)
756 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
760 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
761 ok(size
== 15, "Expected 15, got %ld\n", size
);
762 ret
= (HDDEDATA
)DDE_FACK
;
766 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
767 ok(size
== 18, "Expected 18, got %ld\n", size
);
768 ret
= DDE_FNOTPROCESSED
;
771 DdeUnaccessData(hdata
);
773 else if (msg_index
== 10)
777 size
= DdeGetData(hdata
, NULL
, 0, 0);
778 ok(size
== 17, "DdeGetData should have returned 17 not %ld\n", size
);
780 ok(ptr
!= NULL
, "malloc should have returned ptr not NULL\n");
781 rsize
= DdeGetData(hdata
, (LPBYTE
)ptr
, size
, 0);
782 ok(rsize
== size
, "DdeGetData did not return %ld bytes but %ld\n", size
, rsize
);
784 ok(!lstrcmpA(ptr
, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr
);
785 ok(size
== 17, "Expected 17, got %ld\n", size
);
786 ret
= (HDDEDATA
)DDE_FACK
;
794 case XTYP_DISCONNECT
:
796 ok(msg_index
== 12, "Expected 12, got %d\n", msg_index
);
797 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
798 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
799 ok(dwData1
== 0, "Expected 0, got %08Ix\n", dwData1
);
800 ok(dwData2
== 0, "Expected 0, got %08Ix\n", dwData2
);
801 ok(hsz1
== 0, "Expected 0, got %p\n", hsz2
);
802 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
808 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
814 static void test_ddeml_server(void)
824 client
= create_process("msg");
826 /* set up DDE server */
828 res
= DdeInitializeA(&server_pid
, server_ddeml_callback
, APPCLASS_STANDARD
, 0);
829 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
831 server
= DdeCreateStringHandleA(server_pid
, "TestDDEServer", CP_WINANSI
);
832 ok(server
!= NULL
, "Expected non-NULL string handle\n");
834 hdata
= DdeNameService(server_pid
, server
, 0, DNS_REGISTER
);
835 ok(hdata
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", hdata
);
837 while (MsgWaitForMultipleObjects(1, &client
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
839 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
841 ret
= DdeUninitialize(server_pid
);
842 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
843 GetExitCodeProcess(client
, &exit_code
);
844 ok( !res
, "client failed with %lu error(s)\n", exit_code
);
848 static HWND client_hwnd
, server_hwnd
;
849 static ATOM server
, topic
, item
;
850 static HGLOBAL execute_hglobal
;
852 static LRESULT WINAPI
dde_msg_client_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
861 static int msg_index
= 0;
863 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
864 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
870 case WM_DDE_INITIATE
:
872 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
873 ok(wparam
== (WPARAM
)client_hwnd
, "Expected client hwnd, got %08Ix\n", wparam
);
875 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
876 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
877 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
878 ok(size
== 13, "Expected 13, got %ld\n", size
);
880 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
881 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
882 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
883 ok(size
== 12, "Expected 12, got %ld\n", size
);
890 ok((msg_index
>= 2 && msg_index
<= 4) || (msg_index
>= 6 && msg_index
<= 11),
891 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index
);
895 server_hwnd
= (HWND
)wparam
;
896 ok(wparam
!= 0, "Expected non-NULL wparam, got %08Ix\n", wparam
);
898 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
899 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
900 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
901 ok(size
== 13, "Expected 13, got %ld\n", size
);
903 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
904 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
905 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
906 ok(size
== 12, "Expected 12, got %ld\n", size
);
908 else if (msg_index
>= 9 && msg_index
<= 11)
910 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08Ix\n", wparam
);
912 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
915 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
916 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
917 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
919 ok(hi
== (UINT_PTR
)execute_hglobal
, "Expected execute hglobal, got %08Ix\n", hi
);
920 ptr
= GlobalLock((HGLOBAL
)hi
);
924 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
925 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
926 } else if (msg_index
== 10)
928 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
929 ok(!lstrcmpA(ptr
, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr
);
933 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
934 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
937 GlobalUnlock((HGLOBAL
)hi
);
941 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08Ix\n", wparam
);
943 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
946 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
947 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
948 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
951 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
954 if (msg_index
== 6) todo_wine
955 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
958 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
961 ok(hi
== item
, "Expected item atom, got %08Ix\n", hi
);
962 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
963 ok(size
== 7, "Expected 7, got %ld\n", size
);
965 else if (msg_index
== 4 || msg_index
== 7)
967 ok(hi
== 0, "Expected 0, got %08Ix\n", hi
);
968 ok(size
== 0, "Expected empty string, got %ld\n", size
);
972 ok(hi
== item
, "Expected item atom, got %08Ix\n", hi
);
973 if (msg_index
== 6) todo_wine
975 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
976 ok(size
== 4, "Expected 4, got %ld\n", size
);
986 ok(msg_index
== 5, "Expected 5, got %d\n", msg_index
);
987 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08Ix\n", wparam
);
989 UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
991 data
= GlobalLock((HGLOBAL
)lo
);
992 ok(data
->unused
== 0, "Expected 0, got %d\n", data
->unused
);
993 ok(data
->fResponse
== TRUE
, "Expected TRUE, got %d\n", data
->fResponse
);
996 ok(data
->fRelease
== TRUE
, "Expected TRUE, got %d\n", data
->fRelease
);
998 ok(data
->fAckReq
== 0, "Expected 0, got %d\n", data
->fAckReq
);
999 ok(data
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", data
->cfFormat
);
1000 ok(!lstrcmpA((LPSTR
)data
->Value
, "requested data\r\n"),
1001 "Expected 'requested data\\r\\n', got %s\n", data
->Value
);
1002 GlobalUnlock((HGLOBAL
)lo
);
1004 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
1005 ok(hi
== item
, "Expected item atom, got %08x\n", HIWORD(lparam
));
1006 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
1007 ok(size
== 7, "Expected 7, got %ld\n", size
);
1009 GlobalFree((HGLOBAL
)lo
);
1010 GlobalDeleteAtom(hi
);
1016 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
1019 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1022 static HGLOBAL
create_poke(void)
1028 size
= FIELD_OFFSET(DDEPOKE
, Value
[sizeof("poke data\r\n")]);
1029 hglobal
= GlobalAlloc(GMEM_DDESHARE
, size
);
1030 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
1032 poke
= GlobalLock(hglobal
);
1034 poke
->fRelease
= TRUE
;
1035 poke
->fReserved
= TRUE
;
1036 poke
->cfFormat
= CF_TEXT
;
1037 lstrcpyA((LPSTR
)poke
->Value
, "poke data\r\n");
1038 GlobalUnlock(hglobal
);
1043 static HGLOBAL
create_execute(LPCSTR command
)
1048 hglobal
= GlobalAlloc(GMEM_DDESHARE
, lstrlenA(command
) + 1);
1049 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
1051 ptr
= GlobalLock(hglobal
);
1052 lstrcpyA(ptr
, command
);
1053 GlobalUnlock(hglobal
);
1058 static void test_msg_client(void)
1063 create_dde_window(&client_hwnd
, "dde_client", dde_msg_client_wndproc
);
1065 server
= GlobalAddAtomA("TestDDEServer");
1066 ok(server
!= 0, "Expected non-NULL server\n");
1068 topic
= GlobalAddAtomA("TestDDETopic");
1069 ok(topic
!= 0, "Expected non-NULL topic\n");
1071 SendMessageA(HWND_BROADCAST
, WM_DDE_INITIATE
, (WPARAM
)client_hwnd
, MAKELONG(server
, topic
));
1073 GlobalDeleteAtom(server
);
1074 GlobalDeleteAtom(topic
);
1078 item
= GlobalAddAtomA("request");
1079 ok(item
!= 0, "Expected non-NULL item\n");
1081 /* WM_DDE_REQUEST, bad clipboard format */
1082 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xdeadbeef, item
);
1083 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1087 /* WM_DDE_REQUEST, no item */
1088 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, 0);
1089 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1093 /* WM_DDE_REQUEST, no client hwnd */
1094 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1095 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, 0, lparam
);
1099 /* WM_DDE_REQUEST, correct params */
1100 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1101 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1105 GlobalDeleteAtom(item
);
1106 item
= GlobalAddAtomA("poke");
1107 ok(item
!= 0, "Expected non-NULL item\n");
1109 hglobal
= create_poke();
1111 /* WM_DDE_POKE, no ddepoke */
1112 lparam
= PackDDElParam(WM_DDE_POKE
, 0, item
);
1113 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1116 /* WM_DDE_POKE, no item */
1117 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, 0);
1118 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1122 hglobal
= create_poke();
1124 /* WM_DDE_POKE, no client hwnd */
1125 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1126 PostMessageA(server_hwnd
, WM_DDE_POKE
, 0, lparam
);
1130 /* WM_DDE_POKE, all params correct */
1131 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1132 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1136 execute_hglobal
= create_execute("[Command(Var)]");
1138 /* WM_DDE_EXECUTE, no lparam */
1139 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, 0);
1143 /* WM_DDE_EXECUTE, no hglobal */
1144 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, 0);
1145 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1149 /* WM_DDE_EXECUTE, no client hwnd */
1150 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1151 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, 0, lparam
);
1155 /* WM_DDE_EXECUTE, all params correct */
1156 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1157 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1161 GlobalFree(execute_hglobal
);
1162 execute_hglobal
= create_execute("[Command-2(Var)]");
1164 /* WM_DDE_EXECUTE, all params correct */
1165 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1166 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1170 GlobalFree(execute_hglobal
);
1171 execute_hglobal
= create_execute("[BadCommand(Var)]");
1173 /* WM_DDE_EXECUTE that will get rejected */
1174 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1175 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1179 destroy_dde_window(&client_hwnd
, "dde_client");
1182 static LRESULT WINAPI
hook_dde_client_wndprocA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1186 if (winetest_debug
> 1) trace("hook_dde_client_wndprocA: %p %04x %08Ix %08Ix\n", hwnd
, msg
, wparam
, lparam
);
1191 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1192 if (winetest_debug
> 1) trace("WM_DDE_ACK: status %04Ix hglobal %p\n", lo
, (HGLOBAL
)hi
);
1198 return CallWindowProcA(old_dde_client_wndproc
, hwnd
, msg
, wparam
, lparam
);
1201 static LRESULT WINAPI
hook_dde_client_wndprocW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1205 if (winetest_debug
> 1) trace("hook_dde_client_wndprocW: %p %04x %08Ix %08Ix\n", hwnd
, msg
, wparam
, lparam
);
1210 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1211 if (winetest_debug
> 1) trace("WM_DDE_ACK: status %04Ix hglobal %p\n", lo
, (HGLOBAL
)hi
);
1217 return CallWindowProcW(old_dde_client_wndproc
, hwnd
, msg
, wparam
, lparam
);
1220 static LRESULT WINAPI
dde_server_wndprocA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1222 static BOOL client_unicode
, conv_unicode
;
1227 case WM_DDE_INITIATE
:
1229 ATOM aService
= GlobalAddAtomW(TEST_DDE_SERVICE
);
1231 if (winetest_debug
> 1) trace("server A: got WM_DDE_INITIATE from %p (%s) with %08Ix\n",
1232 (HWND
)wparam
, client_unicode
? "Unicode" : "ANSI", lparam
);
1234 if (LOWORD(lparam
) == aService
)
1236 client_unicode
= IsWindowUnicode((HWND
)wparam
);
1237 conv_unicode
= client_unicode
;
1238 if (step
>= 10) client_unicode
= !client_unicode
; /* change the client window type */
1241 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrW((HWND
)wparam
, GWLP_WNDPROC
,
1242 (ULONG_PTR
)hook_dde_client_wndprocW
);
1244 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrA((HWND
)wparam
, GWLP_WNDPROC
,
1245 (ULONG_PTR
)hook_dde_client_wndprocA
);
1246 SendMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, PackDDElParam(WM_DDE_ACK
, aService
, 0));
1249 GlobalDeleteAtom(aService
);
1253 case WM_DDE_EXECUTE
:
1260 if (winetest_debug
> 1) trace("server A: got WM_DDE_EXECUTE from %p with %08Ix\n", (HWND
)wparam
, lparam
);
1262 UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1263 if (winetest_debug
> 1) trace("%08Ix => lo %04Ix hi %04Ix\n", lparam
, lo
, hi
);
1265 ack
.bAppReturnCode
= 0;
1268 /* We have to send a negative acknowledge even if we don't
1269 * accept the command, otherwise Windows goes mad and next time
1270 * we send an acknowledge DDEML drops the connection.
1271 * Not sure how to call it: a bug or a feature.
1275 if ((cmd
= GlobalLock((HGLOBAL
)hi
)))
1277 ack
.fAck
= !lstrcmpA(cmd
, exec_cmdA
) || !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
);
1281 case 0: /* bad command */
1284 case 1: /* ANSI command */
1286 ok( !lstrcmpA(cmd
, exec_cmdA
), "server A got wrong command '%s'\n", cmd
);
1287 else /* we get garbage as the A command was mapped W->A */
1288 ok( cmd
[0] != exec_cmdA
[0], "server A got wrong command '%s'\n", cmd
);
1291 case 2: /* ANSI command in Unicode format */
1293 ok( !lstrcmpA(cmd
, exec_cmdA
), "server A got wrong command '%s'\n", cmd
);
1295 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server A got wrong command '%s'\n", cmd
);
1298 case 3: /* Unicode command */
1300 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server A got wrong command '%s'\n", cmd
);
1301 else /* correctly mapped W->A */
1302 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server A got wrong command '%s'\n", cmd
);
1305 case 4: /* Unicode command in ANSI format */
1307 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server A got wrong command '%s'\n", cmd
);
1308 else /* we get garbage as the A command was mapped W->A */
1309 ok( cmd
[0] != exec_cmdWA
[0], "server A got wrong command '%s'\n", cmd
);
1312 GlobalUnlock((HGLOBAL
)hi
);
1314 else ok( 0, "bad command data %Ix\n", hi
);
1318 status
= *((WORD
*)&ack
);
1319 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, status
, hi
);
1321 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1325 case WM_DDE_TERMINATE
:
1330 if (winetest_debug
> 1) trace("server A: got WM_DDE_TERMINATE from %#Ix with %08Ix\n", wparam
, lparam
);
1332 ack
.bAppReturnCode
= 0;
1337 status
= *((WORD
*)&ack
);
1338 lparam
= PackDDElParam(WM_DDE_ACK
, status
, 0);
1340 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1348 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1351 static LRESULT WINAPI
dde_server_wndprocW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1353 static BOOL client_unicode
, conv_unicode
;
1358 case WM_DDE_INITIATE
:
1360 ATOM aService
= GlobalAddAtomW(TEST_DDE_SERVICE
);
1362 if (LOWORD(lparam
) == aService
)
1364 client_unicode
= IsWindowUnicode((HWND
)wparam
);
1365 conv_unicode
= client_unicode
;
1366 if (step
>= 10) client_unicode
= !client_unicode
; /* change the client window type */
1369 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrW((HWND
)wparam
, GWLP_WNDPROC
,
1370 (ULONG_PTR
)hook_dde_client_wndprocW
);
1372 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrA((HWND
)wparam
, GWLP_WNDPROC
,
1373 (ULONG_PTR
)hook_dde_client_wndprocA
);
1374 SendMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, PackDDElParam(WM_DDE_ACK
, aService
, 0));
1377 GlobalDeleteAtom(aService
);
1379 if (winetest_debug
> 1)
1380 trace("server W: got WM_DDE_INITIATE from %p with %08Ix (client %s conv %s)\n", (HWND
)wparam
,
1381 lparam
, client_unicode
? "Unicode" : "ANSI", conv_unicode
? "Unicode" : "ANSI" );
1386 case WM_DDE_EXECUTE
:
1393 if (winetest_debug
> 1) trace("server W: got WM_DDE_EXECUTE from %#Ix with %08Ix\n", wparam
, lparam
);
1395 UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1396 if (winetest_debug
> 1) trace("%08Ix => lo %04Ix hi %04Ix\n", lparam
, lo
, hi
);
1398 ack
.bAppReturnCode
= 0;
1401 /* We have to send a negative acknowledge even if we don't
1402 * accept the command, otherwise Windows goes mad and next time
1403 * we send an acknowledge DDEML drops the connection.
1404 * Not sure how to call it: a bug or a feature.
1408 if ((cmd
= GlobalLock((HGLOBAL
)hi
)))
1410 ack
.fAck
= !lstrcmpA(cmd
, exec_cmdA
) || !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
);
1414 case 0: /* bad command */
1417 case 1: /* ANSI command */
1418 if (conv_unicode
&& !client_unicode
) /* W->A mapping -> garbage */
1419 ok( cmd
[0] != exec_cmdA
[0], "server W got wrong command '%s'\n", cmd
);
1420 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1421 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server W got wrong command '%s'\n", cmd
);
1423 ok( !lstrcmpA(cmd
, exec_cmdA
), "server W got wrong command '%s'\n", cmd
);
1426 case 2: /* ANSI command in Unicode format */
1427 if (conv_unicode
&& !client_unicode
) /* W->A mapping */
1428 ok( !lstrcmpA(cmd
, exec_cmdA
), "server W got wrong command '%s'\n", cmd
);
1429 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1430 ok( *(WCHAR
*)cmd
== exec_cmdAW
[0], "server W got wrong command '%s'\n", cmd
);
1432 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server W got wrong command '%s'\n", cmd
);
1435 case 3: /* Unicode command */
1436 if (conv_unicode
&& !client_unicode
) /* W->A mapping */
1437 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server W got wrong command '%s'\n", cmd
);
1438 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1439 ok( *(WCHAR
*)cmd
== exec_cmdW
[0], "server W got wrong command '%s'\n", cmd
);
1441 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server W got wrong command '%s'\n", cmd
);
1444 case 4: /* Unicode command in ANSI format */
1445 if (conv_unicode
&& !client_unicode
) /* W->A mapping -> garbage */
1446 ok( cmd
[0] != exec_cmdWA
[0], "server W got wrong command '%s'\n", cmd
);
1447 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1448 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server W got wrong command '%s'\n", cmd
);
1450 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server W got wrong command '%s'\n", cmd
);
1453 GlobalUnlock((HGLOBAL
)hi
);
1455 else ok( 0, "bad command data %Ix\n", hi
);
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 if (winetest_debug
> 1) trace("server W: got WM_DDE_TERMINATE from %#Ix with %08Ix\n", wparam
, lparam
);
1473 ack
.bAppReturnCode
= 0;
1478 status
= *((WORD
*)&ack
);
1479 lparam
= PackDDElParam(WM_DDE_ACK
, status
, 0);
1481 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1489 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
1492 static HWND
create_dde_server( BOOL unicode
)
1497 static const char server_class_nameA
[] = "dde_server_windowA";
1498 static const WCHAR server_class_nameW
[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w','W',0};
1502 memset(&wcW
, 0, sizeof(wcW
));
1503 wcW
.lpfnWndProc
= dde_server_wndprocW
;
1504 wcW
.lpszClassName
= server_class_nameW
;
1505 wcW
.hInstance
= GetModuleHandleA(0);
1506 RegisterClassW(&wcW
);
1508 server
= CreateWindowExW(0, server_class_nameW
, NULL
, WS_POPUP
,
1509 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1510 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
1514 memset(&wcA
, 0, sizeof(wcA
));
1515 wcA
.lpfnWndProc
= dde_server_wndprocA
;
1516 wcA
.lpszClassName
= server_class_nameA
;
1517 wcA
.hInstance
= GetModuleHandleA(0);
1518 RegisterClassA(&wcA
);
1520 server
= CreateWindowExA(0, server_class_nameA
, NULL
, WS_POPUP
,
1521 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1522 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
1524 ok(!IsWindowUnicode(server
) == !unicode
, "wrong unicode type\n");
1528 static HDDEDATA CALLBACK
client_dde_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
1529 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
1530 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
1532 static const char * const cmd_type
[15] = {
1533 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1534 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1535 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1536 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1538 const char *cmd_name
;
1540 type
= (uType
& XTYP_MASK
) >> XTYP_SHIFT
;
1541 cmd_name
= (type
<= 14) ? cmd_type
[type
] : "unknown";
1543 if (winetest_debug
> 1)
1544 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08Ix %08Ix\n",
1545 uType
, cmd_name
, uFmt
, hconv
, hsz1
, hsz2
, hdata
, dwData1
, dwData2
);
1549 static void test_dde_aw_transaction( BOOL client_unicode
, BOOL server_unicode
)
1552 DWORD dde_inst
, ret
, err
;
1557 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 %04lx (%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 if (broken(!hconv
)) /* Windows 10 version 1607 */
1576 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(dde_inst
));
1577 DdeUninitialize(dde_inst
);
1580 err
= DdeGetLastError(dde_inst
);
1581 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %lx\n", err
);
1583 info
.cb
= sizeof(info
);
1584 ret
= DdeQueryConvInfo(hconv
, QID_SYNC
, &info
);
1585 ok(ret
, "wrong info size %ld, DdeQueryConvInfo error %x\n", ret
, DdeGetLastError(dde_inst
));
1586 ok(info
.ConvCtxt
.iCodePage
== (client_unicode
? CP_WINUNICODE
: CP_WINANSI
),
1587 "wrong iCodePage %d\n", info
.ConvCtxt
.iCodePage
);
1588 ok(!info
.hConvPartner
, "unexpected info.hConvPartner: %p\n", info
.hConvPartner
);
1590 ok((info
.wStatus
& DDE_FACK
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1592 ok((info
.wStatus
& (ST_CONNECTED
| ST_CLIENT
)) == (ST_CONNECTED
| ST_CLIENT
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1593 ok(info
.wConvst
== XST_CONNECTED
, "unexpected info.wConvst: %04x\n", info
.wConvst
);
1594 ok(info
.wType
== 0, "unexpected info.wType: %04x\n", info
.wType
);
1596 client_unicode
= IsWindowUnicode( info
.hwnd
);
1599 hdata
= DdeClientTransaction((LPBYTE
)test_cmd
, strlen(test_cmd
) + 1, hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
1600 ok(!hdata
, "DdeClientTransaction succeeded\n");
1601 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1602 err
= DdeGetLastError(dde_inst
);
1603 ok(err
== DMLERR_NOTPROCESSED
, "wrong dde error %lx\n", err
);
1606 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdA
, lstrlenA(exec_cmdA
) + 1, hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1607 err
= DdeGetLastError(dde_inst
);
1608 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> garbage */
1610 ok(!hdata
, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1611 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1612 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
1614 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> wrong cmd */
1616 ok(!hdata
, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1617 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1618 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
1620 else /* no mapping */
1622 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1623 ok(ret
== DDE_FACK
, "wrong status code %04lx\n", ret
);
1624 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %lx\n", err
);
1628 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdAW
, (lstrlenW(exec_cmdAW
) + 1) * sizeof(WCHAR
),
1629 hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1630 err
= DdeGetLastError(dde_inst
);
1631 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping */
1633 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1634 ok(ret
== DDE_FACK
, "wrong status code %04lx\n", ret
);
1635 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %lx\n", err
);
1637 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> garbage */
1639 ok(!hdata
, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1640 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1641 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
1643 else /* no mapping */
1645 ok(!hdata
, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1646 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1647 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
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 %lx\n", hdata
, err
);
1656 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1657 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
1659 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> garbage */
1661 ok(!hdata
, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1662 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1663 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
1665 else /* no mapping */
1667 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1668 ok(ret
== DDE_FACK
, "wrong status code %04lx\n", ret
);
1669 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %lx\n", err
);
1673 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdWA
, lstrlenA(exec_cmdWA
) + 1, hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1674 err
= DdeGetLastError(dde_inst
);
1675 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> garbage */
1677 ok(!hdata
, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1678 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1679 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
1681 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping */
1683 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1684 ok(ret
== DDE_FACK
, "wrong status code %04lx\n", ret
);
1685 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %lx\n", err
);
1687 else /* no mapping */
1689 ok(!hdata
, "DdeClientTransaction returned %p, error %lx\n", hdata
, err
);
1690 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04lx\n", ret
);
1691 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %lx\n", err
);
1694 got
= DdeDisconnect(hconv
);
1695 ok(got
, "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 %lx\n", err
);
1705 got
= DdeFreeStringHandle(dde_inst
, hsz_server
);
1706 ok(got
, "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst
));
1708 /* This call hangs on win2k SP4 and XP SP1.
1709 DdeUninitialize(dde_inst);*/
1711 DestroyWindow(hwnd_server
);
1714 static void test_initialisation(void)
1719 HSZ server
, topic
, item
;
1723 /* Initialise without a valid server window. */
1725 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1726 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
1729 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
1730 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
1732 DdeGetLastError(client_pid
);
1734 /* There is no server window so no conversation can be extracted */
1735 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
1736 ok(conversation
== NULL
, "Expected NULL conversation, %p\n", conversation
);
1737 ret
= DdeGetLastError(client_pid
);
1738 ok(ret
== DMLERR_NO_CONV_ESTABLISHED
, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret
);
1740 DdeFreeStringHandle(client_pid
, server
);
1742 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
1744 /* There is no conversation so an invalid parameter results */
1746 DdeGetLastError(client_pid
);
1747 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
1748 ok(hdata
== NULL
, "Expected NULL, got %p\n", hdata
);
1749 ret
= DdeGetLastError(client_pid
);
1751 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
1752 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", res
);
1754 DdeFreeStringHandle(client_pid
, server
);
1755 ret
= DdeDisconnect(conversation
);
1756 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1758 ret
= DdeUninitialize(client_pid
);
1759 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1762 static void test_DdeCreateStringHandleW(DWORD dde_inst
, int codepage
)
1764 static const WCHAR dde_string
[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1771 str_handle
= DdeCreateStringHandleW(dde_inst
, dde_string
, codepage
);
1772 ok(str_handle
!= 0, "DdeCreateStringHandleW failed with error %08x\n",
1773 DdeGetLastError(dde_inst
));
1775 ret
= DdeQueryStringW(dde_inst
, str_handle
, NULL
, 0, codepage
);
1776 if (codepage
== CP_WINANSI
)
1777 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1779 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1781 ret
= DdeQueryStringW(dde_inst
, str_handle
, bufW
, 256, codepage
);
1782 if (codepage
== CP_WINANSI
)
1784 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1785 ok(!lstrcmpA("D", (LPCSTR
)bufW
), "DdeQueryStringW returned wrong string\n");
1789 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1790 ok(!lstrcmpW(dde_string
, bufW
), "DdeQueryStringW returned wrong string\n");
1793 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINANSI
);
1794 if (codepage
== CP_WINANSI
)
1796 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1797 ok(!lstrcmpA("D", buf
), "DdeQueryStringW returned wrong string\n");
1801 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1802 ok(!lstrcmpA("DDE String", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1805 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINUNICODE
);
1806 if (codepage
== CP_WINANSI
)
1808 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1809 ok(!lstrcmpA("D", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1813 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1814 ok(!lstrcmpW(dde_string
, (LPCWSTR
)buf
), "DdeQueryStringW returned wrong string\n");
1817 if (codepage
== CP_WINANSI
)
1819 atom
= FindAtomA((LPSTR
)dde_string
);
1820 ok(atom
!= 0, "Expected a valid atom\n");
1822 SetLastError(0xdeadbeef);
1823 atom
= GlobalFindAtomA((LPSTR
)dde_string
);
1824 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1825 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1826 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
1830 atom
= FindAtomW(dde_string
);
1831 ok(atom
!= 0, "Expected a valid atom\n");
1833 SetLastError(0xdeadbeef);
1834 atom
= GlobalFindAtomW(dde_string
);
1835 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1836 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1837 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
1840 ok(DdeFreeStringHandle(dde_inst
, str_handle
), "DdeFreeStringHandle failed\n");
1843 static void test_DdeCreateDataHandle(void)
1846 DWORD dde_inst
, dde_inst2
;
1852 WCHAR item_str
[] = {'i','t','e','m',0};
1856 res
= DdeInitializeA(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1857 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1859 res
= DdeInitializeA(&dde_inst2
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1860 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1863 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1864 * is invalid then the lastError of all instances is set to the error. There are two instances
1865 * created, lastError is cleared, an error is generated and then both instances are checked to
1866 * ensure that they both have the same error set
1868 item
= DdeCreateStringHandleA(0, "item", CP_WINANSI
);
1869 ok(item
== NULL
, "Expected NULL hsz got %p\n", item
);
1870 err
= DdeGetLastError(dde_inst
);
1871 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1872 err
= DdeGetLastError(dde_inst2
);
1873 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1874 item
= DdeCreateStringHandleW(0, item_str
, CP_WINUNICODE
);
1875 ok(item
== NULL
, "Expected NULL hsz got %p\n", item
);
1876 err
= DdeGetLastError(dde_inst
);
1877 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1878 err
= DdeGetLastError(dde_inst2
);
1879 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1881 item
= DdeCreateStringHandleA(dde_inst
, "item", CP_WINANSI
);
1882 ok(item
!= NULL
, "Expected non-NULL hsz\n");
1883 item
= DdeCreateStringHandleA(dde_inst2
, "item", CP_WINANSI
);
1884 ok(item
!= NULL
, "Expected non-NULL hsz\n");
1886 hdata
= DdeCreateDataHandle(0xdeadbeef, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1889 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1890 * is invalid then the lastError of all instances is set to the error. There are two instances
1891 * created, lastError is cleared, an error is generated and then both instances are checked to
1892 * ensure that they both have the same error set
1894 DdeGetLastError(dde_inst
);
1895 DdeGetLastError(dde_inst2
);
1896 hdata
= DdeCreateDataHandle(0, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1897 err
= DdeGetLastError(dde_inst
);
1898 ok(hdata
== NULL
, "Expected NULL, got %p\n", hdata
);
1899 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1900 err
= DdeGetLastError(dde_inst2
);
1901 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1903 ret
= DdeUninitialize(dde_inst2
);
1904 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1908 DdeGetLastError(dde_inst
);
1909 hdata
= DdeCreateDataHandle(dde_inst
, NULL
, MAX_PATH
, 0, item
, CF_TEXT
, 0);
1910 err
= DdeGetLastError(dde_inst
);
1911 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1912 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1914 ptr
= DdeAccessData(hdata
, &size
);
1915 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1916 ok(size
== 260, "Expected 260, got %ld\n", size
);
1918 ret
= DdeUnaccessData(hdata
);
1919 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1921 ret
= DdeFreeDataHandle(hdata
);
1922 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1925 DdeGetLastError(dde_inst
);
1926 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", 0, 0, item
, CF_TEXT
, 0);
1927 err
= DdeGetLastError(dde_inst
);
1928 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1929 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1931 ptr
= DdeAccessData(hdata
, &size
);
1932 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1933 ok(size
== 0, "Expected 0, got %ld\n", size
);
1935 ret
= DdeUnaccessData(hdata
);
1936 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1938 ret
= DdeFreeDataHandle(hdata
);
1939 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1941 /* cbOff is non-zero */
1942 DdeGetLastError(dde_inst
);
1943 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 2, item
, CF_TEXT
, 0);
1944 err
= DdeGetLastError(dde_inst
);
1945 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1946 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1948 ptr
= DdeAccessData(hdata
, &size
);
1949 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1950 ok(size
== 262, "Expected 262, got %ld\n", size
);
1953 ok(ptr
&& !*ptr
, "Expected 0, got %d\n", lstrlenA((LPSTR
)ptr
));
1956 ret
= DdeUnaccessData(hdata
);
1957 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1959 ret
= DdeFreeDataHandle(hdata
);
1960 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1963 DdeGetLastError(dde_inst
);
1964 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, 0, CF_TEXT
, 0);
1965 err
= DdeGetLastError(dde_inst
);
1966 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1967 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1969 ptr
= DdeAccessData(hdata
, &size
);
1970 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1971 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1972 ok(size
== 260, "Expected 260, got %ld\n", size
);
1974 ret
= DdeUnaccessData(hdata
);
1975 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1977 ret
= DdeFreeDataHandle(hdata
);
1978 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1981 DdeGetLastError(dde_inst
);
1982 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, (HSZ
)0xdeadbeef, CF_TEXT
, 0);
1983 err
= DdeGetLastError(dde_inst
);
1984 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1985 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1987 ptr
= DdeAccessData(hdata
, &size
);
1988 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1989 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1990 ok(size
== 260, "Expected 260, got %ld\n", size
);
1992 ret
= DdeUnaccessData(hdata
);
1993 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1995 ret
= DdeFreeDataHandle(hdata
);
1996 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1998 /* invalid clipboard format */
1999 DdeGetLastError(dde_inst
);
2000 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, item
, 0xdeadbeef, 0);
2001 err
= DdeGetLastError(dde_inst
);
2002 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
2003 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
2005 ptr
= DdeAccessData(hdata
, &size
);
2006 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2007 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
2008 ok(size
== 260, "Expected 260, got %ld\n", size
);
2010 ret
= DdeUnaccessData(hdata
);
2011 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2013 ret
= DdeFreeDataHandle(hdata
);
2014 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2016 ret
= DdeUninitialize(dde_inst
);
2017 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2020 static void test_DdeCreateStringHandle(void)
2022 DWORD dde_inst
, ret
;
2024 dde_inst
= 0xdeadbeef;
2025 SetLastError(0xdeadbeef);
2026 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2027 ok(ret
== DMLERR_INVALIDPARAMETER
, "DdeInitializeW should fail, but got %04lx instead\n", ret
);
2028 ok(DdeGetLastError(dde_inst
) == DMLERR_INVALIDPARAMETER
, "expected DMLERR_INVALIDPARAMETER\n");
2031 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2032 ok(ret
== DMLERR_NO_ERROR
, "DdeInitializeW failed with error %04lx (%08x)\n",
2033 ret
, DdeGetLastError(dde_inst
));
2035 test_DdeCreateStringHandleW(dde_inst
, 0);
2036 test_DdeCreateStringHandleW(dde_inst
, CP_WINUNICODE
);
2037 test_DdeCreateStringHandleW(dde_inst
, CP_WINANSI
);
2039 ok(DdeUninitialize(dde_inst
), "DdeUninitialize failed\n");
2042 static void test_FreeDDElParam(void)
2044 HGLOBAL val
, hglobal
;
2047 ret
= FreeDDElParam(WM_DDE_INITIATE
, 0);
2048 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2050 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2051 ret
= FreeDDElParam(WM_DDE_INITIATE
, (LPARAM
)hglobal
);
2052 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2053 val
= GlobalFree(hglobal
);
2054 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2056 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2057 ret
= FreeDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
);
2058 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2060 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2061 ret
= FreeDDElParam(WM_DDE_UNADVISE
, (LPARAM
)hglobal
);
2062 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2063 val
= GlobalFree(hglobal
);
2064 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2066 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2067 ret
= FreeDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
);
2068 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2070 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2071 ret
= FreeDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
);
2072 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2074 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2075 ret
= FreeDDElParam(WM_DDE_REQUEST
, (LPARAM
)hglobal
);
2076 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2077 val
= GlobalFree(hglobal
);
2078 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2080 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2081 ret
= FreeDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
);
2082 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2084 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2085 ret
= FreeDDElParam(WM_DDE_EXECUTE
, (LPARAM
)hglobal
);
2086 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2087 val
= GlobalFree(hglobal
);
2088 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2091 static void test_PackDDElParam(void)
2093 UINT_PTR lo
, hi
, *ptr
;
2097 lparam
= PackDDElParam(WM_DDE_INITIATE
, 0xcafe, 0xbeef);
2098 /* value gets sign-extended despite being an LPARAM */
2099 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam
);
2102 ret
= UnpackDDElParam(WM_DDE_INITIATE
, lparam
, &lo
, &hi
);
2103 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2104 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2105 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2107 ret
= FreeDDElParam(WM_DDE_INITIATE
, lparam
);
2108 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2110 lparam
= PackDDElParam(WM_DDE_TERMINATE
, 0xcafe, 0xbeef);
2111 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam
);
2114 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, lparam
, &lo
, &hi
);
2115 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2116 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2117 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2119 ret
= FreeDDElParam(WM_DDE_TERMINATE
, lparam
);
2120 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2122 lparam
= PackDDElParam(WM_DDE_ADVISE
, 0xcafe, 0xbeef);
2123 ptr
= GlobalLock((HGLOBAL
)lparam
);
2124 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2125 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr
[0]);
2126 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr
[1]);
2128 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2129 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2132 ret
= UnpackDDElParam(WM_DDE_ADVISE
, lparam
, &lo
, &hi
);
2133 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2134 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2135 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2137 ret
= FreeDDElParam(WM_DDE_ADVISE
, lparam
);
2138 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2140 lparam
= PackDDElParam(WM_DDE_UNADVISE
, 0xcafe, 0xbeef);
2141 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam
);
2144 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, lparam
, &lo
, &hi
);
2145 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2146 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2147 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2149 ret
= FreeDDElParam(WM_DDE_UNADVISE
, lparam
);
2150 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2152 lparam
= PackDDElParam(WM_DDE_ACK
, 0xcafe, 0xbeef);
2153 ptr
= GlobalLock((HGLOBAL
)lparam
);
2154 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2155 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr
[0]);
2156 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr
[1]);
2158 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2159 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2162 ret
= UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
2163 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2164 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2165 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2167 ret
= FreeDDElParam(WM_DDE_ACK
, lparam
);
2168 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2170 lparam
= PackDDElParam(WM_DDE_DATA
, 0xcafe, 0xbeef);
2171 ptr
= GlobalLock((HGLOBAL
)lparam
);
2172 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2173 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr
[0]);
2174 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr
[1]);
2176 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2177 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2180 ret
= UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
2181 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2182 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2183 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2185 ret
= FreeDDElParam(WM_DDE_DATA
, lparam
);
2186 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2188 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xcafe, 0xbeef);
2189 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08Ix\n", lparam
);
2192 ret
= UnpackDDElParam(WM_DDE_REQUEST
, lparam
, &lo
, &hi
);
2193 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2194 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2195 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2197 ret
= FreeDDElParam(WM_DDE_REQUEST
, lparam
);
2198 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2200 lparam
= PackDDElParam(WM_DDE_POKE
, 0xcafe, 0xbeef);
2201 ptr
= GlobalLock((HGLOBAL
)lparam
);
2202 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2203 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08Ix\n", ptr
[0]);
2204 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08Ix\n", ptr
[1]);
2206 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2207 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2210 ret
= UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
2211 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2212 ok(lo
== 0xcafe, "Expected 0xcafe, got %08Ix\n", lo
);
2213 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2215 ret
= FreeDDElParam(WM_DDE_POKE
, lparam
);
2216 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2218 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0xcafe, 0xbeef);
2219 ok(lparam
== 0xbeef, "Expected 0xbeef, got %08Ix\n", lparam
);
2222 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
2223 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2224 ok(lo
== 0, "Expected 0, got %08Ix\n", lo
);
2225 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2227 ret
= FreeDDElParam(WM_DDE_EXECUTE
, lparam
);
2228 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2231 static void test_UnpackDDElParam(void)
2233 UINT_PTR lo
, hi
, *ptr
;
2240 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0, &lo
, &hi
);
2241 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2242 ok(lo
== 0, "Expected 0, got %08Ix\n", lo
);
2243 ok(hi
== 0, "Expected 0, got %08Ix\n", hi
);
2248 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, NULL
, &hi
);
2249 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2250 ok(lo
== 0xdead, "Expected 0xdead, got %08Ix\n", lo
);
2251 ok(hi
== 0xcafe, "Expected 0xcafe, got %08Ix\n", hi
);
2256 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, NULL
);
2257 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2258 ok(lo
== 0xbabe, "Expected 0xbabe, got %08Ix\n", lo
);
2259 ok(hi
== 0xbeef, "Expected 0xbeef, got %08Ix\n", hi
);
2263 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, &hi
);
2264 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2265 ok(lo
== 0xbabe, "Expected 0xbabe, got %08Ix\n", lo
);
2266 ok(hi
== 0xcafe, "Expected 0xcafe, got %08Ix\n", hi
);
2270 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, 0xcafebabe, &lo
, &hi
);
2271 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2272 ok(lo
== 0xbabe, "Expected 0xbabe, got %08Ix\n", lo
);
2273 ok(hi
== 0xcafe, "Expected 0xcafe, got %08Ix\n", hi
);
2277 ret
= UnpackDDElParam(WM_DDE_ADVISE
, 0, &lo
, &hi
);
2278 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2280 broken(lo
== 0xdead), /* win2k */
2281 "Expected 0, got %08Ix\n", lo
);
2283 broken(hi
== 0xbeef), /* win2k */
2284 "Expected 0, got %08Ix\n", hi
);
2286 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 2 * sizeof(*ptr
));
2287 ptr
= GlobalLock(hglobal
);
2288 ptr
[0] = 0xcafebabe;
2289 ptr
[1] = 0xdeadbeef;
2290 GlobalUnlock(hglobal
);
2294 ret
= UnpackDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
, &lo
, &hi
);
2295 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2296 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo
);
2297 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi
);
2301 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, 0xcafebabe, &lo
, &hi
);
2302 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2303 ok(lo
== 0xbabe, "Expected 0xbabe, got %08Ix\n", lo
);
2304 ok(hi
== 0xcafe, "Expected 0xcafe, got %08Ix\n", hi
);
2308 ret
= UnpackDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
, &lo
, &hi
);
2309 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2310 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo
);
2311 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi
);
2315 ret
= UnpackDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
, &lo
, &hi
);
2316 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2317 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo
);
2318 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi
);
2322 ret
= UnpackDDElParam(WM_DDE_REQUEST
, 0xcafebabe, &lo
, &hi
);
2323 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2324 ok(lo
== 0xbabe, "Expected 0xbabe, got %08Ix\n", lo
);
2325 ok(hi
== 0xcafe, "Expected 0xcafe, got %08Ix\n", hi
);
2329 ret
= UnpackDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
, &lo
, &hi
);
2330 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2331 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", lo
);
2332 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08Ix\n", hi
);
2336 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, 0xcafebabe, &lo
, &hi
);
2337 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2338 ok(lo
== 0, "Expected 0, got %08Ix\n", lo
);
2339 ok(hi
== 0xcafebabe, "Expected 0xcafebabe, got %08Ix\n", hi
);
2341 GlobalFree(hglobal
);
2344 static char test_cmd_a_to_a
[] = "Test dde command";
2345 static WCHAR test_cmd_w_to_w
[][32] = {
2346 {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0},
2347 { 0x2018, 0x2019, 0x0161, 0x0041, 0x02dc, 0 }, /* some chars that should map properly to CP1252 */
2348 { 0x2026, 0x2020, 0x2021, 0x0d0a, 0 }, /* false negative for IsTextUnicode */
2349 { 0x4efa, 0x4efc, 0x0061, 0x4efe, 0 }, /* some Chinese chars */
2350 { 0x0061, 0x0062, 0x0063, 0x9152, 0 }, /* Chinese with latin characters begin */
2352 static int msg_index
;
2353 static BOOL unicode_server
, unicode_client
;
2355 static HDDEDATA CALLBACK
server_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2356 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2357 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2361 static HCONV conversation
= 0;
2362 static const char test_service
[] = "TestDDEService";
2363 static const char test_topic
[] = "TestDDETopic";
2365 if (winetest_debug
> 1) trace("type %#x, fmt %#x\n", uType
, uFmt
);
2367 ok(msg_index
< 5 + ARRAY_SIZE(test_cmd_w_to_w
), "Got unexpected message type %#x.\n", uType
);
2374 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
2375 return (HDDEDATA
)TRUE
;
2380 ok(msg_index
== 2, "Expected 2, got %d\n", msg_index
);
2381 ok(uFmt
== 0, "Expected 0, got %d, msg_index=%d\n", uFmt
, msg_index
);
2382 ok(hconv
== 0, "Expected 0, got %p, msg_index=%d\n", hconv
, msg_index
);
2383 ok(hdata
== 0, "Expected 0, got %p, msg_index=%d\n", hdata
, msg_index
);
2384 ok(dwData1
!= 0, "Expected not 0, got %08Ix, msg_index=%d\n", dwData1
, msg_index
);
2385 ok(dwData2
== FALSE
, "Expected FALSE, got %08Ix, msg_index=%d\n", dwData2
, msg_index
);
2387 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2388 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2389 test_topic
, str
, msg_index
);
2390 ok(size
== 12, "Expected 12, got %ld, msg_index=%d\n", size
, msg_index
);
2392 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
2393 ok(!lstrcmpA(str
, test_service
), "Expected %s, got %s, msg_index=%d\n",
2394 test_service
, str
, msg_index
);
2395 ok(size
== 14, "Expected 14, got %ld, msg_index=%d\n", size
, msg_index
);
2397 return (HDDEDATA
) TRUE
;
2399 case XTYP_CONNECT_CONFIRM
:
2401 ok(msg_index
== 3, "Expected 3, got %d\n", msg_index
);
2402 conversation
= hconv
;
2403 return (HDDEDATA
) TRUE
;
2407 BYTE
*buffer
= NULL
;
2409 char test_cmd_w_to_a
[64];
2410 WCHAR test_cmd_a_to_w
[64];
2411 DWORD size_a
, size_w
, size_w_to_a
, size_a_to_w
;
2414 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
2415 ok(hconv
== conversation
, "Expected conversation handle, got %p, msg_index=%d\n",
2417 ok(dwData1
== 0, "Expected 0, got %08Ix, msg_index=%d\n", dwData1
, msg_index
);
2418 ok(dwData2
== 0, "Expected 0, got %08Ix, msg_index=%d\n", dwData2
, msg_index
);
2419 ok(hsz2
== 0, "Expected 0, got %p, msg_index=%d\n", hsz2
, msg_index
);
2420 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2421 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2422 test_topic
, str
, msg_index
);
2423 ok(size
== 12, "Expected 12, got %ld, msg_index=%d\n", size
, msg_index
);
2425 size
= DdeGetData(hdata
, NULL
, 0, 0);
2426 ok((buffer
= calloc(1, size
)) != NULL
, "should not be null\n");
2427 rsize
= DdeGetData(hdata
, buffer
, size
, 0);
2428 ok(rsize
== size
, "Incorrect size returned, expected %ld got %ld, msg_index=%d\n",
2429 size
, rsize
, msg_index
);
2430 if (winetest_debug
> 1) trace("msg %u strA \"%s\" strW %s\n", msg_index
, buffer
, wine_dbgstr_w((WCHAR
*)buffer
));
2432 str_index
= msg_index
- 4;
2433 cmd_w
= test_cmd_w_to_w
[str_index
- 1];
2434 size_a
= strlen(test_cmd_a_to_a
) + 1;
2435 size_w
= (lstrlenW(cmd_w
) + 1) * sizeof(WCHAR
);
2436 size_a_to_w
= MultiByteToWideChar( CP_ACP
, 0, test_cmd_a_to_a
, -1, test_cmd_a_to_w
,
2437 ARRAY_SIZE(test_cmd_a_to_w
)) * sizeof(WCHAR
);
2438 size_w_to_a
= WideCharToMultiByte( CP_ACP
, 0, cmd_w
, -1,
2439 test_cmd_w_to_a
, sizeof(test_cmd_w_to_a
), NULL
, NULL
);
2442 case 0: /* ANSI string */
2445 ok(size
== size_a_to_w
, "Wrong size %ld/%ld, msg_index=%d\n", size
, size_a_to_w
, msg_index
);
2446 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_a_to_w
),
2447 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w
), msg_index
);
2449 else if (unicode_client
)
2451 /* ANSI string mapped W->A -> garbage */
2455 ok(size
== size_a
, "Wrong size %ld/%ld, msg_index=%d\n", size
, size_a
, msg_index
);
2456 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_a_to_a
), "Expected %s, got %s, msg_index=%d\n",
2457 test_cmd_a_to_a
, buffer
, msg_index
);
2461 case 1: /* Unicode string with only 8-bit chars */
2464 ok(size
== size_w
, "Wrong size %ld/%ld, msg_index=%d\n", size
, size_w
, msg_index
);
2465 ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2466 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), msg_index
);
2470 ok(size
== size_w_to_a
, "Wrong size %ld/%ld, msg_index=%d\n",
2471 size
, size_w_to_a
, msg_index
);
2472 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2473 test_cmd_w_to_a
, buffer
, msg_index
);
2477 case 2: /* normal Unicode string */
2478 case 3: /* IsTextUnicode false negative */
2479 case 4: /* Chinese chars */
2482 /* double A->W mapping */
2483 /* NT uses the full size, XP+ only until the first null */
2484 DWORD nt_size
= MultiByteToWideChar( CP_ACP
, 0, (char *)cmd_w
, size_w
, test_cmd_a_to_w
,
2485 ARRAY_SIZE(test_cmd_a_to_w
)) * sizeof(WCHAR
);
2486 DWORD xp_size
= MultiByteToWideChar( CP_ACP
, 0, (char *)cmd_w
, -1, NULL
, 0 ) * sizeof(WCHAR
);
2487 ok(size
== xp_size
|| broken(size
== nt_size
) ||
2488 broken(str_index
== 4 && IsDBCSLeadByte(cmd_w
[0])) /* East Asian */,
2489 "Wrong size %ld/%ld, msg_index=%d\n", size
, size_a_to_w
, msg_index
);
2490 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_a_to_w
),
2491 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w
), msg_index
);
2493 else if (unicode_client
)
2495 ok(size
== size_w_to_a
, "Wrong size %ld/%ld, msg_index=%d\n", size
, size_w_to_a
, 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
);
2501 ok(size
== size_w
, "Wrong size %ld/%ld, msg_index=%d\n", size
, size_w
, msg_index
);
2502 ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2503 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), msg_index
);
2506 case 5: /* Chinese with latin characters begin */
2507 if (unicode_server
&& unicode_client
)
2509 todo_wine
ok(size
== size_w
, "Wrong size %ld expected %ld, msg_index=%d\n", size
, size_w
, msg_index
);
2510 MultiByteToWideChar(CP_ACP
, 0, test_cmd_w_to_a
, size_w
, test_cmd_a_to_w
,
2511 ARRAY_SIZE(test_cmd_a_to_w
));
2512 todo_wine
ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2513 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), wine_dbgstr_w((WCHAR
*)buffer
), msg_index
);
2515 else if (unicode_server
)
2517 todo_wine
ok(size
== size_w
, "Wrong size %ld expected %ld, msg_index=%d\n", size
, size_w
, msg_index
);
2518 MultiByteToWideChar(CP_ACP
, 0, test_cmd_w_to_a
, size_w
, test_cmd_a_to_w
,
2519 ARRAY_SIZE(test_cmd_a_to_w
));
2521 todo_wine
ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_a_to_w
), "Expected %s, got %s, msg_index=%d\n",
2522 wine_dbgstr_w(test_cmd_a_to_w
), wine_dbgstr_w((WCHAR
*)buffer
), msg_index
);
2524 todo_wine
ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2525 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), wine_dbgstr_w((WCHAR
*)buffer
), msg_index
);
2527 else if (unicode_client
)
2529 ok(size
== size_w_to_a
, "Wrong size %ld expected %ld, msg_index=%d\n", size
, size_w_to_a
, msg_index
);
2530 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2531 test_cmd_w_to_a
, buffer
, msg_index
);
2535 todo_wine
ok(size
== size_w_to_a
|| size
== (size_w_to_a
- 1), "Wrong size %ld expected %ld or %ld, msg_index=%d\n",
2536 size
, size_w_to_a
, size_w_to_a
- 1, msg_index
);
2537 todo_wine
ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2538 test_cmd_w_to_a
, buffer
, msg_index
);
2543 ok( 0, "Invalid message %u\n", msg_index
);
2547 return (HDDEDATA
) DDE_FACK
;
2549 case XTYP_DISCONNECT
:
2550 return (HDDEDATA
) TRUE
;
2553 ok(FALSE
, "Unhandled msg: %08x, msg_index=%d\n", uType
, msg_index
);
2559 static HDDEDATA CALLBACK
client_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2560 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2561 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2565 case XTYP_DISCONNECT
:
2566 return (HDDEDATA
) TRUE
;
2569 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
2575 static void test_end_to_end_client(BOOL type_a
)
2578 DWORD client_pid
= 0;
2582 static const char test_service
[] = "TestDDEService";
2583 static const WCHAR test_service_w
[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2584 static const char test_topic
[] = "TestDDETopic";
2585 static const WCHAR test_topic_w
[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2588 ret
= DdeInitializeA(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2590 ret
= DdeInitializeW(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2591 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %lx\n", ret
);
2595 server
= DdeCreateStringHandleA(client_pid
, test_service
, CP_WINANSI
);
2596 topic
= DdeCreateStringHandleA(client_pid
, test_topic
, CP_WINANSI
);
2599 server
= DdeCreateStringHandleW(client_pid
, test_service_w
, CP_WINUNICODE
);
2600 topic
= DdeCreateStringHandleW(client_pid
, test_topic_w
, CP_WINUNICODE
);
2603 DdeGetLastError(client_pid
);
2604 hconv
= DdeConnect(client_pid
, server
, topic
, NULL
);
2605 if (broken(!hconv
)) /* Windows 10 version 1607 */
2607 win_skip("Failed to connect; error %#x.\n", DdeGetLastError(client_pid
));
2608 DdeUninitialize(client_pid
);
2611 ret
= DdeGetLastError(client_pid
);
2612 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %lx\n", ret
);
2613 DdeFreeStringHandle(client_pid
, server
);
2615 /* Test both A and W data being passed to DdeClientTransaction */
2616 hdata
= DdeClientTransaction((LPBYTE
)test_cmd_a_to_a
, sizeof(test_cmd_a_to_a
),
2617 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2618 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2619 ok(ret
== DDE_FACK
, "wrong status code %lx\n", ret
);
2620 err
= DdeGetLastError(client_pid
);
2621 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %lx\n", err
);
2623 for (i
= 0; i
< ARRAY_SIZE(test_cmd_w_to_w
); i
++)
2625 hdata
= DdeClientTransaction((LPBYTE
)test_cmd_w_to_w
[i
],
2626 (lstrlenW(test_cmd_w_to_w
[i
]) + 1) * sizeof(WCHAR
),
2627 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2628 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2629 ok(ret
== DDE_FACK
, "wrong status code %lx\n", ret
);
2630 err
= DdeGetLastError(client_pid
);
2631 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %lx\n", err
);
2634 DdeFreeStringHandle(client_pid
, topic
);
2635 ret
= DdeDisconnect(hconv
);
2636 ok(ret
== TRUE
, "Expected TRUE, got %lx\n", ret
);
2638 ret
= DdeUninitialize(client_pid
);
2639 ok(ret
== TRUE
, "Expected TRUE, got %lx\n", ret
);
2643 static void test_end_to_end_server(void)
2651 static const char test_service
[] = "TestDDEService";
2653 trace("client %s, server %s\n", unicode_client
? "unicode" : "ansi",
2654 unicode_server
? "unicode" : "ansi");
2659 res
= DdeInitializeW(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2661 res
= DdeInitializeA(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2662 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %ld\n", res
);
2664 server
= DdeCreateStringHandleA(server_pid
, test_service
, CP_WINANSI
);
2665 ok(server
!= NULL
, "Expected non-NULL string handle\n");
2667 hdata
= DdeNameService(server_pid
, server
, 0, DNS_REGISTER
);
2668 ok(hdata
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", hdata
);
2670 client
= create_process(unicode_client
? "endw" : "enda");
2672 while (MsgWaitForMultipleObjects(1, &client
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
2674 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2677 ret
= DdeUninitialize(server_pid
);
2678 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2679 GetExitCodeProcess(client
, &res
);
2680 ok( !res
, "client failed with %lu error(s)\n", res
);
2681 CloseHandle(client
);
2688 DWORD dde_inst
= 0xdeadbeef;
2690 argc
= winetest_get_mainargs(&argv
);
2693 if (!lstrcmpA(argv
[2], "ddeml"))
2694 test_ddeml_client();
2695 else if (!lstrcmpA(argv
[2], "msg"))
2697 else if (!lstrcmpA(argv
[2], "enda"))
2698 test_end_to_end_client(TRUE
);
2699 else if (!lstrcmpA(argv
[2], "endw"))
2700 test_end_to_end_client(FALSE
);
2705 test_initialisation();
2707 DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2710 test_ddeml_server();
2712 /* Test the combinations of A and W interfaces with A and W data
2713 end to end to ensure that data conversions are accurate */
2714 unicode_client
= unicode_server
= FALSE
;
2715 test_end_to_end_server();
2716 unicode_client
= unicode_server
= TRUE
;
2717 test_end_to_end_server();
2718 unicode_client
= FALSE
;
2719 unicode_server
= TRUE
;
2720 test_end_to_end_server();
2721 unicode_client
= TRUE
;
2722 unicode_server
= FALSE
;
2723 test_end_to_end_server();
2725 test_dde_aw_transaction( FALSE
, TRUE
);
2726 test_dde_aw_transaction( TRUE
, FALSE
);
2727 test_dde_aw_transaction( TRUE
, TRUE
);
2728 test_dde_aw_transaction( FALSE
, FALSE
);
2730 test_dde_aw_transaction( FALSE
, TRUE
);
2731 test_dde_aw_transaction( TRUE
, FALSE
);
2732 test_dde_aw_transaction( TRUE
, TRUE
);
2733 test_dde_aw_transaction( FALSE
, FALSE
);
2735 test_DdeCreateDataHandle();
2736 test_DdeCreateStringHandle();
2737 test_FreeDDElParam();
2738 test_PackDDElParam();
2739 test_UnpackDDElParam();