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
27 static const WCHAR TEST_DDE_SERVICE
[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
29 static char exec_cmdA
[] = "ANSI dde command";
30 static WCHAR exec_cmdAW
[] = {'A','N','S','I',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
31 static WCHAR exec_cmdW
[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
32 static char exec_cmdWA
[] = "unicode dde command";
34 static WNDPROC old_dde_client_wndproc
;
36 static const DWORD default_timeout
= 200;
38 static BOOL
is_cjk(void)
40 int lang_id
= PRIMARYLANGID(GetUserDefaultLangID());
42 if (lang_id
== LANG_CHINESE
|| lang_id
== LANG_JAPANESE
|| lang_id
== LANG_KOREAN
)
47 static void flush_events(void)
50 int diff
= default_timeout
;
52 DWORD time
= GetTickCount() + diff
;
56 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
57 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
58 diff
= time
- GetTickCount();
63 static void create_dde_window(HWND
*hwnd
, LPCSTR name
, WNDPROC wndproc
)
68 memset(&wcA
, 0, sizeof(wcA
));
69 wcA
.lpfnWndProc
= wndproc
;
70 wcA
.lpszClassName
= name
;
71 wcA
.hInstance
= GetModuleHandleA(0);
72 aclass
= RegisterClassA(&wcA
);
73 ok (aclass
, "RegisterClass failed\n");
75 *hwnd
= CreateWindowExA(0, name
, NULL
, WS_POPUP
,
76 500, 500, CW_USEDEFAULT
, CW_USEDEFAULT
,
77 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
78 ok(*hwnd
!= NULL
, "CreateWindowExA failed\n");
81 static void destroy_dde_window(HWND
*hwnd
, LPCSTR name
)
84 UnregisterClassA(name
, GetModuleHandleA(NULL
));
87 static LRESULT WINAPI
dde_server_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
90 char str
[MAX_PATH
], *ptr
;
96 static int msg_index
= 0;
97 static HWND client
= 0;
98 static BOOL executed
= FALSE
;
100 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
101 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
107 case WM_DDE_INITIATE
:
109 client
= (HWND
)wparam
;
110 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
112 GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
113 ok(!lstrcmpA(str
, "TestDDEService"), "Expected TestDDEService, got %s\n", str
);
115 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
116 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
118 SendMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
125 ok((msg_index
>= 2 && msg_index
<= 4) ||
126 (msg_index
>= 7 && msg_index
<= 8),
127 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index
);
128 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
129 ok(LOWORD(lparam
) == CF_TEXT
, "Expected CF_TEXT, got %d\n", LOWORD(lparam
));
131 GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
133 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
135 ok(!lstrcmpA(str
, "executed"), "Expected executed, got %s\n", str
);
140 lstrcpyA(str
, "command executed\r\n");
142 lstrcpyA(str
, "command not executed\r\n");
145 lstrcpyA(str
, "requested data\r\n");
147 size
= FIELD_OFFSET(DDEDATA
, Value
[lstrlenA(str
) + 1]);
148 hglobal
= GlobalAlloc(GMEM_MOVEABLE
, size
);
149 ok(hglobal
!= NULL
, "Expected non-NULL hglobal\n");
151 data
= GlobalLock(hglobal
);
152 ZeroMemory(data
, size
);
154 /* setting fResponse to FALSE at this point destroys
155 * the internal messaging state of native dde
157 data
->fResponse
= TRUE
;
160 data
->fRelease
= TRUE
;
161 else if (msg_index
== 3)
162 data
->fAckReq
= TRUE
;
164 data
->cfFormat
= CF_TEXT
;
165 lstrcpyA((LPSTR
)data
->Value
, str
);
166 GlobalUnlock(hglobal
);
168 lparam
= PackDDElParam(WM_DDE_DATA
, (UINT_PTR
)hglobal
, HIWORD(lparam
));
169 PostMessageA(client
, WM_DDE_DATA
, (WPARAM
)hwnd
, lparam
);
176 ok(msg_index
== 5 || msg_index
== 6, "Expected 5 or 6, got %d\n", msg_index
);
177 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
179 UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
181 GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
182 ok(!lstrcmpA(str
, "poker"), "Expected poker, got %s\n", str
);
184 poke
= GlobalLock((HGLOBAL
)lo
);
185 ok(poke
!= NULL
, "Expected non-NULL poke\n");
186 ok(poke
->fReserved
== 0, "Expected 0, got %d\n", poke
->fReserved
);
187 ok(poke
->unused
== 0, "Expected 0, got %d\n", poke
->unused
);
188 ok(poke
->fRelease
== TRUE
, "Expected TRUE, got %d\n", poke
->fRelease
);
189 ok(poke
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", poke
->cfFormat
);
193 size
= GlobalSize((HGLOBAL
)lo
);
194 ok(size
== 4 || broken(size
== 32), /* sizes are rounded up on win9x */ "got %d\n", size
);
197 ok(!lstrcmpA((LPSTR
)poke
->Value
, "poke data\r\n"),
198 "Expected 'poke data\\r\\n', got %s\n", poke
->Value
);
200 GlobalUnlock((HGLOBAL
)lo
);
202 lparam
= PackDDElParam(WM_DDE_ACK
, DDE_FACK
, hi
);
203 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
210 ok(msg_index
== 7, "Expected 7, got %d\n", msg_index
);
211 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
213 ptr
= GlobalLock((HGLOBAL
)lparam
);
214 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr
);
215 GlobalUnlock((HGLOBAL
)lparam
);
219 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, DDE_FACK
, lparam
);
220 PostMessageA(client
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
225 case WM_DDE_TERMINATE
:
227 ok(msg_index
== 9, "Expected 9, got %d\n", msg_index
);
228 ok(wparam
== (WPARAM
)client
, "Expected client hwnd, got %08lx\n", wparam
);
229 ok(lparam
== 0, "Expected 0, got %08lx\n", lparam
);
231 PostMessageA(client
, WM_DDE_TERMINATE
, (WPARAM
)hwnd
, 0);
236 case WM_DDE_ACK
: /* happens on win9x when fAckReq is TRUE, ignore it */
237 ok(msg_index
== 4, "Expected 4, got %d\n", msg_index
);
242 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
245 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
248 static void test_msg_server(HANDLE hproc
, HANDLE hthread
)
254 create_dde_window(&hwnd
, "dde_server", dde_server_wndproc
);
255 ResumeThread( hthread
);
257 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
259 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
262 destroy_dde_window(&hwnd
, "dde_server");
263 GetExitCodeProcess( hproc
, &res
);
264 ok( !res
, "client failed with %u error(s)\n", res
);
267 static HDDEDATA CALLBACK
client_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
268 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
269 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
271 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
275 static void test_ddeml_client(void)
282 HSZ server
, topic
, item
;
287 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
288 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
290 /* FIXME: make these atoms global and check them in the server */
292 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
293 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
295 DdeGetLastError(client_pid
);
296 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
297 ok(conversation
!= NULL
, "Expected non-NULL conversation\n");
298 ret
= DdeGetLastError(client_pid
);
299 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
301 DdeFreeStringHandle(client_pid
, server
);
303 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
305 /* XTYP_REQUEST, fRelease = TRUE */
307 DdeGetLastError(client_pid
);
308 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
309 ret
= DdeGetLastError(client_pid
);
310 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
311 ok(res
== DDE_FNOTPROCESSED
|| broken(res
== 0xdeadbeef), /* win9x */
312 "Expected DDE_FNOTPROCESSED, got %08x\n", res
);
313 ok( hdata
!= NULL
, "hdata is NULL\n" );
316 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
317 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
318 ok(size
== 17, "Expected 17, got %d\n", size
);
320 ret
= DdeUnaccessData(hdata
);
321 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
324 /* XTYP_REQUEST, fAckReq = TRUE */
326 DdeGetLastError(client_pid
);
327 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
328 ret
= DdeGetLastError(client_pid
);
329 ok(res
== DDE_FNOTPROCESSED
|| broken(res
== 0xdeadbeef), /* win9x */
330 "Expected DDE_FNOTPROCESSED, got %x\n", res
);
332 ok(ret
== DMLERR_MEMORY_ERROR
|| broken(ret
== 0), /* win9x */
333 "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
334 ok( hdata
!= NULL
, "hdata is NULL\n" );
337 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
338 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
339 ok(size
== 17, "Expected 17, got %d\n", size
);
341 ret
= DdeUnaccessData(hdata
);
342 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
345 /* XTYP_REQUEST, all params normal */
347 DdeGetLastError(client_pid
);
348 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
349 ret
= DdeGetLastError(client_pid
);
350 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
351 ok(res
== DDE_FNOTPROCESSED
|| broken(res
== 0xdeadbeef), /* win9x */
352 "Expected DDE_FNOTPROCESSED, got %x\n", res
);
354 ok(FALSE
, "hdata is NULL\n");
357 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
358 ok(!lstrcmpA(str
, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str
);
359 ok(size
== 17, "Expected 17, got %d\n", size
);
361 ret
= DdeUnaccessData(hdata
);
362 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
365 /* XTYP_REQUEST, no item */
367 DdeGetLastError(client_pid
);
368 hdata
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
369 ret
= DdeGetLastError(client_pid
);
370 ok(hdata
== NULL
, "Expected NULL hdata, got %p\n", hdata
);
371 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res
);
372 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
374 DdeFreeStringHandle(client_pid
, item
);
376 item
= DdeCreateStringHandleA(client_pid
, "poker", CP_WINANSI
);
378 lstrcpyA(buffer
, "poke data\r\n");
379 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
380 0, item
, CF_TEXT
, 0);
381 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
383 /* XTYP_POKE, no item */
385 DdeGetLastError(client_pid
);
386 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
387 ret
= DdeGetLastError(client_pid
);
388 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
389 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
390 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
392 /* XTYP_POKE, no data */
394 DdeGetLastError(client_pid
);
395 op
= DdeClientTransaction(NULL
, 0, conversation
, 0, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
396 ret
= DdeGetLastError(client_pid
);
397 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
398 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
399 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
401 /* XTYP_POKE, wrong size */
403 DdeGetLastError(client_pid
);
404 op
= DdeClientTransaction((LPBYTE
)hdata
, 0, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
405 ret
= DdeGetLastError(client_pid
);
406 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
407 ok(res
== DDE_FACK
|| broken(res
== (0xdead0000 | DDE_FACK
)), /* win9x */
408 "Expected DDE_FACK, got %x\n", res
);
409 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
411 /* XTYP_POKE, correct params */
413 DdeGetLastError(client_pid
);
414 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, item
, CF_TEXT
, XTYP_POKE
, default_timeout
, &res
);
415 ret
= DdeGetLastError(client_pid
);
416 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
417 ok(res
== DDE_FACK
|| broken(res
== (0xdead0000 | DDE_FACK
)), /* win9x */
418 "Expected DDE_FACK, got %x\n", res
);
419 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
421 DdeFreeDataHandle(hdata
);
423 lstrcpyA(buffer
, "[Command(Var)]");
424 hdata
= DdeCreateDataHandle(client_pid
, (LPBYTE
)buffer
, lstrlenA(buffer
) + 1,
425 0, NULL
, CF_TEXT
, 0);
426 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
428 /* XTYP_EXECUTE, correct params */
430 DdeGetLastError(client_pid
);
431 op
= DdeClientTransaction((LPBYTE
)hdata
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
432 ret
= DdeGetLastError(client_pid
);
433 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
434 ok(op
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", op
);
435 ok(res
== DDE_FACK
|| broken(res
== (0xdead0000 | DDE_FACK
)), /* win9x */
436 "Expected DDE_FACK, got %x\n", res
);
438 /* XTYP_EXECUTE, no data */
440 DdeGetLastError(client_pid
);
441 op
= DdeClientTransaction(NULL
, 0, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
442 ret
= DdeGetLastError(client_pid
);
443 ok(op
== NULL
|| broken(op
== (HDDEDATA
)TRUE
), /* win9x */ "Expected NULL, got %p\n", op
);
446 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
447 ok(ret
== DMLERR_MEMORY_ERROR
, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret
);
451 ok(res
== (0xdead0000 | DDE_FACK
), "Expected DDE_FACK, got %x\n", res
);
452 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
455 /* XTYP_EXECUTE, no data, -1 size */
457 DdeGetLastError(client_pid
);
458 op
= DdeClientTransaction(NULL
, -1, conversation
, NULL
, 0, XTYP_EXECUTE
, default_timeout
, &res
);
459 ret
= DdeGetLastError(client_pid
);
460 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
461 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
462 ok(ret
== DMLERR_INVALIDPARAMETER
|| broken(ret
== DMLERR_NO_ERROR
), /* win9x */
463 "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
465 DdeFreeStringHandle(client_pid
, topic
);
466 DdeFreeDataHandle(hdata
);
468 item
= DdeCreateStringHandleA(client_pid
, "executed", CP_WINANSI
);
470 /* verify the execute */
472 DdeGetLastError(client_pid
);
473 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
474 ret
= DdeGetLastError(client_pid
);
475 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
476 ok(res
== DDE_FNOTPROCESSED
|| broken(res
== (0xdead0000 | DDE_FNOTPROCESSED
)), /* win9x */
477 "Expected DDE_FNOTPROCESSED, got %d\n", res
);
479 ok(FALSE
, "hdata is NULL\n");
482 str
= (LPSTR
)DdeAccessData(hdata
, &size
);
483 ok(!lstrcmpA(str
, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str
);
484 ok(size
== 19, "Expected 19, got %d\n", size
);
486 ret
= DdeUnaccessData(hdata
);
487 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
490 /* invalid transactions */
492 DdeGetLastError(client_pid
);
493 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_ADVREQ
, default_timeout
, &res
);
494 ret
= DdeGetLastError(client_pid
);
495 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
496 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
497 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
500 DdeGetLastError(client_pid
);
501 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_CONNECT
, default_timeout
, &res
);
502 ret
= DdeGetLastError(client_pid
);
503 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
504 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
505 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
508 DdeGetLastError(client_pid
);
509 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_CONNECT_CONFIRM
, default_timeout
, &res
);
510 ret
= DdeGetLastError(client_pid
);
511 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
512 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
513 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
516 DdeGetLastError(client_pid
);
517 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_DISCONNECT
, default_timeout
, &res
);
518 ret
= DdeGetLastError(client_pid
);
519 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
520 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
521 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
524 DdeGetLastError(client_pid
);
525 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_ERROR
, default_timeout
, &res
);
526 ret
= DdeGetLastError(client_pid
);
527 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
528 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
529 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
532 DdeGetLastError(client_pid
);
533 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_MONITOR
, default_timeout
, &res
);
534 ret
= DdeGetLastError(client_pid
);
535 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
536 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
537 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
540 DdeGetLastError(client_pid
);
541 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REGISTER
, default_timeout
, &res
);
542 ret
= DdeGetLastError(client_pid
);
543 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
544 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
545 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
548 DdeGetLastError(client_pid
);
549 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_UNREGISTER
, default_timeout
, &res
);
550 ret
= DdeGetLastError(client_pid
);
551 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
552 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
553 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
556 DdeGetLastError(client_pid
);
557 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_WILDCONNECT
, default_timeout
, &res
);
558 ret
= DdeGetLastError(client_pid
);
559 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
560 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
561 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
564 DdeGetLastError(client_pid
);
565 op
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_XACT_COMPLETE
, default_timeout
, &res
);
566 ret
= DdeGetLastError(client_pid
);
567 ok(op
== NULL
, "Expected NULL, got %p\n", op
);
568 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res
);
569 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
571 DdeFreeStringHandle(client_pid
, item
);
573 ret
= DdeDisconnect(conversation
);
574 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
576 ret
= DdeUninitialize(client_pid
);
577 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
580 static DWORD server_pid
;
582 static HDDEDATA CALLBACK
server_ddeml_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
583 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
584 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
586 char str
[MAX_PATH
], *ptr
;
590 static int msg_index
= 0;
591 static HCONV conversation
= 0;
599 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
600 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
601 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
602 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
603 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
604 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
606 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
607 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
608 ok(size
== 13, "Expected 13, got %d\n", size
);
610 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
611 if (!strncmp( str
, "TestDDEServer:(", 15 )) /* win9x style */
613 ok(size
== 16 + 2*sizeof(WORD
), "Got size %d for %s\n", size
, str
);
617 ok(!strncmp(str
, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str
);
618 ok(size
== 17 + 2*sizeof(ULONG_PTR
), "Got size %d for %s\n", size
, str
);
620 ok(str
[size
- 1] == ')', "Expected ')', got %c\n", str
[size
- 1]);
622 return (HDDEDATA
)TRUE
;
627 ok(msg_index
== 2, "Expected 2, got %d\n", msg_index
);
628 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
629 ok(hconv
== 0, "Expected 0, got %p\n", hconv
);
630 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
631 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
632 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx\n", dwData2
);
634 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
635 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
636 ok(size
== 12, "Expected 12, got %d\n", size
);
638 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
639 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
640 ok(size
== 13, "Expected 13, got %d\n", size
);
642 return (HDDEDATA
)TRUE
;
645 case XTYP_CONNECT_CONFIRM
:
647 conversation
= hconv
;
649 ok(msg_index
== 3, "Expected 3, got %d\n", msg_index
);
650 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
651 ok(hconv
!= NULL
, "Expected non-NULL hconv\n");
652 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
653 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
654 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx\n", dwData2
);
656 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
657 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
658 ok(size
== 12, "Expected 12, got %d\n", size
);
660 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
661 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
662 ok(size
== 13, "Expected 13, got %d\n", size
);
664 return (HDDEDATA
)TRUE
;
669 ok(msg_index
== 4 || msg_index
== 5 || msg_index
== 6,
670 "Expected 4, 5 or 6, got %d\n", msg_index
);
671 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
672 ok(hdata
== 0, "Expected 0, got %p\n", hdata
);
673 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
674 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
677 ok(uFmt
== 0xbeef, "Expected 0xbeef, got %08x\n", uFmt
);
679 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %08x\n", uFmt
);
681 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
682 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
683 ok(size
== 12, "Expected 12, got %d\n", size
);
685 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
690 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
691 ok(size
== 1, "Expected 1, got %d\n", size
);
694 else if (msg_index
== 6)
696 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
697 ok(size
== 7, "Expected 7, got %d\n", size
);
702 lstrcpyA(str
, "requested data\r\n");
703 return DdeCreateDataHandle(server_pid
, (LPBYTE
)str
, lstrlenA(str
) + 1,
704 0, hsz2
, CF_TEXT
, 0);
712 ok(msg_index
== 7 || msg_index
== 8, "Expected 7 or 8, got %d\n", msg_index
);
713 ok(uFmt
== CF_TEXT
, "Expected CF_TEXT, got %d\n", uFmt
);
714 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
715 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
716 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
718 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
719 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
720 ok(size
== 12, "Expected 12, got %d\n", size
);
722 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
723 ok(!lstrcmpA(ptr
, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr
);
724 ok(size
== 12 || broken(size
== 28), /* sizes are rounded up on win9x */
725 "Expected 12, got %d\n", size
);
726 DdeUnaccessData(hdata
);
728 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
732 ok(!lstrcmpA(str
, ""), "Expected empty string, got %s\n", str
);
733 ok(size
== 1, "Expected 1, got %d\n", size
);
738 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
739 ok(size
== 4, "Expected 4, got %d\n", size
);
742 return (HDDEDATA
)DDE_FACK
;
747 ok(msg_index
>= 9 && msg_index
<= 11, "Expected 9 or 11, got %d\n", msg_index
);
748 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
749 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
750 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
751 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
752 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
754 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
755 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
756 ok(size
== 12, "Expected 12, got %d\n", size
);
758 if (msg_index
== 9 || msg_index
== 11)
760 ptr
= (LPSTR
)DdeAccessData(hdata
, &size
);
764 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
765 ok(size
== 15, "Expected 15, got %d\n", size
);
766 ret
= (HDDEDATA
)DDE_FACK
;
770 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
771 ok(size
== 18, "Expected 18, got %d\n", size
);
772 ret
= DDE_FNOTPROCESSED
;
775 DdeUnaccessData(hdata
);
777 else if (msg_index
== 10)
781 size
= DdeGetData(hdata
, NULL
, 0, 0);
782 ok(size
== 17, "DdeGetData should have returned 17 not %d\n", size
);
783 ptr
= HeapAlloc(GetProcessHeap(), 0, size
);
784 ok(ptr
!= NULL
,"HeapAlloc should have returned ptr not NULL\n");
785 rsize
= DdeGetData(hdata
, (LPBYTE
)ptr
, size
, 0);
786 ok(rsize
== size
, "DdeGetData did not return %d bytes but %d\n", size
, rsize
);
788 ok(!lstrcmpA(ptr
, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr
);
789 ok(size
== 17, "Expected 17, got %d\n", size
);
790 ret
= (HDDEDATA
)DDE_FACK
;
792 HeapFree(GetProcessHeap(), 0, ptr
);
798 case XTYP_DISCONNECT
:
800 ok(msg_index
== 12, "Expected 12, got %d\n", msg_index
);
801 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
802 ok(hconv
== conversation
, "Expected conversation handle, got %p\n", hconv
);
803 ok(dwData1
== 0, "Expected 0, got %08lx\n", dwData1
);
804 ok(dwData2
== 0, "Expected 0, got %08lx\n", dwData2
);
805 ok(hsz1
== 0, "Expected 0, got %p\n", hsz2
);
806 ok(hsz2
== 0, "Expected 0, got %p\n", hsz2
);
812 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
818 static void test_ddeml_server(HANDLE hproc
)
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, &hproc
, 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( hproc
, &res
);
844 ok( !res
, "client failed with %u error(s)\n", res
);
847 static HWND client_hwnd
, server_hwnd
;
848 static ATOM server
, topic
, item
;
849 static HGLOBAL execute_hglobal
;
851 static LRESULT WINAPI
dde_msg_client_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
860 static int msg_index
= 0;
862 if (msg
< WM_DDE_FIRST
|| msg
> WM_DDE_LAST
)
863 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
869 case WM_DDE_INITIATE
:
871 ok(msg_index
== 1, "Expected 1, got %d\n", msg_index
);
872 ok(wparam
== (WPARAM
)client_hwnd
, "Expected client hwnd, got %08lx\n", wparam
);
874 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
875 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
876 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
877 ok(size
== 13, "Expected 13, got %d\n", size
);
879 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
880 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
881 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
882 ok(size
== 12, "Expected 12, got %d\n", size
);
889 ok((msg_index
>= 2 && msg_index
<= 4) || (msg_index
>= 6 && msg_index
<= 11),
890 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index
);
894 server_hwnd
= (HWND
)wparam
;
895 ok(wparam
!= 0, "Expected non-NULL wparam, got %08lx\n", wparam
);
897 size
= GlobalGetAtomNameA(LOWORD(lparam
), str
, MAX_PATH
);
898 ok(LOWORD(lparam
) == server
, "Expected server atom, got %08x\n", LOWORD(lparam
));
899 ok(!lstrcmpA(str
, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str
);
900 ok(size
== 13, "Expected 13, got %d\n", size
);
902 size
= GlobalGetAtomNameA(HIWORD(lparam
), str
, MAX_PATH
);
903 ok(HIWORD(lparam
) == topic
, "Expected topic atom, got %08x\n", HIWORD(lparam
));
904 ok(!lstrcmpA(str
, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str
);
905 ok(size
== 12, "Expected 12, got %d\n", size
);
907 else if (msg_index
>= 9 && msg_index
<= 11)
909 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
911 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
914 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
915 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
916 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
918 ok(hi
== (UINT_PTR
)execute_hglobal
, "Expected execute hglobal, got %08lx\n", hi
);
919 ptr
= GlobalLock((HGLOBAL
)hi
);
923 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
924 ok(!lstrcmpA(ptr
, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr
);
925 } else if (msg_index
== 10)
927 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
928 ok(!lstrcmpA(ptr
, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr
);
932 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
933 ok(!lstrcmpA(ptr
, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr
);
936 GlobalUnlock((HGLOBAL
)hi
);
940 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
942 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
945 ok(ack
->bAppReturnCode
== 0, "Expected 0, got %d\n", ack
->bAppReturnCode
);
946 ok(ack
->reserved
== 0, "Expected 0, got %d\n", ack
->reserved
);
947 ok(ack
->fBusy
== FALSE
, "Expected FALSE, got %d\n", ack
->fBusy
);
950 ok(ack
->fAck
== TRUE
, "Expected TRUE, got %d\n", ack
->fAck
);
953 if (msg_index
== 6) todo_wine
954 ok(ack
->fAck
== FALSE
, "Expected FALSE, got %d\n", ack
->fAck
);
957 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
960 ok(hi
== item
, "Expected item atom, got %08lx\n", hi
);
961 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
962 ok(size
== 7, "Expected 7, got %d\n", size
);
964 else if (msg_index
== 4 || msg_index
== 7)
966 ok(hi
== 0, "Expected 0, got %08lx\n", hi
);
967 ok(size
== 0, "Expected empty string, got %d\n", size
);
971 ok(hi
== item
, "Expected item atom, got %08lx\n", hi
);
972 if (msg_index
== 6) todo_wine
974 ok(!lstrcmpA(str
, "poke"), "Expected poke, got %s\n", str
);
975 ok(size
== 4, "Expected 4, got %d\n", size
);
985 ok(msg_index
== 5, "Expected 5, got %d\n", msg_index
);
986 ok(wparam
== (WPARAM
)server_hwnd
, "Expected server hwnd, got %08lx\n", wparam
);
988 UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
990 data
= GlobalLock((HGLOBAL
)lo
);
991 ok(data
->unused
== 0, "Expected 0, got %d\n", data
->unused
);
992 ok(data
->fResponse
== TRUE
, "Expected TRUE, got %d\n", data
->fResponse
);
995 ok(data
->fRelease
== TRUE
, "Expected TRUE, got %d\n", data
->fRelease
);
997 ok(data
->fAckReq
== 0, "Expected 0, got %d\n", data
->fAckReq
);
998 ok(data
->cfFormat
== CF_TEXT
, "Expected CF_TEXT, got %d\n", data
->cfFormat
);
999 ok(!lstrcmpA((LPSTR
)data
->Value
, "requested data\r\n"),
1000 "Expected 'requested data\\r\\n', got %s\n", data
->Value
);
1001 GlobalUnlock((HGLOBAL
)lo
);
1003 size
= GlobalGetAtomNameA(hi
, str
, MAX_PATH
);
1004 ok(hi
== item
, "Expected item atom, got %08x\n", HIWORD(lparam
));
1005 ok(!lstrcmpA(str
, "request"), "Expected request, got %s\n", str
);
1006 ok(size
== 7, "Expected 7, got %d\n", size
);
1008 GlobalFree((HGLOBAL
)lo
);
1009 GlobalDeleteAtom(hi
);
1015 ok(FALSE
, "Unhandled msg: %08x\n", msg
);
1018 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1021 static HGLOBAL
create_poke(void)
1027 size
= FIELD_OFFSET(DDEPOKE
, Value
[sizeof("poke data\r\n")]);
1028 hglobal
= GlobalAlloc(GMEM_DDESHARE
, size
);
1029 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
1031 poke
= GlobalLock(hglobal
);
1033 poke
->fRelease
= TRUE
;
1034 poke
->fReserved
= TRUE
;
1035 poke
->cfFormat
= CF_TEXT
;
1036 lstrcpyA((LPSTR
)poke
->Value
, "poke data\r\n");
1037 GlobalUnlock(hglobal
);
1042 static HGLOBAL
create_execute(LPCSTR command
)
1047 hglobal
= GlobalAlloc(GMEM_DDESHARE
, lstrlenA(command
) + 1);
1048 ok(hglobal
!= 0, "Expected non-NULL hglobal\n");
1050 ptr
= GlobalLock(hglobal
);
1051 lstrcpyA(ptr
, command
);
1052 GlobalUnlock(hglobal
);
1057 static void test_msg_client(void)
1062 create_dde_window(&client_hwnd
, "dde_client", dde_msg_client_wndproc
);
1064 server
= GlobalAddAtomA("TestDDEServer");
1065 ok(server
!= 0, "Expected non-NULL server\n");
1067 topic
= GlobalAddAtomA("TestDDETopic");
1068 ok(topic
!= 0, "Expected non-NULL topic\n");
1070 SendMessageA(HWND_BROADCAST
, WM_DDE_INITIATE
, (WPARAM
)client_hwnd
, MAKELONG(server
, topic
));
1072 GlobalDeleteAtom(server
);
1073 GlobalDeleteAtom(topic
);
1077 item
= GlobalAddAtomA("request");
1078 ok(item
!= 0, "Expected non-NULL item\n");
1080 /* WM_DDE_REQUEST, bad clipboard format */
1081 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xdeadbeef, item
);
1082 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1086 /* WM_DDE_REQUEST, no item */
1087 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, 0);
1088 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1092 /* WM_DDE_REQUEST, no client hwnd */
1093 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1094 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, 0, lparam
);
1098 /* WM_DDE_REQUEST, correct params */
1099 lparam
= PackDDElParam(WM_DDE_REQUEST
, CF_TEXT
, item
);
1100 PostMessageA(server_hwnd
, WM_DDE_REQUEST
, (WPARAM
)client_hwnd
, lparam
);
1104 GlobalDeleteAtom(item
);
1105 item
= GlobalAddAtomA("poke");
1106 ok(item
!= 0, "Expected non-NULL item\n");
1108 hglobal
= create_poke();
1110 /* WM_DDE_POKE, no ddepoke */
1111 lparam
= PackDDElParam(WM_DDE_POKE
, 0, item
);
1112 /* win9x returns 0 here and crashes in PostMessageA */
1114 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1118 win_skip("no lparam for WM_DDE_POKE\n");
1121 /* WM_DDE_POKE, no item */
1122 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, 0);
1123 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1127 hglobal
= create_poke();
1129 /* WM_DDE_POKE, no client hwnd */
1130 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1131 PostMessageA(server_hwnd
, WM_DDE_POKE
, 0, lparam
);
1135 /* WM_DDE_POKE, all params correct */
1136 lparam
= PackDDElParam(WM_DDE_POKE
, (UINT_PTR
)hglobal
, item
);
1137 PostMessageA(server_hwnd
, WM_DDE_POKE
, (WPARAM
)client_hwnd
, lparam
);
1141 execute_hglobal
= create_execute("[Command(Var)]");
1143 /* WM_DDE_EXECUTE, no lparam */
1144 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, 0);
1148 /* WM_DDE_EXECUTE, no hglobal */
1149 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, 0);
1150 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1154 /* WM_DDE_EXECUTE, no client hwnd */
1155 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1156 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, 0, lparam
);
1160 /* WM_DDE_EXECUTE, all params correct */
1161 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1162 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1166 GlobalFree(execute_hglobal
);
1167 execute_hglobal
= create_execute("[Command-2(Var)]");
1169 /* WM_DDE_EXECUTE, all params correct */
1170 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1171 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1175 GlobalFree(execute_hglobal
);
1176 execute_hglobal
= create_execute("[BadCommand(Var)]");
1178 /* WM_DDE_EXECUTE that will get rejected */
1179 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0, (UINT_PTR
)execute_hglobal
);
1180 PostMessageA(server_hwnd
, WM_DDE_EXECUTE
, (WPARAM
)client_hwnd
, lparam
);
1184 destroy_dde_window(&client_hwnd
, "dde_client");
1187 static LRESULT WINAPI
hook_dde_client_wndprocA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1191 trace("hook_dde_client_wndprocA: %p %04x %08lx %08lx\n", hwnd
, msg
, wparam
, lparam
);
1196 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1197 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo
, (HGLOBAL
)hi
);
1203 return CallWindowProcA(old_dde_client_wndproc
, hwnd
, msg
, wparam
, lparam
);
1206 static LRESULT WINAPI
hook_dde_client_wndprocW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1210 trace("hook_dde_client_wndprocW: %p %04x %08lx %08lx\n", hwnd
, msg
, wparam
, lparam
);
1215 UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
1216 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo
, (HGLOBAL
)hi
);
1222 return CallWindowProcW(old_dde_client_wndproc
, hwnd
, msg
, wparam
, lparam
);
1225 static LRESULT WINAPI
dde_server_wndprocA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1227 static BOOL client_unicode
, conv_unicode
;
1232 case WM_DDE_INITIATE
:
1234 ATOM aService
= GlobalAddAtomW(TEST_DDE_SERVICE
);
1236 trace("server A: got WM_DDE_INITIATE from %p (%s) with %08lx\n",
1237 (HWND
)wparam
, client_unicode
? "Unicode" : "ANSI", lparam
);
1239 if (LOWORD(lparam
) == aService
)
1241 client_unicode
= IsWindowUnicode((HWND
)wparam
);
1242 conv_unicode
= client_unicode
;
1243 if (step
>= 10) client_unicode
= !client_unicode
; /* change the client window type */
1246 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrW((HWND
)wparam
, GWLP_WNDPROC
,
1247 (ULONG_PTR
)hook_dde_client_wndprocW
);
1249 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrA((HWND
)wparam
, GWLP_WNDPROC
,
1250 (ULONG_PTR
)hook_dde_client_wndprocA
);
1251 trace("server: sending WM_DDE_ACK to %p\n", (HWND
)wparam
);
1252 SendMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, PackDDElParam(WM_DDE_ACK
, aService
, 0));
1255 GlobalDeleteAtom(aService
);
1259 case WM_DDE_EXECUTE
:
1266 trace("server A: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1268 UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1269 trace("%08lx => lo %04lx hi %04lx\n", lparam
, lo
, hi
);
1271 ack
.bAppReturnCode
= 0;
1274 /* We have to send a negative acknowledge even if we don't
1275 * accept the command, otherwise Windows goes mad and next time
1276 * we send an acknowledge DDEML drops the connection.
1277 * Not sure how to call it: a bug or a feature.
1281 if ((cmd
= GlobalLock((HGLOBAL
)hi
)))
1283 ack
.fAck
= !lstrcmpA(cmd
, exec_cmdA
) || !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
);
1287 case 0: /* bad command */
1288 trace( "server A got unhandled command\n" );
1291 case 1: /* ANSI command */
1293 ok( !lstrcmpA(cmd
, exec_cmdA
), "server A got wrong command '%s'\n", cmd
);
1294 else /* we get garbage as the A command was mapped W->A */
1295 ok( cmd
[0] != exec_cmdA
[0], "server A got wrong command '%s'\n", cmd
);
1298 case 2: /* ANSI command in Unicode format */
1300 ok( !lstrcmpA(cmd
, exec_cmdA
), "server A got wrong command '%s'\n", cmd
);
1302 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server A got wrong command '%s'\n", cmd
);
1305 case 3: /* Unicode command */
1307 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server A got wrong command '%s'\n", cmd
);
1308 else /* correctly mapped W->A */
1309 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server A got wrong command '%s'\n", cmd
);
1312 case 4: /* Unicode command in ANSI format */
1314 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server A got wrong command '%s'\n", cmd
);
1315 else /* we get garbage as the A command was mapped W->A */
1316 ok( cmd
[0] != exec_cmdWA
[0], "server A got wrong command '%s'\n", cmd
);
1319 GlobalUnlock((HGLOBAL
)hi
);
1321 else ok( 0, "bad command data %lx\n", hi
);
1324 trace("server A: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1326 status
= *((WORD
*)&ack
);
1327 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, status
, hi
);
1329 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1333 case WM_DDE_TERMINATE
:
1338 trace("server A: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1340 ack
.bAppReturnCode
= 0;
1345 trace("server A: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1347 status
= *((WORD
*)&ack
);
1348 lparam
= PackDDElParam(WM_DDE_ACK
, status
, 0);
1350 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1358 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1361 static LRESULT WINAPI
dde_server_wndprocW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1363 static BOOL client_unicode
, conv_unicode
;
1368 case WM_DDE_INITIATE
:
1370 ATOM aService
= GlobalAddAtomW(TEST_DDE_SERVICE
);
1372 if (LOWORD(lparam
) == aService
)
1374 client_unicode
= IsWindowUnicode((HWND
)wparam
);
1375 conv_unicode
= client_unicode
;
1376 if (step
>= 10) client_unicode
= !client_unicode
; /* change the client window type */
1379 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrW((HWND
)wparam
, GWLP_WNDPROC
,
1380 (ULONG_PTR
)hook_dde_client_wndprocW
);
1382 old_dde_client_wndproc
= (WNDPROC
)SetWindowLongPtrA((HWND
)wparam
, GWLP_WNDPROC
,
1383 (ULONG_PTR
)hook_dde_client_wndprocA
);
1384 trace("server W: sending WM_DDE_ACK to %p\n", (HWND
)wparam
);
1385 SendMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, PackDDElParam(WM_DDE_ACK
, aService
, 0));
1388 GlobalDeleteAtom(aService
);
1390 trace("server W: got WM_DDE_INITIATE from %p with %08lx (client %s conv %s)\n", (HWND
)wparam
,
1391 lparam
, client_unicode
? "Unicode" : "ANSI", conv_unicode
? "Unicode" : "ANSI" );
1396 case WM_DDE_EXECUTE
:
1403 trace("server W: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1405 UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
1406 trace("%08lx => lo %04lx hi %04lx\n", lparam
, lo
, hi
);
1408 ack
.bAppReturnCode
= 0;
1411 /* We have to send a negative acknowledge even if we don't
1412 * accept the command, otherwise Windows goes mad and next time
1413 * we send an acknowledge DDEML drops the connection.
1414 * Not sure how to call it: a bug or a feature.
1418 if ((cmd
= GlobalLock((HGLOBAL
)hi
)))
1420 ack
.fAck
= !lstrcmpA(cmd
, exec_cmdA
) || !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
);
1424 case 0: /* bad command */
1425 trace( "server W got unhandled command\n" );
1428 case 1: /* ANSI command */
1429 if (conv_unicode
&& !client_unicode
) /* W->A mapping -> garbage */
1430 ok( cmd
[0] != exec_cmdA
[0], "server W got wrong command '%s'\n", cmd
);
1431 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1432 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server W got wrong command '%s'\n", cmd
);
1434 ok( !lstrcmpA(cmd
, exec_cmdA
), "server W got wrong command '%s'\n", cmd
);
1437 case 2: /* ANSI command in Unicode format */
1438 if (conv_unicode
&& !client_unicode
) /* W->A mapping */
1439 ok( !lstrcmpA(cmd
, exec_cmdA
), "server W got wrong command '%s'\n", cmd
);
1440 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1441 ok( *(WCHAR
*)cmd
== exec_cmdAW
[0], "server W got wrong command '%s'\n", cmd
);
1443 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdAW
), "server W got wrong command '%s'\n", cmd
);
1446 case 3: /* Unicode command */
1447 if (conv_unicode
&& !client_unicode
) /* W->A mapping */
1448 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server W got wrong command '%s'\n", cmd
);
1449 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1450 ok( *(WCHAR
*)cmd
== exec_cmdW
[0], "server W got wrong command '%s'\n", cmd
);
1452 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server W got wrong command '%s'\n", cmd
);
1455 case 4: /* Unicode command in ANSI format */
1456 if (conv_unicode
&& !client_unicode
) /* W->A mapping -> garbage */
1457 ok( cmd
[0] != exec_cmdWA
[0], "server W got wrong command '%s'\n", cmd
);
1458 else if (!conv_unicode
&& client_unicode
) /* A->W mapping */
1459 ok( !lstrcmpW((LPCWSTR
)cmd
, exec_cmdW
), "server W got wrong command '%s'\n", cmd
);
1461 ok( !lstrcmpA(cmd
, exec_cmdWA
), "server W got wrong command '%s'\n", cmd
);
1464 GlobalUnlock((HGLOBAL
)hi
);
1466 else ok( 0, "bad command data %lx\n", hi
);
1469 trace("server W: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1471 status
= *((WORD
*)&ack
);
1472 lparam
= ReuseDDElParam(lparam
, WM_DDE_EXECUTE
, WM_DDE_ACK
, status
, hi
);
1474 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1478 case WM_DDE_TERMINATE
:
1483 trace("server W: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND
)wparam
, lparam
);
1485 ack
.bAppReturnCode
= 0;
1490 trace("server W: posting %s WM_DDE_ACK to %p\n", ack
.fAck
? "POSITIVE" : "NEGATIVE", (HWND
)wparam
);
1492 status
= *((WORD
*)&ack
);
1493 lparam
= PackDDElParam(WM_DDE_ACK
, status
, 0);
1495 PostMessageW((HWND
)wparam
, WM_DDE_ACK
, (WPARAM
)hwnd
, lparam
);
1503 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
1506 static HWND
create_dde_server( BOOL unicode
)
1511 static const char server_class_nameA
[] = "dde_server_windowA";
1512 static const WCHAR server_class_nameW
[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w','W',0};
1516 memset(&wcW
, 0, sizeof(wcW
));
1517 wcW
.lpfnWndProc
= dde_server_wndprocW
;
1518 wcW
.lpszClassName
= server_class_nameW
;
1519 wcW
.hInstance
= GetModuleHandleA(0);
1520 RegisterClassW(&wcW
);
1522 server
= CreateWindowExW(0, server_class_nameW
, NULL
, WS_POPUP
,
1523 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1524 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
1528 memset(&wcA
, 0, sizeof(wcA
));
1529 wcA
.lpfnWndProc
= dde_server_wndprocA
;
1530 wcA
.lpszClassName
= server_class_nameA
;
1531 wcA
.hInstance
= GetModuleHandleA(0);
1532 RegisterClassA(&wcA
);
1534 server
= CreateWindowExA(0, server_class_nameA
, NULL
, WS_POPUP
,
1535 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1536 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL
);
1538 ok(!IsWindowUnicode(server
) == !unicode
, "wrong unicode type\n");
1542 static HDDEDATA CALLBACK
client_dde_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
1543 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
1544 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
1546 static const char * const cmd_type
[15] = {
1547 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1548 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1549 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1550 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1552 const char *cmd_name
;
1554 type
= (uType
& XTYP_MASK
) >> XTYP_SHIFT
;
1555 cmd_name
= (type
<= 14) ? cmd_type
[type
] : "unknown";
1557 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1558 uType
, cmd_name
, uFmt
, hconv
, hsz1
, hsz2
, hdata
, dwData1
, dwData2
);
1562 static void test_dde_aw_transaction( BOOL client_unicode
, BOOL server_unicode
)
1565 DWORD dde_inst
, ret
, err
;
1570 BOOL conv_unicode
= client_unicode
;
1572 static char test_cmd
[] = "test dde command";
1574 if (!(hwnd_server
= create_dde_server( server_unicode
))) return;
1578 ret
= DdeInitializeW(&dde_inst
, client_dde_callback
, APPCMD_CLIENTONLY
, 0);
1580 ret
= DdeInitializeA(&dde_inst
, client_dde_callback
, APPCMD_CLIENTONLY
, 0);
1581 ok(ret
== DMLERR_NO_ERROR
, "DdeInitializeA failed with error %04x (%x)\n",
1582 ret
, DdeGetLastError(dde_inst
));
1584 hsz_server
= DdeCreateStringHandleW(dde_inst
, TEST_DDE_SERVICE
, CP_WINUNICODE
);
1586 hconv
= DdeConnect(dde_inst
, hsz_server
, 0, NULL
);
1587 ok(hconv
!= 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst
));
1588 err
= DdeGetLastError(dde_inst
);
1589 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1591 info
.cb
= sizeof(info
);
1592 ret
= DdeQueryConvInfo(hconv
, QID_SYNC
, &info
);
1593 ok(ret
, "wrong info size %d, DdeQueryConvInfo error %x\n", ret
, DdeGetLastError(dde_inst
));
1594 ok(info
.ConvCtxt
.iCodePage
== (client_unicode
? CP_WINUNICODE
: CP_WINANSI
),
1595 "wrong iCodePage %d\n", info
.ConvCtxt
.iCodePage
);
1596 ok(!info
.hConvPartner
, "unexpected info.hConvPartner: %p\n", info
.hConvPartner
);
1598 ok((info
.wStatus
& DDE_FACK
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1600 ok((info
.wStatus
& (ST_CONNECTED
| ST_CLIENT
)) == (ST_CONNECTED
| ST_CLIENT
), "unexpected info.wStatus: %04x\n", info
.wStatus
);
1601 ok(info
.wConvst
== XST_CONNECTED
, "unexpected info.wConvst: %04x\n", info
.wConvst
);
1602 ok(info
.wType
== 0, "unexpected info.wType: %04x\n", info
.wType
);
1604 client_unicode
= IsWindowUnicode( info
.hwnd
);
1605 trace("hwnd %p, hwndPartner %p, unicode %u\n", info
.hwnd
, info
.hwndPartner
, client_unicode
);
1607 trace("sending test client transaction command\n");
1609 hdata
= DdeClientTransaction((LPBYTE
)test_cmd
, strlen(test_cmd
) + 1, hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
1610 ok(!hdata
, "DdeClientTransaction succeeded\n");
1611 ok(ret
== DDE_FNOTPROCESSED
|| broken(ret
== (0xdead0000 | DDE_FNOTPROCESSED
)), /* win9x */
1612 "wrong status code %04x\n", ret
);
1613 err
= DdeGetLastError(dde_inst
);
1614 ok(err
== DMLERR_NOTPROCESSED
, "wrong dde error %x\n", err
);
1616 trace("sending ANSI client transaction command\n");
1618 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdA
, lstrlenA(exec_cmdA
) + 1, hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1619 err
= DdeGetLastError(dde_inst
);
1620 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> garbage */
1622 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1623 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1624 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1626 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> wrong cmd */
1628 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1629 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1630 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1632 else /* no mapping */
1634 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1635 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1636 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1639 trace("sending ANSI-as-Unicode client transaction command\n");
1641 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdAW
, (lstrlenW(exec_cmdAW
) + 1) * sizeof(WCHAR
),
1642 hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1643 err
= DdeGetLastError(dde_inst
);
1644 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping */
1646 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1647 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1648 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1650 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> garbage */
1652 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1653 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1654 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1656 else /* no mapping */
1658 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1659 ok(ret
== DDE_FNOTPROCESSED
|| broken(ret
== (0xdead0000 | DDE_FNOTPROCESSED
)), /* win9x */
1660 "wrong status code %04x\n", ret
);
1661 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1664 trace("sending unicode client transaction command\n");
1666 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdW
, (lstrlenW(exec_cmdW
) + 1) * sizeof(WCHAR
), hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1667 err
= DdeGetLastError(dde_inst
);
1668 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> wrong cmd */
1670 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1671 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1672 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1674 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping -> garbage */
1676 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1677 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1678 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1680 else /* no mapping */
1682 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1683 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1684 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1687 trace("sending Unicode-as-ANSI client transaction command\n");
1689 hdata
= DdeClientTransaction((LPBYTE
)exec_cmdWA
, lstrlenA(exec_cmdWA
) + 1, hconv
, 0, 0, XTYP_EXECUTE
, 1000, &ret
);
1690 err
= DdeGetLastError(dde_inst
);
1691 if (conv_unicode
&& (!client_unicode
|| !server_unicode
)) /* W->A mapping -> garbage */
1693 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1694 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1695 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1697 else if (!conv_unicode
&& client_unicode
&& server_unicode
) /* A->W mapping */
1699 ok(hdata
!= 0, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1700 ok(ret
== DDE_FACK
, "wrong status code %04x\n", ret
);
1701 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
1703 else /* no mapping */
1705 ok(!hdata
, "DdeClientTransaction returned %p, error %x\n", hdata
, err
);
1706 ok(ret
== DDE_FNOTPROCESSED
, "wrong status code %04x\n", ret
);
1707 ok(err
== DMLERR_NOTPROCESSED
, "DdeClientTransaction returned error %x\n", err
);
1710 got
= DdeDisconnect(hconv
);
1711 ok(got
, "DdeDisconnect error %x\n", DdeGetLastError(dde_inst
));
1713 info
.cb
= sizeof(info
);
1714 ret
= DdeQueryConvInfo(hconv
, QID_SYNC
, &info
);
1715 ok(!ret
, "DdeQueryConvInfo should fail\n");
1716 err
= DdeGetLastError(dde_inst
);
1718 ok(err
== DMLERR_INVALIDPARAMETER
, "wrong dde error %x\n", err
);
1721 got
= DdeFreeStringHandle(dde_inst
, hsz_server
);
1722 ok(got
, "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst
));
1724 /* This call hangs on win2k SP4 and XP SP1.
1725 DdeUninitialize(dde_inst);*/
1727 DestroyWindow(hwnd_server
);
1730 static void test_initialisation(void)
1735 HSZ server
, topic
, item
;
1739 /* Initialise without a valid server window. */
1741 ret
= DdeInitializeA(&client_pid
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1742 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", ret
);
1745 server
= DdeCreateStringHandleA(client_pid
, "TestDDEService", CP_WINANSI
);
1746 topic
= DdeCreateStringHandleA(client_pid
, "TestDDETopic", CP_WINANSI
);
1748 DdeGetLastError(client_pid
);
1750 /* There is no server window so no conversation can be extracted */
1751 conversation
= DdeConnect(client_pid
, server
, topic
, NULL
);
1752 ok(conversation
== NULL
, "Expected NULL conversation, %p\n", conversation
);
1753 ret
= DdeGetLastError(client_pid
);
1754 ok(ret
== DMLERR_NO_CONV_ESTABLISHED
, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret
);
1756 DdeFreeStringHandle(client_pid
, server
);
1758 item
= DdeCreateStringHandleA(client_pid
, "request", CP_WINANSI
);
1760 /* There is no conversation so an invalid parameter results */
1762 DdeGetLastError(client_pid
);
1763 hdata
= DdeClientTransaction(NULL
, 0, conversation
, item
, CF_TEXT
, XTYP_REQUEST
, default_timeout
, &res
);
1764 ok(hdata
== NULL
, "Expected NULL, got %p\n", hdata
);
1765 ret
= DdeGetLastError(client_pid
);
1767 ok(ret
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret
);
1768 ok(res
== 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res
);
1770 DdeFreeStringHandle(client_pid
, server
);
1771 ret
= DdeDisconnect(conversation
);
1772 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
1774 ret
= DdeUninitialize(client_pid
);
1775 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1778 static void test_DdeCreateStringHandleW(DWORD dde_inst
, int codepage
)
1780 static const WCHAR dde_string
[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1787 str_handle
= DdeCreateStringHandleW(dde_inst
, dde_string
, codepage
);
1788 ok(str_handle
!= 0, "DdeCreateStringHandleW failed with error %08x\n",
1789 DdeGetLastError(dde_inst
));
1791 ret
= DdeQueryStringW(dde_inst
, str_handle
, NULL
, 0, codepage
);
1792 if (codepage
== CP_WINANSI
)
1793 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1795 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1797 ret
= DdeQueryStringW(dde_inst
, str_handle
, bufW
, 256, codepage
);
1798 if (codepage
== CP_WINANSI
)
1800 ok(ret
== 1, "DdeQueryStringW returned wrong length %d\n", ret
);
1801 ok(!lstrcmpA("D", (LPCSTR
)bufW
), "DdeQueryStringW returned wrong string\n");
1805 ok(ret
== lstrlenW(dde_string
), "DdeQueryStringW returned wrong length %d\n", ret
);
1806 ok(!lstrcmpW(dde_string
, bufW
), "DdeQueryStringW returned wrong string\n");
1809 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINANSI
);
1810 if (codepage
== CP_WINANSI
)
1812 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1813 ok(!lstrcmpA("D", buf
), "DdeQueryStringW returned wrong string\n");
1817 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1818 ok(!lstrcmpA("DDE String", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1821 ret
= DdeQueryStringA(dde_inst
, str_handle
, buf
, 256, CP_WINUNICODE
);
1822 if (codepage
== CP_WINANSI
)
1824 ok(ret
== 1, "DdeQueryStringA returned wrong length %d\n", ret
);
1825 ok(!lstrcmpA("D", buf
), "DdeQueryStringA returned wrong string %s\n", buf
);
1829 ok(ret
== lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret
);
1830 ok(!lstrcmpW(dde_string
, (LPCWSTR
)buf
), "DdeQueryStringW returned wrong string\n");
1833 if (codepage
== CP_WINANSI
)
1835 atom
= FindAtomA((LPSTR
)dde_string
);
1836 ok(atom
!= 0, "Expected a valid atom\n");
1838 SetLastError(0xdeadbeef);
1839 atom
= GlobalFindAtomA((LPSTR
)dde_string
);
1840 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1841 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1842 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1846 atom
= FindAtomW(dde_string
);
1847 ok(atom
!= 0, "Expected a valid atom\n");
1849 SetLastError(0xdeadbeef);
1850 atom
= GlobalFindAtomW(dde_string
);
1851 ok(atom
== 0, "Expected 0, got %d\n", atom
);
1852 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
1853 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1856 ok(DdeFreeStringHandle(dde_inst
, str_handle
), "DdeFreeStringHandle failed\n");
1859 static void test_DdeCreateDataHandle(void)
1862 DWORD dde_inst
, dde_inst2
;
1868 WCHAR item_str
[] = {'i','t','e','m',0};
1872 res
= DdeInitializeA(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1873 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1875 res
= DdeInitializeA(&dde_inst2
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
1876 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
1879 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1880 * is invalid then the lastError of all instances is set to the error. There are two instances
1881 * created, lastError is cleared, an error is generated and then both instances are checked to
1882 * ensure that they both have the same error set
1884 item
= DdeCreateStringHandleA(0, "item", CP_WINANSI
);
1885 ok(item
== NULL
, "Expected NULL hsz got %p\n", item
);
1886 err
= DdeGetLastError(dde_inst
);
1887 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1888 err
= DdeGetLastError(dde_inst2
);
1889 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1890 item
= DdeCreateStringHandleW(0, item_str
, CP_WINUNICODE
);
1891 ok(item
== NULL
, "Expected NULL hsz got %p\n", item
);
1892 err
= DdeGetLastError(dde_inst
);
1893 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1894 err
= DdeGetLastError(dde_inst2
);
1895 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1897 item
= DdeCreateStringHandleA(dde_inst
, "item", CP_WINANSI
);
1898 ok(item
!= NULL
, "Expected non-NULL hsz\n");
1899 item
= DdeCreateStringHandleA(dde_inst2
, "item", CP_WINANSI
);
1900 ok(item
!= NULL
, "Expected non-NULL hsz\n");
1903 /* do not test with an invalid instance id: that crashes on win9x */
1904 hdata
= DdeCreateDataHandle(0xdeadbeef, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1908 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1909 * is invalid then the lastError of all instances is set to the error. There are two instances
1910 * created, lastError is cleared, an error is generated and then both instances are checked to
1911 * ensure that they both have the same error set
1913 DdeGetLastError(dde_inst
);
1914 DdeGetLastError(dde_inst2
);
1915 hdata
= DdeCreateDataHandle(0, (LPBYTE
)"data", MAX_PATH
, 0, item
, CF_TEXT
, 0);
1916 err
= DdeGetLastError(dde_inst
);
1917 ok(hdata
== NULL
, "Expected NULL, got %p\n", hdata
);
1918 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1919 err
= DdeGetLastError(dde_inst2
);
1920 ok(err
== DMLERR_INVALIDPARAMETER
, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err
);
1922 ret
= DdeUninitialize(dde_inst2
);
1923 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1927 DdeGetLastError(dde_inst
);
1928 hdata
= DdeCreateDataHandle(dde_inst
, NULL
, MAX_PATH
, 0, item
, CF_TEXT
, 0);
1929 err
= DdeGetLastError(dde_inst
);
1930 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1931 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1933 ptr
= DdeAccessData(hdata
, &size
);
1934 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1935 ok(size
== 260, "Expected 260, got %d\n", size
);
1937 ret
= DdeUnaccessData(hdata
);
1938 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1940 ret
= DdeFreeDataHandle(hdata
);
1941 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1944 DdeGetLastError(dde_inst
);
1945 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", 0, 0, item
, CF_TEXT
, 0);
1946 err
= DdeGetLastError(dde_inst
);
1947 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1948 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1950 ptr
= DdeAccessData(hdata
, &size
);
1951 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1952 ok(size
== 0, "Expected 0, got %d\n", size
);
1954 ret
= DdeUnaccessData(hdata
);
1955 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1957 ret
= DdeFreeDataHandle(hdata
);
1958 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1960 /* cbOff is non-zero */
1961 DdeGetLastError(dde_inst
);
1962 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 2, item
, CF_TEXT
, 0);
1963 err
= DdeGetLastError(dde_inst
);
1964 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1965 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1967 ptr
= DdeAccessData(hdata
, &size
);
1968 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1969 ok(size
== 262, "Expected 262, got %d\n", size
);
1972 ok(lstrlenA((LPSTR
)ptr
) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR
)ptr
));
1975 ret
= DdeUnaccessData(hdata
);
1976 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1978 ret
= DdeFreeDataHandle(hdata
);
1979 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1982 DdeGetLastError(dde_inst
);
1983 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, 0, CF_TEXT
, 0);
1984 err
= DdeGetLastError(dde_inst
);
1985 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
1986 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
1988 ptr
= DdeAccessData(hdata
, &size
);
1989 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
1990 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
1991 ok(size
== 260, "Expected 260, got %d\n", size
);
1993 ret
= DdeUnaccessData(hdata
);
1994 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
1996 ret
= DdeFreeDataHandle(hdata
);
1997 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2000 DdeGetLastError(dde_inst
);
2001 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, (HSZ
)0xdeadbeef, CF_TEXT
, 0);
2002 err
= DdeGetLastError(dde_inst
);
2003 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
2004 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
2006 ptr
= DdeAccessData(hdata
, &size
);
2007 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2008 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
2009 ok(size
== 260, "Expected 260, got %d\n", size
);
2011 ret
= DdeUnaccessData(hdata
);
2012 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2014 ret
= DdeFreeDataHandle(hdata
);
2015 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2017 /* invalid clipboard format */
2018 DdeGetLastError(dde_inst
);
2019 hdata
= DdeCreateDataHandle(dde_inst
, (LPBYTE
)"data", MAX_PATH
, 0, item
, 0xdeadbeef, 0);
2020 err
= DdeGetLastError(dde_inst
);
2021 ok(hdata
!= NULL
, "Expected non-NULL hdata\n");
2022 ok(err
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", err
);
2024 ptr
= DdeAccessData(hdata
, &size
);
2025 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2026 ok(!lstrcmpA((LPSTR
)ptr
, "data"), "Expected data, got %s\n", ptr
);
2027 ok(size
== 260, "Expected 260, got %d\n", size
);
2029 ret
= DdeUnaccessData(hdata
);
2030 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2032 ret
= DdeFreeDataHandle(hdata
);
2033 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2035 ret
= DdeUninitialize(dde_inst
);
2036 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2039 static void test_DdeCreateStringHandle(void)
2041 DWORD dde_inst
, ret
;
2043 dde_inst
= 0xdeadbeef;
2044 SetLastError(0xdeadbeef);
2045 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2046 ok(ret
== DMLERR_INVALIDPARAMETER
, "DdeInitializeW should fail, but got %04x instead\n", ret
);
2047 ok(DdeGetLastError(dde_inst
) == DMLERR_INVALIDPARAMETER
, "expected DMLERR_INVALIDPARAMETER\n");
2050 ret
= DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2051 ok(ret
== DMLERR_NO_ERROR
, "DdeInitializeW failed with error %04x (%08x)\n",
2052 ret
, DdeGetLastError(dde_inst
));
2054 test_DdeCreateStringHandleW(dde_inst
, 0);
2055 test_DdeCreateStringHandleW(dde_inst
, CP_WINUNICODE
);
2056 test_DdeCreateStringHandleW(dde_inst
, CP_WINANSI
);
2058 ok(DdeUninitialize(dde_inst
), "DdeUninitialize failed\n");
2061 static void test_FreeDDElParam(void)
2063 HGLOBAL val
, hglobal
;
2066 ret
= FreeDDElParam(WM_DDE_INITIATE
, 0);
2067 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2069 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2070 ret
= FreeDDElParam(WM_DDE_INITIATE
, (LPARAM
)hglobal
);
2071 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2072 val
= GlobalFree(hglobal
);
2073 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2075 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2076 ret
= FreeDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
);
2077 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2079 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2080 ret
= FreeDDElParam(WM_DDE_UNADVISE
, (LPARAM
)hglobal
);
2081 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2082 val
= GlobalFree(hglobal
);
2083 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2085 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2086 ret
= FreeDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
);
2087 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2089 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2090 ret
= FreeDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
);
2091 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2093 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2094 ret
= FreeDDElParam(WM_DDE_REQUEST
, (LPARAM
)hglobal
);
2095 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2096 val
= GlobalFree(hglobal
);
2097 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2099 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2100 ret
= FreeDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
);
2101 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2103 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 100);
2104 ret
= FreeDDElParam(WM_DDE_EXECUTE
, (LPARAM
)hglobal
);
2105 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2106 val
= GlobalFree(hglobal
);
2107 ok(val
== NULL
, "Expected NULL, got %p\n", val
);
2110 static void test_PackDDElParam(void)
2112 UINT_PTR lo
, hi
, *ptr
;
2116 lparam
= PackDDElParam(WM_DDE_INITIATE
, 0xcafe, 0xbeef);
2117 /* value gets sign-extended despite being an LPARAM */
2118 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2121 ret
= UnpackDDElParam(WM_DDE_INITIATE
, lparam
, &lo
, &hi
);
2122 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2123 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2124 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2126 ret
= FreeDDElParam(WM_DDE_INITIATE
, lparam
);
2127 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2129 lparam
= PackDDElParam(WM_DDE_TERMINATE
, 0xcafe, 0xbeef);
2130 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2133 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, lparam
, &lo
, &hi
);
2134 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2135 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2136 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2138 ret
= FreeDDElParam(WM_DDE_TERMINATE
, lparam
);
2139 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2141 lparam
= PackDDElParam(WM_DDE_ADVISE
, 0xcafe, 0xbeef);
2142 /* win9x returns 0 here */
2144 ptr
= GlobalLock((HGLOBAL
)lparam
);
2145 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2146 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2147 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2149 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2150 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2153 ret
= UnpackDDElParam(WM_DDE_ADVISE
, lparam
, &lo
, &hi
);
2154 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2155 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2156 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2159 win_skip("no lparam for WM_DDE_ADVISE\n");
2161 ret
= FreeDDElParam(WM_DDE_ADVISE
, lparam
);
2162 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2164 lparam
= PackDDElParam(WM_DDE_UNADVISE
, 0xcafe, 0xbeef);
2165 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2168 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, lparam
, &lo
, &hi
);
2169 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2170 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2171 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2173 ret
= FreeDDElParam(WM_DDE_UNADVISE
, lparam
);
2174 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2176 lparam
= PackDDElParam(WM_DDE_ACK
, 0xcafe, 0xbeef);
2177 /* win9x returns the input (0xbeef<<16 | 0xcafe) here */
2178 if (lparam
!= (int)0xbeefcafe) {
2179 ptr
= GlobalLock((HGLOBAL
)lparam
);
2180 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2181 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2182 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2184 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2185 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2188 ret
= UnpackDDElParam(WM_DDE_ACK
, lparam
, &lo
, &hi
);
2189 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2190 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2191 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2193 ret
= FreeDDElParam(WM_DDE_ACK
, lparam
);
2194 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2197 win_skip("got lparam 0x%lx for WM_DDE_ACK\n", lparam
);
2199 lparam
= PackDDElParam(WM_DDE_DATA
, 0xcafe, 0xbeef);
2200 /* win9x returns 0 here */
2202 ptr
= GlobalLock((HGLOBAL
)lparam
);
2203 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2204 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2205 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2207 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2208 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2211 ret
= UnpackDDElParam(WM_DDE_DATA
, lparam
, &lo
, &hi
);
2212 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2213 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2214 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2217 win_skip("no lparam for WM_DDE_DATA\n");
2219 ret
= FreeDDElParam(WM_DDE_DATA
, lparam
);
2220 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2222 lparam
= PackDDElParam(WM_DDE_REQUEST
, 0xcafe, 0xbeef);
2223 ok(lparam
== (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam
);
2226 ret
= UnpackDDElParam(WM_DDE_REQUEST
, lparam
, &lo
, &hi
);
2227 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2228 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2229 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2231 ret
= FreeDDElParam(WM_DDE_REQUEST
, lparam
);
2232 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2234 lparam
= PackDDElParam(WM_DDE_POKE
, 0xcafe, 0xbeef);
2235 /* win9x returns 0 here */
2237 ptr
= GlobalLock((HGLOBAL
)lparam
);
2238 ok(ptr
!= NULL
, "Expected non-NULL ptr\n");
2239 ok(ptr
[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr
[0]);
2240 ok(ptr
[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr
[1]);
2242 ret
= GlobalUnlock((HGLOBAL
)lparam
);
2243 ok(ret
== 1, "Expected 1, got %d\n", ret
);
2246 ret
= UnpackDDElParam(WM_DDE_POKE
, lparam
, &lo
, &hi
);
2247 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2248 ok(lo
== 0xcafe, "Expected 0xcafe, got %08lx\n", lo
);
2249 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2252 win_skip("no lparam for WM_DDE_POKE\n");
2254 ret
= FreeDDElParam(WM_DDE_POKE
, lparam
);
2255 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2257 lparam
= PackDDElParam(WM_DDE_EXECUTE
, 0xcafe, 0xbeef);
2258 ok(lparam
== 0xbeef, "Expected 0xbeef, got %08lx\n", lparam
);
2261 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, lparam
, &lo
, &hi
);
2262 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2263 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2264 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2266 ret
= FreeDDElParam(WM_DDE_EXECUTE
, lparam
);
2267 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2270 static void test_UnpackDDElParam(void)
2272 UINT_PTR lo
, hi
, *ptr
;
2279 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0, &lo
, &hi
);
2280 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2281 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2282 ok(hi
== 0, "Expected 0, got %08lx\n", hi
);
2287 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, NULL
, &hi
);
2288 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2289 ok(lo
== 0xdead, "Expected 0xdead, got %08lx\n", lo
);
2290 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2295 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, NULL
);
2296 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2297 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2298 ok(hi
== 0xbeef, "Expected 0xbeef, got %08lx\n", hi
);
2302 ret
= UnpackDDElParam(WM_DDE_INITIATE
, 0xcafebabe, &lo
, &hi
);
2303 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2304 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2305 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2309 ret
= UnpackDDElParam(WM_DDE_TERMINATE
, 0xcafebabe, &lo
, &hi
);
2310 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2311 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2312 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2316 ret
= UnpackDDElParam(WM_DDE_ADVISE
, 0, &lo
, &hi
);
2317 ok(ret
== FALSE
, "Expected FALSE, got %d\n", ret
);
2319 broken(lo
== 0xdead), /* win2k */
2320 "Expected 0, got %08lx\n", lo
);
2322 broken(hi
== 0xbeef), /* win2k */
2323 "Expected 0, got %08lx\n", hi
);
2325 hglobal
= GlobalAlloc(GMEM_DDESHARE
, 2 * sizeof(*ptr
));
2326 ptr
= GlobalLock(hglobal
);
2327 ptr
[0] = 0xcafebabe;
2328 ptr
[1] = 0xdeadbeef;
2329 GlobalUnlock(hglobal
);
2333 ret
= UnpackDDElParam(WM_DDE_ADVISE
, (LPARAM
)hglobal
, &lo
, &hi
);
2334 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2335 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2336 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2340 ret
= UnpackDDElParam(WM_DDE_UNADVISE
, 0xcafebabe, &lo
, &hi
);
2341 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2342 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2343 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2347 ret
= UnpackDDElParam(WM_DDE_ACK
, (LPARAM
)hglobal
, &lo
, &hi
);
2348 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2349 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2350 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2354 ret
= UnpackDDElParam(WM_DDE_DATA
, (LPARAM
)hglobal
, &lo
, &hi
);
2355 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2356 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2357 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2361 ret
= UnpackDDElParam(WM_DDE_REQUEST
, 0xcafebabe, &lo
, &hi
);
2362 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2363 ok(lo
== 0xbabe, "Expected 0xbabe, got %08lx\n", lo
);
2364 ok(hi
== 0xcafe, "Expected 0xcafe, got %08lx\n", hi
);
2368 ret
= UnpackDDElParam(WM_DDE_POKE
, (LPARAM
)hglobal
, &lo
, &hi
);
2369 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2370 ok(lo
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo
);
2371 ok(hi
== 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi
);
2375 ret
= UnpackDDElParam(WM_DDE_EXECUTE
, 0xcafebabe, &lo
, &hi
);
2376 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2377 ok(lo
== 0, "Expected 0, got %08lx\n", lo
);
2378 ok(hi
== 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi
);
2380 GlobalFree(hglobal
);
2383 static char test_cmd_a_to_a
[] = "Test dde command";
2384 static WCHAR test_cmd_w_to_w
[][32] = {
2385 {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0},
2386 { 0x2018, 0x2019, 0x0161, 0x0041, 0x02dc, 0 }, /* some chars that should map properly to CP1252 */
2387 { 0x2026, 0x2020, 0x2021, 0x0d0a, 0 }, /* false negative for IsTextUnicode */
2388 { 0x4efa, 0x4efc, 0x0061, 0x4efe, 0 }, /* some Chinese chars */
2389 { 0x0061, 0x0062, 0x0063, 0x9152, 0 }, /* Chinese with latin characters begin */
2391 static const int nb_callbacks
= 5 + sizeof(test_cmd_w_to_w
)/sizeof(test_cmd_w_to_w
[0]);
2393 static HDDEDATA CALLBACK
server_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2394 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2395 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2399 static int msg_index
= 0;
2400 static HCONV conversation
= 0;
2401 static const char test_service
[] = "TestDDEService";
2402 static const char test_topic
[] = "TestDDETopic";
2410 ok(msg_index
% nb_callbacks
== 1, "Expected 1 modulo %u, got %d\n", nb_callbacks
, msg_index
);
2411 return (HDDEDATA
)TRUE
;
2416 ok(msg_index
% nb_callbacks
== 2, "Expected 2 modulo %u, got %d\n", nb_callbacks
, msg_index
);
2417 ok(uFmt
== 0, "Expected 0, got %d, msg_index=%d\n", uFmt
, msg_index
);
2418 ok(hconv
== 0, "Expected 0, got %p, msg_index=%d\n", hconv
, msg_index
);
2419 ok(hdata
== 0, "Expected 0, got %p, msg_index=%d\n", hdata
, msg_index
);
2420 ok(dwData1
!= 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1
, msg_index
);
2421 ok(dwData2
== FALSE
, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2
, msg_index
);
2423 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2424 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2425 test_topic
, str
, msg_index
);
2426 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2428 size
= DdeQueryStringA(server_pid
, hsz2
, str
, MAX_PATH
, CP_WINANSI
);
2429 ok(!lstrcmpA(str
, test_service
), "Expected %s, got %s, msg_index=%d\n",
2430 test_service
, str
, msg_index
);
2431 ok(size
== 14, "Expected 14, got %d, msg_index=%d\n", size
, msg_index
);
2433 return (HDDEDATA
) TRUE
;
2435 case XTYP_CONNECT_CONFIRM
:
2437 ok(msg_index
% nb_callbacks
== 3, "Expected 3 modulo %u, got %d\n", nb_callbacks
, msg_index
);
2438 conversation
= hconv
;
2439 return (HDDEDATA
) TRUE
;
2443 BYTE
*buffer
= NULL
;
2445 char test_cmd_w_to_a
[64];
2446 WCHAR test_cmd_a_to_w
[64];
2447 DWORD size_a
, size_w
, size_w_to_a
, size_a_to_w
;
2448 BOOL unicode_server
, unicode_client
, str_index
;
2450 ok(uFmt
== 0, "Expected 0, got %d\n", uFmt
);
2451 ok(hconv
== conversation
, "Expected conversation handle, got %p, msg_index=%d\n",
2453 ok(dwData1
== 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1
, msg_index
);
2454 ok(dwData2
== 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2
, msg_index
);
2455 ok(hsz2
== 0, "Expected 0, got %p, msg_index=%d\n", hsz2
, msg_index
);
2456 size
= DdeQueryStringA(server_pid
, hsz1
, str
, MAX_PATH
, CP_WINANSI
);
2457 ok(!lstrcmpA(str
, test_topic
), "Expected %s, got %s, msg_index=%d\n",
2458 test_topic
, str
, msg_index
);
2459 ok(size
== 12, "Expected 12, got %d, msg_index=%d\n", size
, msg_index
);
2461 size
= DdeGetData(hdata
, NULL
, 0, 0);
2462 ok((buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
)) != NULL
, "should not be null\n");
2463 rsize
= DdeGetData(hdata
, buffer
, size
, 0);
2464 ok(rsize
== size
, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2465 size
, rsize
, msg_index
);
2466 trace("msg %u strA \"%s\" strW %s\n", msg_index
, buffer
, wine_dbgstr_w((WCHAR
*)buffer
));
2468 unicode_server
= (msg_index
/ nb_callbacks
== 1 || msg_index
/ nb_callbacks
== 2);
2469 unicode_client
= (msg_index
/ nb_callbacks
== 1 || msg_index
/ nb_callbacks
== 3);
2470 str_index
= msg_index
% nb_callbacks
- 4;
2471 cmd_w
= test_cmd_w_to_w
[str_index
- 1];
2472 size_a
= strlen(test_cmd_a_to_a
) + 1;
2473 size_w
= (lstrlenW(cmd_w
) + 1) * sizeof(WCHAR
);
2474 size_a_to_w
= MultiByteToWideChar( CP_ACP
, 0, test_cmd_a_to_a
, -1, test_cmd_a_to_w
,
2475 sizeof(test_cmd_a_to_w
)/sizeof(WCHAR
) ) * sizeof(WCHAR
);
2476 size_w_to_a
= WideCharToMultiByte( CP_ACP
, 0, cmd_w
, -1,
2477 test_cmd_w_to_a
, sizeof(test_cmd_w_to_a
), NULL
, NULL
);
2480 case 0: /* ASCII string */
2483 ok(size
== size_a_to_w
, "Wrong size %d/%d, msg_index=%d\n", size
, size_a_to_w
, msg_index
);
2484 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_a_to_w
),
2485 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w
), msg_index
);
2487 else if (unicode_client
)
2489 /* ASCII string mapped W->A -> garbage */
2493 ok(size
== size_a
, "Wrong size %d/%d, msg_index=%d\n", size
, size_a
, msg_index
);
2494 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_a_to_a
), "Expected %s, got %s, msg_index=%d\n",
2495 test_cmd_a_to_a
, buffer
, msg_index
);
2499 case 1: /* Unicode string with only 8-bit chars */
2502 ok(size
== size_w
, "Wrong size %d/%d, msg_index=%d\n", size
, size_w
, msg_index
);
2503 ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2504 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), msg_index
);
2508 ok(size
== size_w_to_a
, "Wrong size %d/%d, msg_index=%d\n",
2509 size
, size_w_to_a
, msg_index
);
2510 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2511 test_cmd_w_to_a
, buffer
, msg_index
);
2515 case 2: /* normal Unicode string */
2516 case 3: /* IsTextUnicode false negative */
2517 case 4: /* Chinese chars */
2520 /* double A->W mapping */
2521 /* NT uses the full size, XP+ only until the first null */
2522 DWORD nt_size
= MultiByteToWideChar( CP_ACP
, 0, (char *)cmd_w
, size_w
, test_cmd_a_to_w
,
2523 sizeof(test_cmd_a_to_w
)/sizeof(WCHAR
) ) * sizeof(WCHAR
);
2524 DWORD xp_size
= MultiByteToWideChar( CP_ACP
, 0, (char *)cmd_w
, -1, NULL
, 0 ) * sizeof(WCHAR
);
2525 ok(size
== xp_size
|| broken(size
== nt_size
) ||
2526 broken(str_index
== 4 && IsDBCSLeadByte(cmd_w
[0])) /* East Asian */,
2527 "Wrong size %d/%d, msg_index=%d\n", size
, size_a_to_w
, msg_index
);
2528 ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_a_to_w
),
2529 "Expected %s, msg_index=%d\n", wine_dbgstr_w(test_cmd_a_to_w
), msg_index
);
2531 else if (unicode_client
)
2533 ok(size
== size_w_to_a
, "Wrong size %d/%d, msg_index=%d\n", size
, size_w_to_a
, msg_index
);
2534 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2535 test_cmd_w_to_a
, buffer
, msg_index
);
2539 ok(size
== size_w
, "Wrong size %d/%d, msg_index=%d\n", size
, size_w
, msg_index
);
2540 ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2541 "Expected %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), msg_index
);
2544 case 5: /* Chinese with latin characters begin */
2545 if (unicode_server
&& unicode_client
)
2547 todo_wine
ok(size
== size_w
, "Wrong size %d expected %d, msg_index=%d\n", size
, size_w
, msg_index
);
2548 MultiByteToWideChar(CP_ACP
, 0, test_cmd_w_to_a
, size_w
, test_cmd_a_to_w
,
2549 sizeof(test_cmd_a_to_w
)/sizeof(WCHAR
));
2550 todo_wine
ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2551 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), wine_dbgstr_w((WCHAR
*)buffer
), msg_index
);
2553 else if (unicode_server
)
2555 todo_wine
ok(size
== size_w
, "Wrong size %d expected %d, msg_index=%d\n", size
, size_w
, msg_index
);
2556 MultiByteToWideChar(CP_ACP
, 0, test_cmd_w_to_a
, size_w
, test_cmd_a_to_w
,
2557 sizeof(test_cmd_a_to_w
)/sizeof(WCHAR
));
2559 todo_wine
ok(!lstrcmpW((WCHAR
*)buffer
, test_cmd_a_to_w
), "Expected %s, got %s, msg_index=%d\n",
2560 wine_dbgstr_w(test_cmd_a_to_w
), wine_dbgstr_w((WCHAR
*)buffer
), msg_index
);
2562 todo_wine
ok(!lstrcmpW((WCHAR
*)buffer
, cmd_w
),
2563 "Expected %s got %s, msg_index=%d\n", wine_dbgstr_w(cmd_w
), wine_dbgstr_w((WCHAR
*)buffer
), msg_index
);
2565 else if (unicode_client
)
2567 ok(size
== size_w_to_a
, "Wrong size %d expected %d, msg_index=%d\n", size
, size_w_to_a
, msg_index
);
2568 ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2569 test_cmd_w_to_a
, buffer
, msg_index
);
2573 todo_wine
ok(size
== size_w_to_a
|| size
== (size_w_to_a
- 1), "Wrong size %d expected %d or %d, msg_index=%d\n",
2574 size
, size_w_to_a
, size_w_to_a
- 1, msg_index
);
2575 todo_wine
ok(!lstrcmpA((CHAR
*)buffer
, test_cmd_w_to_a
), "Expected %s, got %s, msg_index=%d\n",
2576 test_cmd_w_to_a
, buffer
, msg_index
);
2581 ok( 0, "Invalid message %u\n", msg_index
);
2584 HeapFree(GetProcessHeap(), 0, buffer
);
2585 return (HDDEDATA
) DDE_FACK
;
2587 case XTYP_DISCONNECT
:
2588 return (HDDEDATA
) TRUE
;
2591 ok(FALSE
, "Unhandled msg: %08x, msg_index=%d\n", uType
, msg_index
);
2597 static HDDEDATA CALLBACK
client_end_to_end_callback(UINT uType
, UINT uFmt
, HCONV hconv
,
2598 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
2599 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
2603 case XTYP_DISCONNECT
:
2604 return (HDDEDATA
) TRUE
;
2607 ok(FALSE
, "Unhandled msg: %08x\n", uType
);
2613 static void test_end_to_end_client(BOOL type_a
)
2616 DWORD client_pid
= 0;
2620 static const char test_service
[] = "TestDDEService";
2621 static const WCHAR test_service_w
[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2622 static const char test_topic
[] = "TestDDETopic";
2623 static const WCHAR test_topic_w
[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2625 trace("Start end to end client %s\n", type_a
? "ASCII" : "UNICODE");
2628 ret
= DdeInitializeA(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2630 ret
= DdeInitializeW(&client_pid
, client_end_to_end_callback
, APPCMD_CLIENTONLY
, 0);
2631 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %x\n", ret
);
2635 server
= DdeCreateStringHandleA(client_pid
, test_service
, CP_WINANSI
);
2636 topic
= DdeCreateStringHandleA(client_pid
, test_topic
, CP_WINANSI
);
2639 server
= DdeCreateStringHandleW(client_pid
, test_service_w
, CP_WINUNICODE
);
2640 topic
= DdeCreateStringHandleW(client_pid
, test_topic_w
, CP_WINUNICODE
);
2643 DdeGetLastError(client_pid
);
2644 hconv
= DdeConnect(client_pid
, server
, topic
, NULL
);
2645 ok(hconv
!= NULL
, "Expected non-NULL conversation\n");
2646 ret
= DdeGetLastError(client_pid
);
2647 ok(ret
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %x\n", ret
);
2648 DdeFreeStringHandle(client_pid
, server
);
2650 /* Test both A and W data being passed to DdeClientTransaction */
2651 hdata
= DdeClientTransaction((LPBYTE
)test_cmd_a_to_a
, sizeof(test_cmd_a_to_a
),
2652 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2653 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2654 ok(ret
== DDE_FACK
, "wrong status code %x\n", ret
);
2655 err
= DdeGetLastError(client_pid
);
2656 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
2658 for (i
= 0; i
< sizeof(test_cmd_w_to_w
)/sizeof(test_cmd_w_to_w
[0]); i
++)
2660 hdata
= DdeClientTransaction((LPBYTE
)test_cmd_w_to_w
[i
],
2661 (lstrlenW(test_cmd_w_to_w
[i
]) + 1) * sizeof(WCHAR
),
2662 hconv
, (HSZ
)0xdead, 0xbeef, XTYP_EXECUTE
, 1000, &ret
);
2663 ok(hdata
!= NULL
, "DdeClientTransaction failed\n");
2664 ok(ret
== DDE_FACK
, "wrong status code %x\n", ret
);
2665 err
= DdeGetLastError(client_pid
);
2666 ok(err
== DMLERR_NO_ERROR
, "wrong dde error %x\n", err
);
2669 DdeFreeStringHandle(client_pid
, topic
);
2670 ret
= DdeDisconnect(hconv
);
2671 ok(ret
== TRUE
, "Expected TRUE, got %x\n", ret
);
2673 ret
= DdeUninitialize(client_pid
);
2674 ok(ret
== TRUE
, "Expected TRUE, got %x\n", ret
);
2678 static void test_end_to_end_server(HANDLE hproc
, HANDLE hthread
, BOOL type_a
)
2685 static const char test_service
[] = "TestDDEService";
2687 trace("start end to end server %s\n", type_a
? "ASCII" : "UNICODE");
2691 res
= DdeInitializeA(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2693 res
= DdeInitializeW(&server_pid
, server_end_to_end_callback
, APPCLASS_STANDARD
, 0);
2694 ok(res
== DMLERR_NO_ERROR
, "Expected DMLERR_NO_ERROR, got %d\n", res
);
2696 server
= DdeCreateStringHandleA(server_pid
, test_service
, CP_WINANSI
);
2697 ok(server
!= NULL
, "Expected non-NULL string handle\n");
2699 hdata
= DdeNameService(server_pid
, server
, 0, DNS_REGISTER
);
2700 ok(hdata
== (HDDEDATA
)TRUE
, "Expected TRUE, got %p\n", hdata
);
2701 ResumeThread( hthread
);
2704 while (MsgWaitForMultipleObjects( 1, &hproc
, FALSE
, INFINITE
, QS_ALLINPUT
) != 0)
2706 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2709 ret
= DdeUninitialize(server_pid
);
2710 ok(ret
== TRUE
, "Expected TRUE, got %d\n", ret
);
2711 GetExitCodeProcess( hproc
, &res
);
2712 ok( !res
, "client failed with %u error(s)\n", res
);
2719 char buffer
[MAX_PATH
];
2720 STARTUPINFOA startup
;
2721 PROCESS_INFORMATION proc
;
2722 DWORD dde_inst
= 0xdeadbeef;
2724 argc
= winetest_get_mainargs(&argv
);
2727 if (!lstrcmpA(argv
[2], "ddeml"))
2728 test_ddeml_client();
2729 else if (!lstrcmpA(argv
[2], "msg"))
2731 else if (!lstrcmpA(argv
[2], "enda"))
2732 test_end_to_end_client(TRUE
);
2733 else if (!lstrcmpA(argv
[2], "endw"))
2734 test_end_to_end_client(FALSE
);
2739 test_initialisation();
2741 SetLastError(0xdeadbeef);
2742 DdeInitializeW(&dde_inst
, client_ddeml_callback
, APPCMD_CLIENTONLY
, 0);
2743 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
2745 win_skip("Skipping tests on win9x because of brokenness\n");
2749 ZeroMemory(&startup
, sizeof(STARTUPINFOA
));
2750 sprintf(buffer
, "%s dde ddeml", argv
[0]);
2751 startup
.cb
= sizeof(startup
);
2752 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
2753 startup
.wShowWindow
= SW_SHOWNORMAL
;
2755 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2756 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2758 test_msg_server(proc
.hProcess
, proc
.hThread
);
2760 sprintf(buffer
, "%s dde msg", argv
[0]);
2761 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2762 0, NULL
, NULL
, &startup
, &proc
);
2764 test_ddeml_server(proc
.hProcess
);
2766 /* Test the combinations of A and W interfaces with A and W data
2767 end to end to ensure that data conversions are accurate */
2768 sprintf(buffer
, "%s dde enda", argv
[0]);
2769 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2770 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2772 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, TRUE
);
2774 /* Don't bother testing W interfaces on Win9x/WinMe */
2775 SetLastError(0xdeadbeef);
2776 lstrcmpW(NULL
, NULL
);
2777 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
2779 win_skip("Skipping W-interface tests\n");
2783 sprintf(buffer
, "%s dde endw", argv
[0]);
2784 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2785 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2787 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, FALSE
);
2789 sprintf(buffer
, "%s dde enda", argv
[0]);
2790 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2791 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2793 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, FALSE
);
2795 sprintf(buffer
, "%s dde endw", argv
[0]);
2796 CreateProcessA(NULL
, buffer
, NULL
, NULL
, FALSE
,
2797 CREATE_SUSPENDED
, NULL
, NULL
, &startup
, &proc
);
2799 test_end_to_end_server(proc
.hProcess
, proc
.hThread
, TRUE
);
2801 test_dde_aw_transaction( FALSE
, TRUE
);
2802 test_dde_aw_transaction( TRUE
, FALSE
);
2803 test_dde_aw_transaction( TRUE
, TRUE
);
2804 test_dde_aw_transaction( FALSE
, FALSE
);
2806 test_dde_aw_transaction( FALSE
, TRUE
);
2807 test_dde_aw_transaction( TRUE
, FALSE
);
2808 test_dde_aw_transaction( TRUE
, TRUE
);
2810 test_dde_aw_transaction( FALSE
, FALSE
);
2812 test_DdeCreateDataHandle();
2813 test_DdeCreateStringHandle();
2814 test_FreeDDElParam();
2815 test_PackDDElParam();
2816 test_UnpackDDElParam();