- Sync winetests with Wine head (comcat, crypt32, gdiplus, lz32, mapi32, mlang, msacm...
[reactos.git] / rostests / winetests / user32 / dde.c
1 /*
2 * Unit tests for DDE functions
3 *
4 * Copyright (c) 2004 Dmitry Timoshkov
5 * Copyright (c) 2007 James Hawkins
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "dde.h"
30 #include "ddeml.h"
31 #include "winerror.h"
32
33 #include "wine/test.h"
34
35 static const WCHAR TEST_DDE_SERVICE[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
36
37 static char exec_cmdA[] = "ANSI dde command";
38 static WCHAR exec_cmdW[] = {'u','n','i','c','o','d','e',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
39
40 static WNDPROC old_dde_client_wndproc;
41
42 static const DWORD default_timeout = 200;
43
44 static void flush_events(void)
45 {
46 MSG msg;
47 int diff = default_timeout;
48 int min_timeout = 50;
49 DWORD time = GetTickCount() + diff;
50
51 while (diff > 0)
52 {
53 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
54 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
55 diff = time - GetTickCount();
56 min_timeout = 10;
57 }
58 }
59
60 static void create_dde_window(HWND *hwnd, LPCSTR name, WNDPROC wndproc)
61 {
62 WNDCLASSA wcA;
63
64 memset(&wcA, 0, sizeof(wcA));
65 wcA.lpfnWndProc = wndproc;
66 wcA.lpszClassName = name;
67 wcA.hInstance = GetModuleHandleA(0);
68 assert(RegisterClassA(&wcA));
69
70 *hwnd = CreateWindowExA(0, name, NULL, WS_POPUP,
71 500, 500, CW_USEDEFAULT, CW_USEDEFAULT,
72 GetDesktopWindow(), 0, GetModuleHandleA(0), NULL);
73 assert(*hwnd);
74 }
75
76 static void destroy_dde_window(HWND *hwnd, LPCSTR name)
77 {
78 DestroyWindow(*hwnd);
79 UnregisterClass(name, GetModuleHandleA(0));
80 }
81
82 static LRESULT WINAPI dde_server_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
83 {
84 UINT_PTR lo, hi;
85 char str[MAX_PATH], *ptr;
86 HGLOBAL hglobal;
87 DDEDATA *data;
88 DDEPOKE *poke;
89 DWORD size;
90
91 static int msg_index = 0;
92 static HWND client = 0;
93 static BOOL executed = FALSE;
94
95 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
96 return DefWindowProcA(hwnd, msg, wparam, lparam);
97
98 msg_index++;
99
100 switch (msg)
101 {
102 case WM_DDE_INITIATE:
103 {
104 client = (HWND)wparam;
105 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
106
107 GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
108 ok(!lstrcmpA(str, "TestDDEService"), "Expected TestDDEService, got %s\n", str);
109
110 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
111 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
112
113 SendMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
114
115 break;
116 }
117
118 case WM_DDE_REQUEST:
119 {
120 ok((msg_index >= 2 && msg_index <= 4) ||
121 (msg_index >= 7 && msg_index <= 8),
122 "Expected 2, 3, 4, 7 or 8, got %d\n", msg_index);
123 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
124 ok(LOWORD(lparam) == CF_TEXT, "Expected CF_TEXT, got %d\n", LOWORD(lparam));
125
126 GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
127 if (msg_index < 8)
128 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
129 else
130 ok(!lstrcmpA(str, "executed"), "Expected executed, got %s\n", str);
131
132 if (msg_index == 8)
133 {
134 if (executed)
135 lstrcpyA(str, "command executed\r\n");
136 else
137 lstrcpyA(str, "command not executed\r\n");
138 }
139 else
140 lstrcpyA(str, "requested data\r\n");
141
142 size = sizeof(DDEDATA) + lstrlenA(str) + 1;
143 hglobal = GlobalAlloc(GMEM_MOVEABLE, size);
144 ok(hglobal != NULL, "Expected non-NULL hglobal\n");
145
146 data = GlobalLock(hglobal);
147 ZeroMemory(data, size);
148
149 /* setting fResponse to FALSE at this point destroys
150 * the internal messaging state of native dde
151 */
152 data->fResponse = TRUE;
153
154 if (msg_index == 2)
155 data->fRelease = TRUE;
156 else if (msg_index == 3)
157 data->fAckReq = TRUE;
158
159 data->cfFormat = CF_TEXT;
160 lstrcpyA((LPSTR)data->Value, str);
161 GlobalUnlock(hglobal);
162
163 lparam = PackDDElParam(WM_DDE_ACK, (UINT_PTR)hglobal, HIWORD(lparam));
164 PostMessageA(client, WM_DDE_DATA, (WPARAM)hwnd, lparam);
165
166 break;
167 }
168
169 case WM_DDE_POKE:
170 {
171 ok(msg_index == 5 || msg_index == 6, "Expected 5 or 6, got %d\n", msg_index);
172 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
173
174 UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
175
176 GlobalGetAtomNameA(hi, str, MAX_PATH);
177 ok(!lstrcmpA(str, "poker"), "Expected poker, got %s\n", str);
178
179 poke = GlobalLock((HGLOBAL)lo);
180 ok(poke != NULL, "Expected non-NULL poke\n");
181 ok(poke->fReserved == 0, "Expected 0, got %d\n", poke->fReserved);
182 ok(poke->unused == 0, "Expected 0, got %d\n", poke->unused);
183 ok(poke->fRelease == TRUE, "Expected TRUE, got %d\n", poke->fRelease);
184 ok(poke->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", poke->cfFormat);
185
186 if (msg_index == 5)
187 {
188 size = GlobalSize((HGLOBAL)lo);
189 ok(size == 4, "got %d\n", size);
190 }
191 else
192 ok(!lstrcmpA((LPSTR)poke->Value, "poke data\r\n"),
193 "Expected 'poke data\\r\\n', got %s\n", poke->Value);
194
195 GlobalUnlock((HGLOBAL)lo);
196
197 lparam = PackDDElParam(WM_DDE_ACK, DDE_FACK, hi);
198 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
199
200 break;
201 }
202
203 case WM_DDE_EXECUTE:
204 {
205 ok(msg_index == 7, "Expected 7, got %d\n", msg_index);
206 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
207
208 ptr = GlobalLock((HGLOBAL)lparam);
209 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected [Command(Var)], got %s\n", ptr);
210 GlobalUnlock((HGLOBAL)lparam);
211
212 executed = TRUE;
213
214 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, DDE_FACK, HIWORD(lparam));
215 PostMessageA(client, WM_DDE_ACK, (WPARAM)hwnd, lparam);
216
217 break;
218 }
219
220 case WM_DDE_TERMINATE:
221 {
222 ok(msg_index == 9, "Expected 9, got %d\n", msg_index);
223 ok(wparam == (WPARAM)client, "Expected client hwnd, got %08lx\n", wparam);
224 ok(lparam == 0, "Expected 0, got %08lx\n", lparam);
225
226 PostMessageA(client, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
227
228 break;
229 }
230
231 default:
232 ok(FALSE, "Unhandled msg: %08x\n", msg);
233 }
234
235 return DefWindowProcA(hwnd, msg, wparam, lparam);
236 }
237
238 static void test_msg_server(HANDLE hproc, HANDLE hthread)
239 {
240 MSG msg;
241 HWND hwnd;
242 DWORD res;
243
244 create_dde_window(&hwnd, "dde_server", dde_server_wndproc);
245 ResumeThread( hthread );
246
247 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
248 {
249 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
250 }
251
252 destroy_dde_window(&hwnd, "dde_server");
253 GetExitCodeProcess( hproc, &res );
254 ok( !res, "client failed with %u error(s)\n", res );
255 }
256
257 static HDDEDATA CALLBACK client_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
258 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
259 ULONG_PTR dwData1, ULONG_PTR dwData2)
260 {
261 ok(FALSE, "Unhandled msg: %08x\n", uType);
262 return 0;
263 }
264
265 static void test_ddeml_client(void)
266 {
267 UINT ret;
268 char buffer[32];
269 LPSTR str;
270 DWORD size, res;
271 HDDEDATA hdata, op;
272 HSZ server, topic, item;
273 DWORD client_pid;
274 HCONV conversation;
275
276 client_pid = 0;
277 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
278 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
279
280 /* FIXME: make these atoms global and check them in the server */
281
282 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
283 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
284
285 DdeGetLastError(client_pid);
286 conversation = DdeConnect(client_pid, server, topic, NULL);
287 ok(conversation != NULL, "Expected non-NULL conversation\n");
288 ret = DdeGetLastError(client_pid);
289 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
290
291 DdeFreeStringHandle(client_pid, server);
292
293 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
294
295 /* XTYP_REQUEST, fRelease = TRUE */
296 res = 0xdeadbeef;
297 DdeGetLastError(client_pid);
298 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
299 ret = DdeGetLastError(client_pid);
300 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
301 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %08x\n", res);
302 if (hdata == NULL)
303 ok(FALSE, "hdata is NULL\n");
304 else
305 {
306 str = (LPSTR)DdeAccessData(hdata, &size);
307 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
308 ok(size == 19, "Expected 19, got %d\n", size);
309
310 ret = DdeUnaccessData(hdata);
311 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
312 }
313
314 /* XTYP_REQUEST, fAckReq = TRUE */
315 res = 0xdeadbeef;
316 DdeGetLastError(client_pid);
317 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
318 ret = DdeGetLastError(client_pid);
319 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
320 todo_wine
321 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
322 if (hdata == NULL)
323 ok(FALSE, "hdata is NULL\n");
324 else
325 {
326 str = (LPSTR)DdeAccessData(hdata, &size);
327 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
328 ok(size == 19, "Expected 19, got %d\n", size);
329
330 ret = DdeUnaccessData(hdata);
331 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
332 }
333
334 /* XTYP_REQUEST, all params normal */
335 res = 0xdeadbeef;
336 DdeGetLastError(client_pid);
337 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
338 ret = DdeGetLastError(client_pid);
339 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
340 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
341 if (hdata == NULL)
342 ok(FALSE, "hdata is NULL\n");
343 else
344 {
345 str = (LPSTR)DdeAccessData(hdata, &size);
346 ok(!lstrcmpA(str, "requested data\r\n"), "Expected 'requested data\\r\\n', got %s\n", str);
347 ok(size == 19, "Expected 19, got %d\n", size);
348
349 ret = DdeUnaccessData(hdata);
350 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
351 }
352
353 /* XTYP_REQUEST, no item */
354 res = 0xdeadbeef;
355 DdeGetLastError(client_pid);
356 hdata = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
357 ret = DdeGetLastError(client_pid);
358 ok(hdata == NULL, "Expected NULL hdata, got %p\n", hdata);
359 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
360 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
361
362 DdeFreeStringHandle(client_pid, item);
363
364 item = DdeCreateStringHandleA(client_pid, "poker", CP_WINANSI);
365
366 lstrcpyA(buffer, "poke data\r\n");
367 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
368 0, item, CF_TEXT, 0);
369 ok(hdata != NULL, "Expected non-NULL hdata\n");
370
371 /* XTYP_POKE, no item */
372 res = 0xdeadbeef;
373 DdeGetLastError(client_pid);
374 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
375 ret = DdeGetLastError(client_pid);
376 ok(op == NULL, "Expected NULL, got %p\n", op);
377 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
378 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
379
380 /* XTYP_POKE, no data */
381 res = 0xdeadbeef;
382 DdeGetLastError(client_pid);
383 op = DdeClientTransaction(NULL, 0, conversation, 0, CF_TEXT, XTYP_POKE, default_timeout, &res);
384 ret = DdeGetLastError(client_pid);
385 ok(op == NULL, "Expected NULL, got %p\n", op);
386 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
387 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
388
389 /* XTYP_POKE, wrong size */
390 res = 0xdeadbeef;
391 DdeGetLastError(client_pid);
392 op = DdeClientTransaction((LPBYTE)hdata, 0, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
393 ret = DdeGetLastError(client_pid);
394 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
395 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
396 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
397
398 /* XTYP_POKE, correct params */
399 res = 0xdeadbeef;
400 DdeGetLastError(client_pid);
401 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, item, CF_TEXT, XTYP_POKE, default_timeout, &res);
402 ret = DdeGetLastError(client_pid);
403 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
404 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
405 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
406
407 DdeFreeDataHandle(hdata);
408
409 lstrcpyA(buffer, "[Command(Var)]");
410 hdata = DdeCreateDataHandle(client_pid, (LPBYTE)buffer, lstrlenA(buffer) + 1,
411 0, NULL, CF_TEXT, 0);
412 ok(hdata != NULL, "Expected non-NULL hdata\n");
413
414 /* XTYP_EXECUTE, correct params */
415 res = 0xdeadbeef;
416 DdeGetLastError(client_pid);
417 op = DdeClientTransaction((LPBYTE)hdata, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
418 ret = DdeGetLastError(client_pid);
419 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
420 ok(op == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", op);
421 ok(res == DDE_FACK, "Expected DDE_FACK, got %d\n", res);
422
423 /* XTYP_EXECUTE, no data */
424 res = 0xdeadbeef;
425 DdeGetLastError(client_pid);
426 op = DdeClientTransaction(NULL, 0, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
427 ret = DdeGetLastError(client_pid);
428 ok(op == NULL, "Expected NULL, got %p\n", op);
429 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
430 ok(ret == DMLERR_MEMORY_ERROR, "Expected DMLERR_MEMORY_ERROR, got %d\n", ret);
431
432 /* XTYP_EXECUTE, no data, -1 size */
433 res = 0xdeadbeef;
434 DdeGetLastError(client_pid);
435 op = DdeClientTransaction(NULL, -1, conversation, NULL, 0, XTYP_EXECUTE, default_timeout, &res);
436 ret = DdeGetLastError(client_pid);
437 ok(op == NULL, "Expected NULL, got %p\n", op);
438 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
439 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
440
441 DdeFreeStringHandle(client_pid, topic);
442 DdeFreeDataHandle(hdata);
443
444 item = DdeCreateStringHandleA(client_pid, "executed", CP_WINANSI);
445
446 /* verify the execute */
447 res = 0xdeadbeef;
448 DdeGetLastError(client_pid);
449 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
450 ret = DdeGetLastError(client_pid);
451 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
452 ok(res == DDE_FNOTPROCESSED, "Expected DDE_FNOTPROCESSED, got %d\n", res);
453 if (hdata == NULL)
454 ok(FALSE, "hdata is NULL\n");
455 else
456 {
457 str = (LPSTR)DdeAccessData(hdata, &size);
458 ok(!lstrcmpA(str, "command executed\r\n"), "Expected 'command executed\\r\\n', got %s\n", str);
459 ok(size == 21, "Expected 21, got %d\n", size);
460
461 ret = DdeUnaccessData(hdata);
462 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
463 }
464
465 /* invalid transactions */
466 res = 0xdeadbeef;
467 DdeGetLastError(client_pid);
468 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ADVREQ, default_timeout, &res);
469 ret = DdeGetLastError(client_pid);
470 ok(op == NULL, "Expected NULL, got %p\n", op);
471 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
472 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
473
474 res = 0xdeadbeef;
475 DdeGetLastError(client_pid);
476 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT, default_timeout, &res);
477 ret = DdeGetLastError(client_pid);
478 ok(op == NULL, "Expected NULL, got %p\n", op);
479 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
480 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
481
482 res = 0xdeadbeef;
483 DdeGetLastError(client_pid);
484 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_CONNECT_CONFIRM, default_timeout, &res);
485 ret = DdeGetLastError(client_pid);
486 ok(op == NULL, "Expected NULL, got %p\n", op);
487 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
488 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
489
490 res = 0xdeadbeef;
491 DdeGetLastError(client_pid);
492 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_DISCONNECT, default_timeout, &res);
493 ret = DdeGetLastError(client_pid);
494 ok(op == NULL, "Expected NULL, got %p\n", op);
495 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
496 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
497
498 res = 0xdeadbeef;
499 DdeGetLastError(client_pid);
500 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_ERROR, default_timeout, &res);
501 ret = DdeGetLastError(client_pid);
502 ok(op == NULL, "Expected NULL, got %p\n", op);
503 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
504 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
505
506 res = 0xdeadbeef;
507 DdeGetLastError(client_pid);
508 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_MONITOR, default_timeout, &res);
509 ret = DdeGetLastError(client_pid);
510 ok(op == NULL, "Expected NULL, got %p\n", op);
511 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
512 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
513
514 res = 0xdeadbeef;
515 DdeGetLastError(client_pid);
516 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REGISTER, default_timeout, &res);
517 ret = DdeGetLastError(client_pid);
518 ok(op == NULL, "Expected NULL, got %p\n", op);
519 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
520 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
521
522 res = 0xdeadbeef;
523 DdeGetLastError(client_pid);
524 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_UNREGISTER, default_timeout, &res);
525 ret = DdeGetLastError(client_pid);
526 ok(op == NULL, "Expected NULL, got %p\n", op);
527 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
528 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
529
530 res = 0xdeadbeef;
531 DdeGetLastError(client_pid);
532 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_WILDCONNECT, default_timeout, &res);
533 ret = DdeGetLastError(client_pid);
534 ok(op == NULL, "Expected NULL, got %p\n", op);
535 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
536 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
537
538 res = 0xdeadbeef;
539 DdeGetLastError(client_pid);
540 op = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_XACT_COMPLETE, default_timeout, &res);
541 ret = DdeGetLastError(client_pid);
542 ok(op == NULL, "Expected NULL, got %p\n", op);
543 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", res);
544 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
545
546 DdeFreeStringHandle(client_pid, item);
547
548 ret = DdeDisconnect(conversation);
549 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
550
551 ret = DdeUninitialize(client_pid);
552 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
553 }
554
555 static DWORD server_pid;
556
557 static HDDEDATA CALLBACK server_ddeml_callback(UINT uType, UINT uFmt, HCONV hconv,
558 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
559 ULONG_PTR dwData1, ULONG_PTR dwData2)
560 {
561 char str[MAX_PATH], *ptr;
562 HDDEDATA ret = NULL;
563 DWORD size;
564
565 static int msg_index = 0;
566 static HCONV conversation = 0;
567
568 msg_index++;
569
570 switch (uType)
571 {
572 case XTYP_REGISTER:
573 {
574 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
575 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
576 ok(hconv == 0, "Expected 0, got %p\n", hconv);
577 ok(hdata == 0, "Expected 0, got %p\n", hdata);
578 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
579 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
580
581 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
582 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
583 ok(size == 13, "Expected 13, got %d\n", size);
584
585 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
586 ok(!strncmp(str, "TestDDEServer(", 14), "Expected TestDDEServer(, got %s\n", str);
587 ok(str[size - 1] == ')', "Expected ')', got %c\n", str[size - 1]);
588 ok(size == 25, "Expected 25, got %d\n", size);
589
590 return (HDDEDATA)TRUE;
591 }
592
593 case XTYP_CONNECT:
594 {
595 ok(msg_index == 2, "Expected 2, got %d\n", msg_index);
596 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
597 ok(hconv == 0, "Expected 0, got %p\n", hconv);
598 ok(hdata == 0, "Expected 0, got %p\n", hdata);
599 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
600 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
601
602 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
603 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
604 ok(size == 12, "Expected 12, got %d\n", size);
605
606 size = DdeQueryStringA(server_pid, hsz2, 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);
609
610 return (HDDEDATA)TRUE;
611 }
612
613 case XTYP_CONNECT_CONFIRM:
614 {
615 conversation = hconv;
616
617 ok(msg_index == 3, "Expected 3, got %d\n", msg_index);
618 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
619 ok(hconv != NULL, "Expected non-NULL hconv\n");
620 ok(hdata == 0, "Expected 0, got %p\n", hdata);
621 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
622 ok(dwData2 == FALSE, "Expected FALSE, got %08lx\n", dwData2);
623
624 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
625 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
626 ok(size == 12, "Expected 12, got %d\n", size);
627
628 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
629 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
630 ok(size == 13, "Expected 13, got %d\n", size);
631
632 return (HDDEDATA)TRUE;
633 }
634
635 case XTYP_REQUEST:
636 {
637 ok(msg_index == 4 || msg_index == 5 || msg_index == 6,
638 "Expected 4, 5 or 6, got %d\n", msg_index);
639 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
640 ok(hdata == 0, "Expected 0, got %p\n", hdata);
641 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
642 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
643
644 if (msg_index == 4)
645 ok(uFmt == 0xbeef, "Expected 0xbeef, got %08x\n", uFmt);
646 else
647 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %08x\n", uFmt);
648
649 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
650 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
651 ok(size == 12, "Expected 12, got %d\n", size);
652
653 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
654
655 if (msg_index == 5)
656 {
657 {
658 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
659 ok(size == 1, "Expected 1, got %d\n", size);
660 }
661 }
662 else if (msg_index == 6)
663 {
664 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
665 ok(size == 7, "Expected 7, got %d\n", size);
666 }
667
668 if (msg_index == 6)
669 {
670 lstrcpyA(str, "requested data\r\n");
671 return DdeCreateDataHandle(server_pid, (LPBYTE)str, lstrlenA(str) + 1,
672 0, hsz2, CF_TEXT, 0);
673 }
674
675 return NULL;
676 }
677
678 case XTYP_POKE:
679 {
680 ok(msg_index == 7 || msg_index == 8, "Expected 7 or 8, got %d\n", msg_index);
681 ok(uFmt == CF_TEXT, "Expected CF_TEXT, got %d\n", uFmt);
682 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
683 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
684 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
685
686 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
687 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
688 ok(size == 12, "Expected 12, got %d\n", size);
689
690 ptr = (LPSTR)DdeAccessData(hdata, &size);
691 ok(!lstrcmpA(ptr, "poke data\r\n"), "Expected 'poke data\\r\\n', got %s\n", ptr);
692 ok(size == 12, "Expected 12, got %d\n", size);
693 DdeUnaccessData(hdata);
694
695 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
696 if (msg_index == 7)
697 {
698 {
699 ok(!lstrcmpA(str, ""), "Expected empty string, got %s\n", str);
700 ok(size == 1, "Expected 1, got %d\n", size);
701 }
702 }
703 else
704 {
705 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
706 ok(size == 4, "Expected 4, got %d\n", size);
707 }
708
709 return (HDDEDATA)DDE_FACK;
710 }
711
712 case XTYP_EXECUTE:
713 {
714 ok(msg_index >= 9 && msg_index <= 11, "Expected 9 or 11, got %d\n", msg_index);
715 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
716 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
717 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
718 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
719 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
720
721 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
722 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
723 ok(size == 12, "Expected 12, got %d\n", size);
724
725 if (msg_index == 9 || msg_index == 11)
726 {
727 ptr = (LPSTR)DdeAccessData(hdata, &size);
728
729 if (msg_index == 9)
730 {
731 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
732 ok(size == 15, "Expected 15, got %d\n", size);
733 ret = (HDDEDATA)DDE_FACK;
734 }
735 else
736 {
737 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
738 ok(size == 18, "Expected 18, got %d\n", size);
739 ret = DDE_FNOTPROCESSED;
740 }
741
742 DdeUnaccessData(hdata);
743 }
744 else if (msg_index == 10)
745 {
746 DWORD rsize = 0;
747 size = 0;
748
749 size = DdeGetData(hdata, NULL, 0, 0);
750 ok(size == 17, "DdeGetData should have returned 17 not %d\n", size);
751 ptr = HeapAlloc(GetProcessHeap(), 0, size);
752 ok(ptr != NULL,"HeapAlloc should have returned ptr not NULL\n");
753 rsize = DdeGetData(hdata, (LPBYTE)ptr, size, 0);
754 ok(rsize == size, "DdeGetData did not return %d bytes but %d\n", size, rsize);
755
756 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]' got %s\n", ptr);
757 ok(size == 17, "Expected 17, got %d\n", size);
758 ret = (HDDEDATA)DDE_FACK;
759
760 HeapFree(GetProcessHeap(), 0, ptr);
761 }
762
763 return ret;
764 }
765
766 case XTYP_DISCONNECT:
767 {
768 ok(msg_index == 12, "Expected 12, got %d\n", msg_index);
769 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
770 ok(hconv == conversation, "Expected conversation handle, got %p\n", hconv);
771 ok(dwData1 == 0, "Expected 0, got %08lx\n", dwData1);
772 ok(dwData2 == 0, "Expected 0, got %08lx\n", dwData2);
773 ok(hsz1 == 0, "Expected 0, got %p\n", hsz2);
774 ok(hsz2 == 0, "Expected 0, got %p\n", hsz2);
775
776 return 0;
777 }
778
779 default:
780 ok(FALSE, "Unhandled msg: %08x\n", uType);
781 }
782
783 return 0;
784 }
785
786 static void test_ddeml_server(HANDLE hproc)
787 {
788 MSG msg;
789 UINT res;
790 BOOL ret;
791 HSZ server;
792 HDDEDATA hdata;
793
794 /* set up DDE server */
795 server_pid = 0;
796 res = DdeInitialize(&server_pid, server_ddeml_callback, APPCLASS_STANDARD, 0);
797 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
798
799 server = DdeCreateStringHandle(server_pid, "TestDDEServer", CP_WINANSI);
800 ok(server != NULL, "Expected non-NULL string handle\n");
801
802 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
803 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
804
805 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
806 {
807 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
808 }
809 ret = DdeUninitialize(server_pid);
810 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
811 GetExitCodeProcess( hproc, &res );
812 ok( !res, "client failed with %u error(s)\n", res );
813 }
814
815 static HWND client_hwnd, server_hwnd;
816 static ATOM server, topic, item;
817 static HGLOBAL execute_hglobal;
818
819 static LRESULT WINAPI dde_msg_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
820 {
821 char str[MAX_PATH];
822 UINT_PTR lo, hi;
823 DDEDATA *data;
824 DDEACK *ack;
825 DWORD size;
826 LPSTR ptr;
827
828 static int msg_index = 0;
829
830 if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST)
831 return DefWindowProcA(hwnd, msg, wparam, lparam);
832
833 msg_index++;
834
835 switch (msg)
836 {
837 case WM_DDE_INITIATE:
838 {
839 ok(msg_index == 1, "Expected 1, got %d\n", msg_index);
840 ok(wparam == (WPARAM)client_hwnd, "Expected client hwnd, got %08lx\n", wparam);
841
842 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
843 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
844 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
845 ok(size == 13, "Expected 13, got %d\n", size);
846
847 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
848 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
849 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
850 ok(size == 12, "Expected 12, got %d\n", size);
851
852 break;
853 }
854
855 case WM_DDE_ACK:
856 {
857 ok((msg_index >= 2 && msg_index <= 4) || (msg_index >= 6 && msg_index <= 11),
858 "Expected 2, 3, 4, 6, 7, 8, 9, 10 or 11, got %d\n", msg_index);
859
860 if (msg_index == 2)
861 {
862 server_hwnd = (HWND)wparam;
863 ok(wparam != 0, "Expected non-NULL wparam, got %08lx\n", wparam);
864
865 size = GlobalGetAtomNameA(LOWORD(lparam), str, MAX_PATH);
866 ok(LOWORD(lparam) == server, "Expected server atom, got %08x\n", LOWORD(lparam));
867 ok(!lstrcmpA(str, "TestDDEServer"), "Expected TestDDEServer, got %s\n", str);
868 ok(size == 13, "Expected 13, got %d\n", size);
869
870 size = GlobalGetAtomNameA(HIWORD(lparam), str, MAX_PATH);
871 ok(HIWORD(lparam) == topic, "Expected topic atom, got %08x\n", HIWORD(lparam));
872 ok(!lstrcmpA(str, "TestDDETopic"), "Expected TestDDETopic, got %s\n", str);
873 ok(size == 12, "Expected 12, got %d\n", size);
874 }
875 else if (msg_index >= 9 && msg_index <= 11)
876 {
877 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
878
879 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
880
881 ack = (DDEACK *)&lo;
882 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
883 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
884 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
885
886 ok(hi == (UINT_PTR)execute_hglobal, "Execpted execute hglobal, got %08lx\n", hi);
887 ptr = GlobalLock((HGLOBAL)hi);
888
889 if (msg_index == 9)
890 {
891 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
892 ok(!lstrcmpA(ptr, "[Command(Var)]"), "Expected '[Command(Var)]', got %s\n", ptr);
893 } else if (msg_index == 10)
894 {
895 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
896 ok(!lstrcmpA(ptr, "[Command-2(Var)]"), "Expected '[Command-2(Var)]', got %s\n", ptr);
897 }
898 else
899 {
900 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
901 ok(!lstrcmpA(ptr, "[BadCommand(Var)]"), "Expected '[BadCommand(Var)]', got %s\n", ptr);
902 }
903
904 GlobalUnlock((HGLOBAL)hi);
905 }
906 else
907 {
908 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
909
910 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
911
912 ack = (DDEACK *)&lo;
913 ok(ack->bAppReturnCode == 0, "Expected 0, got %d\n", ack->bAppReturnCode);
914 ok(ack->reserved == 0, "Expected 0, got %d\n", ack->reserved);
915 ok(ack->fBusy == FALSE, "Expected FALSE, got %d\n", ack->fBusy);
916
917 if (msg_index >= 7)
918 ok(ack->fAck == TRUE, "Expected TRUE, got %d\n", ack->fAck);
919 else
920 {
921 if (msg_index == 6) todo_wine
922 ok(ack->fAck == FALSE, "Expected FALSE, got %d\n", ack->fAck);
923 }
924
925 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
926 if (msg_index == 3)
927 {
928 ok(hi == item, "Expected item atom, got %08lx\n", hi);
929 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
930 ok(size == 7, "Expected 7, got %d\n", size);
931 }
932 else if (msg_index == 4 || msg_index == 7)
933 {
934 ok(hi == 0, "Expected 0, got %08lx\n", hi);
935 ok(size == 0, "Expected empty string, got %d\n", size);
936 }
937 else
938 {
939 ok(hi == item, "Expected item atom, got %08lx\n", hi);
940 if (msg_index == 6) todo_wine
941 {
942 ok(!lstrcmpA(str, "poke"), "Expected poke, got %s\n", str);
943 ok(size == 4, "Expected 4, got %d\n", size);
944 }
945 }
946 }
947
948 break;
949 }
950
951 case WM_DDE_DATA:
952 {
953 ok(msg_index == 5, "Expected 5, got %d\n", msg_index);
954 ok(wparam == (WPARAM)server_hwnd, "Expected server hwnd, got %08lx\n", wparam);
955
956 UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
957
958 data = GlobalLock((HGLOBAL)lo);
959 ok(data->unused == 0, "Expected 0, got %d\n", data->unused);
960 ok(data->fResponse == TRUE, "Expected TRUE, got %d\n", data->fResponse);
961 todo_wine
962 {
963 ok(data->fRelease == TRUE, "Expected TRUE, got %d\n", data->fRelease);
964 }
965 ok(data->fAckReq == 0, "Expected 0, got %d\n", data->fAckReq);
966 ok(data->cfFormat == CF_TEXT, "Expected CF_TEXT, got %d\n", data->cfFormat);
967 ok(!lstrcmpA((LPSTR)data->Value, "requested data\r\n"),
968 "Expeted 'requested data\\r\\n', got %s\n", data->Value);
969 GlobalUnlock((HGLOBAL)lo);
970
971 size = GlobalGetAtomNameA(hi, str, MAX_PATH);
972 ok(hi == item, "Expected item atom, got %08x\n", HIWORD(lparam));
973 ok(!lstrcmpA(str, "request"), "Expected request, got %s\n", str);
974 ok(size == 7, "Expected 7, got %d\n", size);
975
976 GlobalFree((HGLOBAL)lo);
977 GlobalDeleteAtom(hi);
978
979 break;
980 }
981
982 default:
983 ok(FALSE, "Unhandled msg: %08x\n", msg);
984 }
985
986 return DefWindowProcA(hwnd, msg, wparam, lparam);
987 }
988
989 static HGLOBAL create_poke(void)
990 {
991 HGLOBAL hglobal;
992 DDEPOKE *poke;
993 DWORD size;
994
995 size = FIELD_OFFSET(DDEPOKE, Value[sizeof("poke data\r\n")]);
996 hglobal = GlobalAlloc(GMEM_DDESHARE, size);
997 ok(hglobal != 0, "Expected non-NULL hglobal\n");
998
999 poke = GlobalLock(hglobal);
1000 poke->unused = 0;
1001 poke->fRelease = TRUE;
1002 poke->fReserved = TRUE;
1003 poke->cfFormat = CF_TEXT;
1004 lstrcpyA((LPSTR)poke->Value, "poke data\r\n");
1005 GlobalUnlock(hglobal);
1006
1007 return hglobal;
1008 }
1009
1010 static HGLOBAL create_execute(LPCSTR command)
1011 {
1012 HGLOBAL hglobal;
1013 LPSTR ptr;
1014
1015 hglobal = GlobalAlloc(GMEM_DDESHARE, lstrlenA(command) + 1);
1016 ok(hglobal != 0, "Expected non-NULL hglobal\n");
1017
1018 ptr = GlobalLock(hglobal);
1019 lstrcpyA(ptr, command);
1020 GlobalUnlock(hglobal);
1021
1022 return hglobal;
1023 }
1024
1025 static void test_msg_client(void)
1026 {
1027 HGLOBAL hglobal;
1028 LPARAM lparam;
1029
1030 create_dde_window(&client_hwnd, "dde_client", dde_msg_client_wndproc);
1031
1032 server = GlobalAddAtomA("TestDDEServer");
1033 ok(server != 0, "Expected non-NULL server\n");
1034
1035 topic = GlobalAddAtomA("TestDDETopic");
1036 ok(topic != 0, "Expected non-NULL topic\n");
1037
1038 SendMessageA(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)client_hwnd, MAKELONG(server, topic));
1039
1040 GlobalDeleteAtom(server);
1041 GlobalDeleteAtom(topic);
1042
1043 flush_events();
1044
1045 item = GlobalAddAtom("request");
1046 ok(item != 0, "Expected non-NULL item\n");
1047
1048 /* WM_DDE_REQUEST, bad clipboard format */
1049 lparam = PackDDElParam(WM_DDE_REQUEST, 0xdeadbeef, item);
1050 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1051
1052 flush_events();
1053
1054 /* WM_DDE_REQUEST, no item */
1055 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, 0);
1056 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1057
1058 flush_events();
1059
1060 /* WM_DDE_REQUEST, no client hwnd */
1061 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1062 PostMessageA(server_hwnd, WM_DDE_REQUEST, 0, lparam);
1063
1064 flush_events();
1065
1066 /* WM_DDE_REQUEST, correct params */
1067 lparam = PackDDElParam(WM_DDE_REQUEST, CF_TEXT, item);
1068 PostMessageA(server_hwnd, WM_DDE_REQUEST, (WPARAM)client_hwnd, lparam);
1069
1070 flush_events();
1071
1072 GlobalDeleteAtom(item);
1073 item = GlobalAddAtomA("poke");
1074 ok(item != 0, "Expected non-NULL item\n");
1075
1076 hglobal = create_poke();
1077
1078 /* WM_DDE_POKE, no ddepoke */
1079 lparam = PackDDElParam(WM_DDE_POKE, 0, item);
1080 /* win9x returns 0 here and crashes in PostMessageA */
1081 if (lparam) {
1082 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1083 flush_events();
1084 }
1085 else
1086 win_skip("no lparam for WM_DDE_POKE\n");
1087
1088
1089 /* WM_DDE_POKE, no item */
1090 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, 0);
1091 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1092
1093 flush_events();
1094
1095 hglobal = create_poke();
1096
1097 /* WM_DDE_POKE, no client hwnd */
1098 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1099 PostMessageA(server_hwnd, WM_DDE_POKE, 0, lparam);
1100
1101 flush_events();
1102
1103 /* WM_DDE_POKE, all params correct */
1104 lparam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)hglobal, item);
1105 PostMessageA(server_hwnd, WM_DDE_POKE, (WPARAM)client_hwnd, lparam);
1106
1107 flush_events();
1108
1109 execute_hglobal = create_execute("[Command(Var)]");
1110
1111 /* WM_DDE_EXECUTE, no lparam */
1112 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, 0);
1113
1114 flush_events();
1115
1116 /* WM_DDE_EXECUTE, no hglobal */
1117 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, 0);
1118 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1119
1120 flush_events();
1121
1122 /* WM_DDE_EXECUTE, no client hwnd */
1123 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1124 PostMessageA(server_hwnd, WM_DDE_EXECUTE, 0, lparam);
1125
1126 flush_events();
1127
1128 /* WM_DDE_EXECUTE, all params correct */
1129 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1130 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1131
1132 flush_events();
1133
1134 GlobalFree(execute_hglobal);
1135 execute_hglobal = create_execute("[Command-2(Var)]");
1136
1137 /* WM_DDE_EXECUTE, all params correct */
1138 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1139 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1140
1141 flush_events();
1142
1143 GlobalFree(execute_hglobal);
1144 execute_hglobal = create_execute("[BadCommand(Var)]");
1145
1146 /* WM_DDE_EXECUTE that will get rejected */
1147 lparam = PackDDElParam(WM_DDE_EXECUTE, 0, (UINT_PTR)execute_hglobal);
1148 PostMessageA(server_hwnd, WM_DDE_EXECUTE, (WPARAM)client_hwnd, lparam);
1149
1150 flush_events();
1151
1152 destroy_dde_window(&client_hwnd, "dde_client");
1153 }
1154
1155 static LRESULT WINAPI hook_dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1156 {
1157 UINT_PTR lo, hi;
1158
1159 trace("hook_dde_client_wndproc: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1160
1161 switch (msg)
1162 {
1163 case WM_DDE_ACK:
1164 UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1165 trace("WM_DDE_ACK: status %04lx hglobal %p\n", lo, (HGLOBAL)hi);
1166 break;
1167
1168 default:
1169 break;
1170 }
1171 return CallWindowProcA(old_dde_client_wndproc, hwnd, msg, wparam, lparam);
1172 }
1173
1174 static LRESULT WINAPI dde_server_wndprocW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1175 {
1176 trace("dde_server_wndprocW: %p %04x %08lx %08lx\n", hwnd, msg, wparam, lparam);
1177
1178 switch (msg)
1179 {
1180 case WM_DDE_INITIATE:
1181 {
1182 ATOM aService = GlobalAddAtomW(TEST_DDE_SERVICE);
1183
1184 trace("server: got WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);
1185
1186 if (LOWORD(lparam) == aService)
1187 {
1188 ok(!IsWindowUnicode((HWND)wparam), "client should be an ANSI window\n");
1189 old_dde_client_wndproc = (WNDPROC)SetWindowLongPtrA((HWND)wparam, GWLP_WNDPROC, (ULONG_PTR)hook_dde_client_wndproc);
1190 trace("server: sending WM_DDE_ACK to %p\n", (HWND)wparam);
1191 SendMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aService, 0));
1192 }
1193 else
1194 GlobalDeleteAtom(aService);
1195 return 0;
1196 }
1197
1198 case WM_DDE_EXECUTE:
1199 {
1200 DDEACK ack;
1201 WORD status;
1202 LPCSTR cmd;
1203 UINT_PTR lo, hi;
1204
1205 trace("server: got WM_DDE_EXECUTE from %p with %08lx\n", (HWND)wparam, lparam);
1206
1207 UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
1208 trace("%08lx => lo %04lx hi %04lx\n", lparam, lo, hi);
1209
1210 ack.bAppReturnCode = 0;
1211 ack.reserved = 0;
1212 ack.fBusy = 0;
1213
1214 cmd = GlobalLock((HGLOBAL)hi);
1215 if (!cmd || (lstrcmpA(cmd, exec_cmdA) && lstrcmpW((LPCWSTR)cmd, exec_cmdW)))
1216 {
1217 trace("ignoring unknown WM_DDE_EXECUTE command\n");
1218 /* We have to send a negative acknowledge even if we don't
1219 * accept the command, otherwise Windows goes mad and next time
1220 * we send an acknowledge DDEML drops the connection.
1221 * Not sure how to call it: a bug or a feature.
1222 */
1223 ack.fAck = 0;
1224 }
1225 else
1226 ack.fAck = 1;
1227 GlobalUnlock((HGLOBAL)hi);
1228
1229 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1230
1231 status = *((WORD *)&ack);
1232 lparam = ReuseDDElParam(lparam, WM_DDE_EXECUTE, WM_DDE_ACK, status, hi);
1233
1234 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1235 return 0;
1236 }
1237
1238 case WM_DDE_TERMINATE:
1239 {
1240 DDEACK ack;
1241 WORD status;
1242
1243 trace("server: got WM_DDE_TERMINATE from %p with %08lx\n", (HWND)wparam, lparam);
1244
1245 ack.bAppReturnCode = 0;
1246 ack.reserved = 0;
1247 ack.fBusy = 0;
1248 ack.fAck = 1;
1249
1250 trace("server: posting %s WM_DDE_ACK to %p\n", ack.fAck ? "POSITIVE" : "NEGATIVE", (HWND)wparam);
1251
1252 status = *((WORD *)&ack);
1253 lparam = PackDDElParam(WM_DDE_ACK, status, 0);
1254
1255 PostMessageW((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, lparam);
1256 return 0;
1257 }
1258
1259 default:
1260 break;
1261 }
1262
1263 return DefWindowProcW(hwnd, msg, wparam, lparam);
1264 }
1265
1266 static LRESULT WINAPI dde_client_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1267 {
1268 return DefWindowProcA(hwnd, msg, wparam, lparam);
1269 }
1270
1271 static BOOL create_dde_windows(HWND *client, HWND *server)
1272 {
1273 WNDCLASSA wcA;
1274 WNDCLASSW wcW;
1275 static const WCHAR server_class_name[] = {'d','d','e','_','s','e','r','v','e','r','_','w','i','n','d','o','w',0};
1276 static const char client_class_name[] = "dde_client_window";
1277
1278 memset(&wcW, 0, sizeof(wcW));
1279 wcW.lpfnWndProc = dde_server_wndprocW;
1280 wcW.lpszClassName = server_class_name;
1281 wcW.hInstance = GetModuleHandleA(0);
1282 if (!RegisterClassW(&wcW)) return FALSE;
1283
1284 memset(&wcA, 0, sizeof(wcA));
1285 wcA.lpfnWndProc = dde_client_wndproc;
1286 wcA.lpszClassName = client_class_name;
1287 wcA.hInstance = GetModuleHandleA(0);
1288 assert(RegisterClassA(&wcA));
1289
1290 *server = CreateWindowExW(0, server_class_name, NULL,
1291 WS_POPUP,
1292 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1293 GetDesktopWindow(), 0,
1294 GetModuleHandleA(0), NULL);
1295 assert(*server);
1296
1297 *client = CreateWindowExA(0, client_class_name, NULL,
1298 WS_POPUP,
1299 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1300 GetDesktopWindow(), 0,
1301 GetModuleHandleA(0), NULL);
1302 assert(*client);
1303
1304 trace("server hwnd %p, client hwnd %p\n", *server, *client);
1305
1306 ok(IsWindowUnicode(*server), "server has to be a unicode window\n");
1307 ok(!IsWindowUnicode(*client), "client has to be an ANSI window\n");
1308
1309 return TRUE;
1310 }
1311
1312 static HDDEDATA CALLBACK client_dde_callback(UINT uType, UINT uFmt, HCONV hconv,
1313 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
1314 ULONG_PTR dwData1, ULONG_PTR dwData2)
1315 {
1316 static const char * const cmd_type[15] = {
1317 "XTYP_ERROR", "XTYP_ADVDATA", "XTYP_ADVREQ", "XTYP_ADVSTART",
1318 "XTYP_ADVSTOP", "XTYP_EXECUTE", "XTYP_CONNECT", "XTYP_CONNECT_CONFIRM",
1319 "XTYP_XACT_COMPLETE", "XTYP_POKE", "XTYP_REGISTER", "XTYP_REQUEST",
1320 "XTYP_DISCONNECT", "XTYP_UNREGISTER", "XTYP_WILDCONNECT" };
1321 UINT type;
1322 const char *cmd_name;
1323
1324 type = (uType & XTYP_MASK) >> XTYP_SHIFT;
1325 cmd_name = (type <= 14) ? cmd_type[type] : "unknown";
1326
1327 trace("client_dde_callback: %04x (%s) %d %p %p %p %p %08lx %08lx\n",
1328 uType, cmd_name, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);
1329 return 0;
1330 }
1331
1332 static void test_dde_aw_transaction(void)
1333 {
1334 HSZ hsz_server;
1335 DWORD dde_inst, ret, err;
1336 HCONV hconv;
1337 HWND hwnd_client, hwnd_server;
1338 CONVINFO info;
1339 HDDEDATA hdata;
1340 static char test_cmd[] = "test dde command";
1341
1342 /* server: unicode, client: ansi */
1343 if (!create_dde_windows(&hwnd_client, &hwnd_server)) return;
1344
1345 dde_inst = 0;
1346 ret = DdeInitializeA(&dde_inst, client_dde_callback, APPCMD_CLIENTONLY, 0);
1347 ok(ret == DMLERR_NO_ERROR, "DdeInitializeA failed with error %04x (%x)\n",
1348 ret, DdeGetLastError(dde_inst));
1349
1350 hsz_server = DdeCreateStringHandleW(dde_inst, TEST_DDE_SERVICE, CP_WINUNICODE);
1351
1352 hconv = DdeConnect(dde_inst, hsz_server, 0, NULL);
1353 ok(hconv != 0, "DdeConnect error %x\n", DdeGetLastError(dde_inst));
1354 err = DdeGetLastError(dde_inst);
1355 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1356
1357 info.cb = sizeof(info);
1358 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1359 ok(ret, "wrong info size %d, DdeQueryConvInfo error %x\n", ret, DdeGetLastError(dde_inst));
1360 /* should be CP_WINANSI since we used DdeInitializeA */
1361 ok(info.ConvCtxt.iCodePage == CP_WINANSI, "wrong iCodePage %d\n", info.ConvCtxt.iCodePage);
1362 ok(!info.hConvPartner, "unexpected info.hConvPartner: %p\n", info.hConvPartner);
1363 todo_wine {
1364 ok((info.wStatus & DDE_FACK), "unexpected info.wStatus: %04x\n", info.wStatus);
1365 }
1366 ok((info.wStatus & (ST_CONNECTED | ST_CLIENT)) == (ST_CONNECTED | ST_CLIENT), "unexpected info.wStatus: %04x\n", info.wStatus);
1367 ok(info.wConvst == XST_CONNECTED, "unexpected info.wConvst: %04x\n", info.wConvst);
1368 ok(info.wType == 0, "unexpected info.wType: %04x\n", info.wType);
1369
1370 trace("hwnd %p, hwndPartner %p\n", info.hwnd, info.hwndPartner);
1371
1372 trace("sending test client transaction command\n");
1373 ret = 0xdeadbeef;
1374 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1, hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
1375 ok(!hdata, "DdeClientTransaction succeeded\n");
1376 ok(ret == DDE_FNOTPROCESSED, "wrong status code %04x\n", ret);
1377 err = DdeGetLastError(dde_inst);
1378 ok(err == DMLERR_NOTPROCESSED, "wrong dde error %x\n", err);
1379
1380 trace("sending ANSI client transaction command\n");
1381 ret = 0xdeadbeef;
1382 hdata = DdeClientTransaction((LPBYTE)exec_cmdA, lstrlenA(exec_cmdA) + 1, hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1383 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1384 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1385
1386 err = DdeGetLastError(dde_inst);
1387 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1388
1389 trace("sending unicode client transaction command\n");
1390 ret = 0xdeadbeef;
1391 hdata = DdeClientTransaction((LPBYTE)exec_cmdW, (lstrlenW(exec_cmdW) + 1) * sizeof(WCHAR), hconv, 0, 0, XTYP_EXECUTE, 1000, &ret);
1392 ok(hdata != 0, "DdeClientTransaction returned %p, error %x\n", hdata, DdeGetLastError(dde_inst));
1393 ok(ret == DDE_FACK, "wrong status code %04x\n", ret);
1394 err = DdeGetLastError(dde_inst);
1395 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
1396
1397 ok(DdeDisconnect(hconv), "DdeDisconnect error %x\n", DdeGetLastError(dde_inst));
1398
1399 info.cb = sizeof(info);
1400 ret = DdeQueryConvInfo(hconv, QID_SYNC, &info);
1401 ok(!ret, "DdeQueryConvInfo should fail\n");
1402 err = DdeGetLastError(dde_inst);
1403 todo_wine {
1404 ok(err == DMLERR_INVALIDPARAMETER, "wrong dde error %x\n", err);
1405 }
1406
1407 ok(DdeFreeStringHandle(dde_inst, hsz_server), "DdeFreeStringHandle error %x\n", DdeGetLastError(dde_inst));
1408
1409 /* This call hangs on win2k SP4 and XP SP1.
1410 DdeUninitialize(dde_inst);*/
1411
1412 DestroyWindow(hwnd_client);
1413 DestroyWindow(hwnd_server);
1414 }
1415
1416 static void test_initialisation(void)
1417 {
1418 UINT ret;
1419 DWORD res;
1420 HDDEDATA hdata;
1421 HSZ server, topic, item;
1422 DWORD client_pid;
1423 HCONV conversation;
1424
1425 /* Initialise without a valid server window. */
1426 client_pid = 0;
1427 ret = DdeInitializeA(&client_pid, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1428 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", ret);
1429
1430
1431 server = DdeCreateStringHandleA(client_pid, "TestDDEService", CP_WINANSI);
1432 topic = DdeCreateStringHandleA(client_pid, "TestDDETopic", CP_WINANSI);
1433
1434 DdeGetLastError(client_pid);
1435
1436 /* There is no server window so no conversation can be extracted */
1437 conversation = DdeConnect(client_pid, server, topic, NULL);
1438 ok(conversation == NULL, "Expected NULL conversation, %p\n", conversation);
1439 ret = DdeGetLastError(client_pid);
1440 ok(ret == DMLERR_NO_CONV_ESTABLISHED, "Expected DMLERR_NO_CONV_ESTABLISHED, got %d\n", ret);
1441
1442 DdeFreeStringHandle(client_pid, server);
1443
1444 item = DdeCreateStringHandleA(client_pid, "request", CP_WINANSI);
1445
1446 /* There is no converstation so an invalild parameter results */
1447 res = 0xdeadbeef;
1448 DdeGetLastError(client_pid);
1449 hdata = DdeClientTransaction(NULL, 0, conversation, item, CF_TEXT, XTYP_REQUEST, default_timeout, &res);
1450 ret = DdeGetLastError(client_pid);
1451 todo_wine
1452 ok(ret == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", ret);
1453 ok(res == 0xdeadbeef, "Expected 0xdeadbeef, got %08x\n", res);
1454
1455 DdeFreeStringHandle(client_pid, server);
1456 ret = DdeDisconnect(conversation);
1457 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1458
1459 ret = DdeUninitialize(client_pid);
1460 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1461 }
1462
1463 static void test_DdeCreateStringHandleW(DWORD dde_inst, int codepage)
1464 {
1465 static const WCHAR dde_string[] = {'D','D','E',' ','S','t','r','i','n','g',0};
1466 HSZ str_handle;
1467 WCHAR bufW[256];
1468 char buf[256];
1469 ATOM atom;
1470 int ret;
1471
1472 str_handle = DdeCreateStringHandleW(dde_inst, dde_string, codepage);
1473 ok(str_handle != 0, "DdeCreateStringHandleW failed with error %08x\n",
1474 DdeGetLastError(dde_inst));
1475
1476 ret = DdeQueryStringW(dde_inst, str_handle, NULL, 0, codepage);
1477 if (codepage == CP_WINANSI)
1478 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1479 else
1480 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1481
1482 ret = DdeQueryStringW(dde_inst, str_handle, bufW, 256, codepage);
1483 if (codepage == CP_WINANSI)
1484 {
1485 ok(ret == 1, "DdeQueryStringW returned wrong length %d\n", ret);
1486 ok(!lstrcmpA("D", (LPCSTR)bufW), "DdeQueryStringW returned wrong string\n");
1487 }
1488 else
1489 {
1490 ok(ret == lstrlenW(dde_string), "DdeQueryStringW returned wrong length %d\n", ret);
1491 ok(!lstrcmpW(dde_string, bufW), "DdeQueryStringW returned wrong string\n");
1492 }
1493
1494 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINANSI);
1495 if (codepage == CP_WINANSI)
1496 {
1497 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1498 ok(!lstrcmpA("D", buf), "DdeQueryStringW returned wrong string\n");
1499 }
1500 else
1501 {
1502 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1503 ok(!lstrcmpA("DDE String", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1504 }
1505
1506 ret = DdeQueryStringA(dde_inst, str_handle, buf, 256, CP_WINUNICODE);
1507 if (codepage == CP_WINANSI)
1508 {
1509 ok(ret == 1, "DdeQueryStringA returned wrong length %d\n", ret);
1510 ok(!lstrcmpA("D", buf), "DdeQueryStringA returned wrong string %s\n", buf);
1511 }
1512 else
1513 {
1514 ok(ret == lstrlenA("DDE String"), "DdeQueryStringA returned wrong length %d\n", ret);
1515 ok(!lstrcmpW(dde_string, (LPCWSTR)buf), "DdeQueryStringW returned wrong string\n");
1516 }
1517
1518 if (codepage == CP_WINANSI)
1519 {
1520 atom = FindAtomA((LPSTR)dde_string);
1521 ok(atom != 0, "Expected a valid atom\n");
1522
1523 SetLastError(0xdeadbeef);
1524 atom = GlobalFindAtomA((LPSTR)dde_string);
1525 ok(atom == 0, "Expected 0, got %d\n", atom);
1526 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1527 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1528 }
1529 else
1530 {
1531 atom = FindAtomW(dde_string);
1532 ok(atom != 0, "Expected a valid atom\n");
1533
1534 SetLastError(0xdeadbeef);
1535 atom = GlobalFindAtomW(dde_string);
1536 ok(atom == 0, "Expected 0, got %d\n", atom);
1537 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
1538 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
1539 }
1540
1541 ok(DdeFreeStringHandle(dde_inst, str_handle), "DdeFreeStringHandle failed\n");
1542 }
1543
1544 static void test_DdeCreateDataHandle(void)
1545 {
1546 HDDEDATA hdata;
1547 DWORD dde_inst, dde_inst2;
1548 DWORD size;
1549 UINT res, err;
1550 BOOL ret;
1551 HSZ item;
1552 LPBYTE ptr;
1553 WCHAR item_str[] = {'i','t','e','m',0};
1554
1555 dde_inst = 0;
1556 dde_inst2 = 0;
1557 res = DdeInitializeA(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1558 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1559
1560 res = DdeInitializeA(&dde_inst2, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1561 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1562
1563 /* 0 instance id
1564 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1565 * is invalid then the lastError of all instances is set to the error. There are two instances
1566 * created, lastError is cleared, an error is generated and then both instances are checked to
1567 * ensure that they both have the same error set
1568 */
1569 item = DdeCreateStringHandleA(0, "item", CP_WINANSI);
1570 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1571 err = DdeGetLastError(dde_inst);
1572 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1573 err = DdeGetLastError(dde_inst2);
1574 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1575 item = DdeCreateStringHandleW(0, item_str, CP_WINUNICODE);
1576 ok(item == NULL, "Expected NULL hsz got %p\n", item);
1577 err = DdeGetLastError(dde_inst);
1578 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1579 err = DdeGetLastError(dde_inst2);
1580 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1581
1582 item = DdeCreateStringHandleA(dde_inst, "item", CP_WINANSI);
1583 ok(item != NULL, "Expected non-NULL hsz\n");
1584 item = DdeCreateStringHandleA(dde_inst2, "item", CP_WINANSI);
1585 ok(item != NULL, "Expected non-NULL hsz\n");
1586
1587 if (0) {
1588 /* do not test with an invalid instance id: that crashes on win9x */
1589 hdata = DdeCreateDataHandle(0xdeadbeef, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1590 }
1591
1592 /* 0 instance id
1593 * This block tests an invalid instance Id. The correct behaviour is that if the instance Id
1594 * is invalid then the lastError of all instances is set to the error. There are two instances
1595 * created, lastError is cleared, an error is generated and then both instances are checked to
1596 * ensure that they both have the same error set
1597 */
1598 DdeGetLastError(dde_inst);
1599 DdeGetLastError(dde_inst2);
1600 hdata = DdeCreateDataHandle(0, (LPBYTE)"data", MAX_PATH, 0, item, CF_TEXT, 0);
1601 err = DdeGetLastError(dde_inst);
1602 ok(hdata == NULL, "Expected NULL, got %p\n", hdata);
1603 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1604 err = DdeGetLastError(dde_inst2);
1605 ok(err == DMLERR_INVALIDPARAMETER, "Expected DMLERR_INVALIDPARAMETER, got %d\n", err);
1606
1607 ret = DdeUninitialize(dde_inst2);
1608 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1609
1610
1611 /* NULL pSrc */
1612 DdeGetLastError(dde_inst);
1613 hdata = DdeCreateDataHandle(dde_inst, NULL, MAX_PATH, 0, item, CF_TEXT, 0);
1614 err = DdeGetLastError(dde_inst);
1615 ok(hdata != NULL, "Expected non-NULL hdata\n");
1616 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1617
1618 ptr = GlobalLock(hdata);
1619 todo_wine
1620 {
1621 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1622 }
1623
1624 ptr = DdeAccessData(hdata, &size);
1625 ok(ptr != NULL, "Expected non-NULL ptr\n");
1626 ok(size == 260, "Expected 260, got %d\n", size);
1627
1628 ret = DdeUnaccessData(hdata);
1629 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1630
1631 ret = DdeFreeDataHandle(hdata);
1632 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1633
1634 /* cb is zero */
1635 DdeGetLastError(dde_inst);
1636 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", 0, 0, item, CF_TEXT, 0);
1637 err = DdeGetLastError(dde_inst);
1638 ok(hdata != NULL, "Expected non-NULL hdata\n");
1639 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1640
1641 ptr = GlobalLock(hdata);
1642 todo_wine
1643 {
1644 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1645 }
1646
1647 ptr = DdeAccessData(hdata, &size);
1648 ok(ptr != NULL, "Expected non-NULL ptr\n");
1649 ok(size == 0, "Expected 0, got %d\n", size);
1650
1651 ret = DdeUnaccessData(hdata);
1652 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1653
1654 ret = DdeFreeDataHandle(hdata);
1655 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1656
1657 /* cbOff is non-zero */
1658 DdeGetLastError(dde_inst);
1659 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 2, item, CF_TEXT, 0);
1660 err = DdeGetLastError(dde_inst);
1661 ok(hdata != NULL, "Expected non-NULL hdata\n");
1662 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1663
1664 ptr = GlobalLock(hdata);
1665 todo_wine
1666 {
1667 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1668 }
1669
1670 ptr = DdeAccessData(hdata, &size);
1671 ok(ptr != NULL, "Expected non-NULL ptr\n");
1672 ok(size == 262, "Expected 262, got %d\n", size);
1673 todo_wine
1674 {
1675 ok(lstrlenA((LPSTR)ptr) == 0, "Expected 0, got %d\n", lstrlenA((LPSTR)ptr));
1676 }
1677
1678 ret = DdeUnaccessData(hdata);
1679 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1680
1681 ret = DdeFreeDataHandle(hdata);
1682 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1683
1684 /* NULL item */
1685 DdeGetLastError(dde_inst);
1686 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, 0, CF_TEXT, 0);
1687 err = DdeGetLastError(dde_inst);
1688 ok(hdata != NULL, "Expected non-NULL hdata\n");
1689 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1690
1691 ptr = GlobalLock(hdata);
1692 todo_wine
1693 {
1694 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1695 }
1696
1697 ptr = DdeAccessData(hdata, &size);
1698 ok(ptr != NULL, "Expected non-NULL ptr\n");
1699 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1700 ok(size == 260, "Expected 260, got %d\n", size);
1701
1702 ret = DdeUnaccessData(hdata);
1703 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1704
1705 ret = DdeFreeDataHandle(hdata);
1706 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1707
1708 /* NULL item */
1709 DdeGetLastError(dde_inst);
1710 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, (HSZ)0xdeadbeef, CF_TEXT, 0);
1711 err = DdeGetLastError(dde_inst);
1712 ok(hdata != NULL, "Expected non-NULL hdata\n");
1713 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1714
1715 ptr = GlobalLock(hdata);
1716 todo_wine
1717 {
1718 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1719 }
1720
1721 ptr = DdeAccessData(hdata, &size);
1722 ok(ptr != NULL, "Expected non-NULL ptr\n");
1723 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1724 ok(size == 260, "Expected 260, got %d\n", size);
1725
1726 ret = DdeUnaccessData(hdata);
1727 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1728
1729 ret = DdeFreeDataHandle(hdata);
1730 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1731
1732 /* invalid clipboard format */
1733 DdeGetLastError(dde_inst);
1734 hdata = DdeCreateDataHandle(dde_inst, (LPBYTE)"data", MAX_PATH, 0, item, 0xdeadbeef, 0);
1735 err = DdeGetLastError(dde_inst);
1736 ok(hdata != NULL, "Expected non-NULL hdata\n");
1737 ok(err == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", err);
1738
1739 ptr = GlobalLock(hdata);
1740 todo_wine
1741 {
1742 ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
1743 }
1744
1745 ptr = DdeAccessData(hdata, &size);
1746 ok(ptr != NULL, "Expected non-NULL ptr\n");
1747 ok(!lstrcmpA((LPSTR)ptr, "data"), "Expected data, got %s\n", ptr);
1748 ok(size == 260, "Expected 260, got %d\n", size);
1749
1750 ret = DdeUnaccessData(hdata);
1751 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1752
1753 ret = DdeFreeDataHandle(hdata);
1754 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1755
1756 ret = DdeUninitialize(dde_inst);
1757 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
1758 }
1759
1760 static void test_DdeCreateStringHandle(void)
1761 {
1762 DWORD dde_inst, ret;
1763
1764 dde_inst = 0xdeadbeef;
1765 SetLastError(0xdeadbeef);
1766 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1767 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1768 {
1769 win_skip("DdeInitializeW is unimplemented\n");
1770 return;
1771 }
1772
1773 ok(ret == DMLERR_INVALIDPARAMETER, "DdeInitializeW should fail, but got %04x instead\n", ret);
1774 ok(DdeGetLastError(dde_inst) == DMLERR_INVALIDPARAMETER, "expected DMLERR_INVALIDPARAMETER\n");
1775
1776 dde_inst = 0;
1777 ret = DdeInitializeW(&dde_inst, client_ddeml_callback, APPCMD_CLIENTONLY, 0);
1778 ok(ret == DMLERR_NO_ERROR, "DdeInitializeW failed with error %04x (%08x)\n",
1779 ret, DdeGetLastError(dde_inst));
1780
1781 test_DdeCreateStringHandleW(dde_inst, 0);
1782 test_DdeCreateStringHandleW(dde_inst, CP_WINUNICODE);
1783 test_DdeCreateStringHandleW(dde_inst, CP_WINANSI);
1784
1785 ok(DdeUninitialize(dde_inst), "DdeUninitialize failed\n");
1786 }
1787
1788 static void test_FreeDDElParam(void)
1789 {
1790 HGLOBAL val, hglobal;
1791 BOOL ret;
1792
1793 ret = FreeDDElParam(WM_DDE_INITIATE, 0);
1794 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1795
1796 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1797 ret = FreeDDElParam(WM_DDE_INITIATE, (LPARAM)hglobal);
1798 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1799 val = GlobalFree(hglobal);
1800 ok(val == NULL, "Expected NULL, got %p\n", val);
1801
1802 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1803 ret = FreeDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal);
1804 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1805 val = GlobalFree(hglobal);
1806 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1807 ok(GetLastError() == ERROR_INVALID_HANDLE,
1808 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1809
1810 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1811 ret = FreeDDElParam(WM_DDE_UNADVISE, (LPARAM)hglobal);
1812 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1813 val = GlobalFree(hglobal);
1814 ok(val == NULL, "Expected NULL, got %p\n", val);
1815
1816 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1817 ret = FreeDDElParam(WM_DDE_ACK, (LPARAM)hglobal);
1818 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1819 val = GlobalFree(hglobal);
1820 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1821 ok(GetLastError() == ERROR_INVALID_HANDLE,
1822 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1823
1824 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1825 ret = FreeDDElParam(WM_DDE_DATA, (LPARAM)hglobal);
1826 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1827 val = GlobalFree(hglobal);
1828 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1829 ok(GetLastError() == ERROR_INVALID_HANDLE,
1830 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1831
1832 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1833 ret = FreeDDElParam(WM_DDE_REQUEST, (LPARAM)hglobal);
1834 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1835 val = GlobalFree(hglobal);
1836 ok(val == NULL, "Expected NULL, got %p\n", val);
1837
1838 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1839 ret = FreeDDElParam(WM_DDE_POKE, (LPARAM)hglobal);
1840 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1841 val = GlobalFree(hglobal);
1842 ok(val == hglobal, "Expected hglobal, got %p\n", val);
1843 ok(GetLastError() == ERROR_INVALID_HANDLE,
1844 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1845
1846 hglobal = GlobalAlloc(GMEM_DDESHARE, 100);
1847 ret = FreeDDElParam(WM_DDE_EXECUTE, (LPARAM)hglobal);
1848 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1849 val = GlobalFree(hglobal);
1850 ok(val == NULL, "Expected NULL, got %p\n", val);
1851 }
1852
1853 static void test_PackDDElParam(void)
1854 {
1855 UINT_PTR lo, hi, *ptr;
1856 HGLOBAL hglobal;
1857 LPARAM lparam;
1858 BOOL ret;
1859
1860 lparam = PackDDElParam(WM_DDE_INITIATE, 0xcafe, 0xbeef);
1861 /* value gets sign-extended despite being an LPARAM */
1862 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1863 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1864 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1865 ok(GetLastError() == ERROR_INVALID_HANDLE,
1866 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1867
1868 lo = hi = 0;
1869 ret = UnpackDDElParam(WM_DDE_INITIATE, lparam, &lo, &hi);
1870 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1871 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1872 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1873
1874 ret = FreeDDElParam(WM_DDE_INITIATE, lparam);
1875 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1876
1877 lparam = PackDDElParam(WM_DDE_TERMINATE, 0xcafe, 0xbeef);
1878 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1879 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1880 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1881 ok(GetLastError() == ERROR_INVALID_HANDLE,
1882 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1883
1884 lo = hi = 0;
1885 ret = UnpackDDElParam(WM_DDE_TERMINATE, lparam, &lo, &hi);
1886 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1887 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1888 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1889
1890 ret = FreeDDElParam(WM_DDE_TERMINATE, lparam);
1891 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1892
1893 lparam = PackDDElParam(WM_DDE_ADVISE, 0xcafe, 0xbeef);
1894 /* win9x returns 0 here */
1895 if (lparam) {
1896 ptr = GlobalLock((HGLOBAL)lparam);
1897 ok(ptr != NULL, "Expected non-NULL ptr\n");
1898 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1899 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1900
1901 ret = GlobalUnlock((HGLOBAL)lparam);
1902 ok(ret == 1, "Expected 1, got %d\n", ret);
1903
1904 lo = hi = 0;
1905 ret = UnpackDDElParam(WM_DDE_ADVISE, lparam, &lo, &hi);
1906 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1907 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1908 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1909 }
1910 else
1911 win_skip("no lparam for WM_DDE_ADVISE\n");
1912
1913 ret = FreeDDElParam(WM_DDE_ADVISE, lparam);
1914 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1915
1916 hglobal = GlobalFree((HGLOBAL)lparam);
1917 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1918 ok(GetLastError() == ERROR_INVALID_HANDLE,
1919 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1920
1921 lparam = PackDDElParam(WM_DDE_UNADVISE, 0xcafe, 0xbeef);
1922 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1923 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1924 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1925 ok(GetLastError() == ERROR_INVALID_HANDLE,
1926 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1927
1928 lo = hi = 0;
1929 ret = UnpackDDElParam(WM_DDE_UNADVISE, lparam, &lo, &hi);
1930 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1931 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1932 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1933
1934 ret = FreeDDElParam(WM_DDE_UNADVISE, lparam);
1935 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1936
1937 lparam = PackDDElParam(WM_DDE_ACK, 0xcafe, 0xbeef);
1938 /* win9x returns the input (0xbeef<<16 | 0xcafe) here */
1939 if (lparam != (int)0xbeefcafe) {
1940 ptr = GlobalLock((HGLOBAL)lparam);
1941 ok(ptr != NULL, "Expected non-NULL ptr\n");
1942 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1943 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1944
1945 ret = GlobalUnlock((HGLOBAL)lparam);
1946 ok(ret == 1, "Expected 1, got %d\n", ret);
1947
1948 lo = hi = 0;
1949 ret = UnpackDDElParam(WM_DDE_ACK, lparam, &lo, &hi);
1950 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1951 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1952 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1953
1954 ret = FreeDDElParam(WM_DDE_ACK, lparam);
1955 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1956
1957 hglobal = GlobalFree((HGLOBAL)lparam);
1958 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1959 ok(GetLastError() == ERROR_INVALID_HANDLE,
1960 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1961 }
1962 else
1963 win_skip("got lparam 0x%lx for WM_DDE_ACK\n", lparam);
1964
1965 lparam = PackDDElParam(WM_DDE_DATA, 0xcafe, 0xbeef);
1966 /* win9x returns 0 here */
1967 if (lparam) {
1968 ptr = GlobalLock((HGLOBAL)lparam);
1969 ok(ptr != NULL, "Expected non-NULL ptr\n");
1970 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
1971 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
1972
1973 ret = GlobalUnlock((HGLOBAL)lparam);
1974 ok(ret == 1, "Expected 1, got %d\n", ret);
1975
1976 lo = hi = 0;
1977 ret = UnpackDDElParam(WM_DDE_DATA, lparam, &lo, &hi);
1978 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1979 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
1980 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
1981 }
1982 else
1983 win_skip("no lparam for WM_DDE_DATA\n");
1984
1985 ret = FreeDDElParam(WM_DDE_DATA, lparam);
1986 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1987
1988 hglobal = GlobalFree((HGLOBAL)lparam);
1989 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
1990 ok(GetLastError() == ERROR_INVALID_HANDLE,
1991 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1992
1993 lparam = PackDDElParam(WM_DDE_REQUEST, 0xcafe, 0xbeef);
1994 ok(lparam == (int)0xbeefcafe, "Expected 0xbeefcafe, got %08lx\n", lparam);
1995 ok(GlobalLock((HGLOBAL)lparam) == NULL,
1996 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
1997 ok(GetLastError() == ERROR_INVALID_HANDLE,
1998 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1999
2000 lo = hi = 0;
2001 ret = UnpackDDElParam(WM_DDE_REQUEST, lparam, &lo, &hi);
2002 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2003 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2004 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2005
2006 ret = FreeDDElParam(WM_DDE_REQUEST, lparam);
2007 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2008
2009 lparam = PackDDElParam(WM_DDE_POKE, 0xcafe, 0xbeef);
2010 /* win9x returns 0 here */
2011 if (lparam) {
2012 ptr = GlobalLock((HGLOBAL)lparam);
2013 ok(ptr != NULL, "Expected non-NULL ptr\n");
2014 ok(ptr[0] == 0xcafe, "Expected 0xcafe, got %08lx\n", ptr[0]);
2015 ok(ptr[1] == 0xbeef, "Expected 0xbeef, got %08lx\n", ptr[1]);
2016
2017 ret = GlobalUnlock((HGLOBAL)lparam);
2018 ok(ret == 1, "Expected 1, got %d\n", ret);
2019
2020 lo = hi = 0;
2021 ret = UnpackDDElParam(WM_DDE_POKE, lparam, &lo, &hi);
2022 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2023 ok(lo == 0xcafe, "Expected 0xcafe, got %08lx\n", lo);
2024 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2025 }
2026 else
2027 win_skip("no lparam for WM_DDE_POKE\n");
2028
2029 ret = FreeDDElParam(WM_DDE_POKE, lparam);
2030 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2031
2032 hglobal = GlobalFree((HGLOBAL)lparam);
2033 ok(hglobal == (HGLOBAL)lparam, "Expected lparam, got %d\n", ret);
2034 ok(GetLastError() == ERROR_INVALID_HANDLE,
2035 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
2036
2037 lparam = PackDDElParam(WM_DDE_EXECUTE, 0xcafe, 0xbeef);
2038 ok(lparam == 0xbeef, "Expected 0xbeef, got %08lx\n", lparam);
2039 ok(GlobalLock((HGLOBAL)lparam) == NULL,
2040 "Expected NULL, got %p\n", GlobalLock((HGLOBAL)lparam));
2041 ok(GetLastError() == ERROR_INVALID_HANDLE,
2042 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
2043
2044 lo = hi = 0;
2045 ret = UnpackDDElParam(WM_DDE_EXECUTE, lparam, &lo, &hi);
2046 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2047 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2048 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2049
2050 ret = FreeDDElParam(WM_DDE_EXECUTE, lparam);
2051 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2052 }
2053
2054 static void test_UnpackDDElParam(void)
2055 {
2056 UINT_PTR lo, hi, *ptr;
2057 HGLOBAL hglobal;
2058 BOOL ret;
2059
2060 /* NULL lParam */
2061 lo = 0xdead;
2062 hi = 0xbeef;
2063 ret = UnpackDDElParam(WM_DDE_INITIATE, 0, &lo, &hi);
2064 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2065 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2066 ok(hi == 0, "Expected 0, got %08lx\n", hi);
2067
2068 /* NULL lo */
2069 lo = 0xdead;
2070 hi = 0xbeef;
2071 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, NULL, &hi);
2072 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2073 ok(lo == 0xdead, "Expected 0xdead, got %08lx\n", lo);
2074 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2075
2076 /* NULL hi */
2077 lo = 0xdead;
2078 hi = 0xbeef;
2079 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, NULL);
2080 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2081 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2082 ok(hi == 0xbeef, "Expected 0xbeef, got %08lx\n", hi);
2083
2084 lo = 0xdead;
2085 hi = 0xbeef;
2086 ret = UnpackDDElParam(WM_DDE_INITIATE, 0xcafebabe, &lo, &hi);
2087 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2088 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2089 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2090
2091 lo = 0xdead;
2092 hi = 0xbeef;
2093 ret = UnpackDDElParam(WM_DDE_TERMINATE, 0xcafebabe, &lo, &hi);
2094 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2095 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2096 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2097
2098 lo = 0xdead;
2099 hi = 0xbeef;
2100 ret = UnpackDDElParam(WM_DDE_ADVISE, 0, &lo, &hi);
2101 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2102 ok(lo == 0 ||
2103 broken(lo == 0xdead), /* win2k */
2104 "Expected 0, got %08lx\n", lo);
2105 ok(hi == 0 ||
2106 broken(hi == 0xbeef), /* win2k */
2107 "Expected 0, got %08lx\n", hi);
2108
2109 lo = 0xdead;
2110 hi = 0xbeef;
2111 ret = UnpackDDElParam(WM_DDE_ADVISE, 0xcafebabe, &lo, &hi);
2112 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2113 ok(lo == 0 ||
2114 broken(lo == 0xdead), /* win2k */
2115 "Expected 0, got %08lx\n", lo);
2116 ok(hi == 0 ||
2117 broken(hi == 0xbeef), /* win2k */
2118 "Expected 0, got %08lx\n", hi);
2119
2120 hglobal = GlobalAlloc(GMEM_DDESHARE, 2);
2121 ptr = GlobalLock(hglobal);
2122 ptr[0] = 0xcafebabe;
2123 ptr[1] = 0xdeadbeef;
2124 GlobalUnlock(hglobal);
2125
2126 lo = 0xdead;
2127 hi = 0xbeef;
2128 ret = UnpackDDElParam(WM_DDE_ADVISE, (LPARAM)hglobal, &lo, &hi);
2129 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2130 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2131 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2132
2133 lo = 0xdead;
2134 hi = 0xbeef;
2135 ret = UnpackDDElParam(WM_DDE_UNADVISE, 0xcafebabe, &lo, &hi);
2136 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2137 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2138 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2139
2140 lo = 0xdead;
2141 hi = 0xbeef;
2142 ret = UnpackDDElParam(WM_DDE_ACK, 0xcafebabe, &lo, &hi);
2143 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2144 ok(lo == 0 ||
2145 broken(lo == 0xdead), /* win2k */
2146 "Expected 0, got %08lx\n", lo);
2147 ok(hi == 0 ||
2148 broken(hi == 0xbeef), /* win2k */
2149 "Expected 0, got %08lx\n", hi);
2150
2151 lo = 0xdead;
2152 hi = 0xbeef;
2153 ret = UnpackDDElParam(WM_DDE_ACK, (LPARAM)hglobal, &lo, &hi);
2154 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2155 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2156 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2157
2158 lo = 0xdead;
2159 hi = 0xbeef;
2160 ret = UnpackDDElParam(WM_DDE_DATA, 0xcafebabe, &lo, &hi);
2161 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2162 ok(lo == 0 ||
2163 broken(lo == 0xdead), /* win2k */
2164 "Expected 0, got %08lx\n", lo);
2165 ok(hi == 0 ||
2166 broken(hi == 0xbeef), /* win2k */
2167 "Expected 0, got %08lx\n", hi);
2168
2169 lo = 0xdead;
2170 hi = 0xbeef;
2171 ret = UnpackDDElParam(WM_DDE_DATA, (LPARAM)hglobal, &lo, &hi);
2172 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2173 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2174 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2175
2176 lo = 0xdead;
2177 hi = 0xbeef;
2178 ret = UnpackDDElParam(WM_DDE_REQUEST, 0xcafebabe, &lo, &hi);
2179 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2180 ok(lo == 0xbabe, "Expected 0xbabe, got %08lx\n", lo);
2181 ok(hi == 0xcafe, "Expected 0xcafe, got %08lx\n", hi);
2182
2183 lo = 0xdead;
2184 hi = 0xbeef;
2185 ret = UnpackDDElParam(WM_DDE_POKE, 0xcafebabe, &lo, &hi);
2186 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
2187 ok(lo == 0 ||
2188 broken(lo == 0xdead), /* win2k */
2189 "Expected 0, got %08lx\n", lo);
2190 ok(hi == 0 ||
2191 broken(hi == 0xbeef), /* win2k */
2192 "Expected 0, got %08lx\n", hi);
2193
2194 lo = 0xdead;
2195 hi = 0xbeef;
2196 ret = UnpackDDElParam(WM_DDE_POKE, (LPARAM)hglobal, &lo, &hi);
2197 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2198 ok(lo == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", lo);
2199 ok(hi == 0xdeadbeef, "Expected 0xdeadbeef, got %08lx\n", hi);
2200
2201 lo = 0xdead;
2202 hi = 0xbeef;
2203 ret = UnpackDDElParam(WM_DDE_EXECUTE, 0xcafebabe, &lo, &hi);
2204 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2205 ok(lo == 0, "Expected 0, got %08lx\n", lo);
2206 ok(hi == 0xcafebabe, "Expected 0xcafebabe, got %08lx\n", hi);
2207 }
2208
2209 static HDDEDATA CALLBACK server_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2210 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2211 ULONG_PTR dwData1, ULONG_PTR dwData2)
2212 {
2213 DWORD size, rsize;
2214 char str[MAX_PATH];
2215 static int msg_index = 0;
2216 static HCONV conversation = 0;
2217 static char test_cmd_w_to_a[] = "test dde command";
2218 static char test_cmd_a_to_a[] = "Test dde command";
2219 static WCHAR test_cmd_w_to_w[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2220 static WCHAR test_cmd_a_to_w[] = {'T','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2221 static char test_service [] = "TestDDEService";
2222 static char test_topic [] = "TestDDETopic";
2223
2224 msg_index++;
2225
2226 switch (uType)
2227 {
2228 case XTYP_REGISTER:
2229 {
2230 ok(msg_index == 1 || msg_index == 7 || msg_index == 13 || msg_index == 19,
2231 "Expected 1, 7, 13 or 19, got %d\n", msg_index);
2232 return (HDDEDATA)TRUE;
2233 }
2234
2235 case XTYP_CONNECT:
2236 {
2237 ok(msg_index == 2 || msg_index == 8 || msg_index == 14 || msg_index == 20,
2238 "Expected 2, 8, 14 or 20, got %d\n", msg_index);
2239 ok(uFmt == 0, "Expected 0, got %d, msg_index=%d\n", uFmt, msg_index);
2240 ok(hconv == 0, "Expected 0, got %p, msg_index=%d\n", hconv, msg_index);
2241 ok(hdata == 0, "Expected 0, got %p, msg_index=%d\n", hdata, msg_index);
2242 ok(dwData1 != 0, "Expected not 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2243 ok(dwData2 == FALSE, "Expected FALSE, got %08lx, msg_index=%d\n", dwData2, msg_index);
2244
2245 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2246 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2247 test_topic, str, msg_index);
2248 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2249
2250 size = DdeQueryStringA(server_pid, hsz2, str, MAX_PATH, CP_WINANSI);
2251 ok(!lstrcmpA(str, test_service), "Expected %s, got %s, msg_index=%d\n",
2252 test_service, str, msg_index);
2253 ok(size == 14, "Expected 14, got %d, msg_index=%d\n", size, msg_index);
2254
2255 return (HDDEDATA) TRUE;
2256 }
2257 case XTYP_CONNECT_CONFIRM:
2258 {
2259 ok(msg_index == 3 || msg_index == 9 || msg_index == 15 || msg_index == 21,
2260 "Expected 3, 9, 15 or 21 got %d\n", msg_index);
2261 conversation = hconv;
2262 return (HDDEDATA) TRUE;
2263 }
2264 case XTYP_EXECUTE:
2265 {
2266 BYTE *buffer = NULL;
2267
2268 ok(msg_index == 4 || msg_index == 5 || msg_index == 10 || msg_index == 11 ||
2269 msg_index == 16 || msg_index == 17 || msg_index == 22 || msg_index == 23,
2270 "Expected 4, 5, 10, 11, 16, 17, 22 or 23, got %d\n", msg_index);
2271 ok(uFmt == 0, "Expected 0, got %d\n", uFmt);
2272 ok(hconv == conversation, "Expected conversation handle, got %p, msg_index=%d\n",
2273 hconv, msg_index);
2274 ok(dwData1 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData1, msg_index);
2275 ok(dwData2 == 0, "Expected 0, got %08lx, msg_index=%d\n", dwData2, msg_index);
2276 ok(hsz2 == 0, "Expected 0, got %p, msg_index=%d\n", hsz2, msg_index);
2277 size = DdeQueryStringA(server_pid, hsz1, str, MAX_PATH, CP_WINANSI);
2278 ok(!lstrcmpA(str, test_topic), "Expected %s, got %s, msg_index=%d\n",
2279 test_topic, str, msg_index);
2280 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2281 ok(size == 12, "Expected 12, got %d, msg_index=%d\n", size, msg_index);
2282
2283 size = DdeGetData(hdata, NULL, 0, 0);
2284 if (msg_index == 10 || msg_index ==11 || msg_index == 16 || msg_index ==17)
2285 if (msg_index == 10 || msg_index == 16)
2286 todo_wine
2287 ok(size == 34, "Expected that size should be 34 not %d, msg_index=%d\n",
2288 size, msg_index);
2289 else
2290 ok(size == 34, "Expected that size should be 34 not %d, msg_index=%d\n",
2291 size, msg_index);
2292 else
2293 if (msg_index ==22)
2294 ok(size == 8 || size == 9, "Expected that size should be 8 or 9 not %d, msg_index=%d\n",
2295 size, msg_index);
2296 else
2297 if (msg_index == 5)
2298 todo_wine
2299 ok(size == 17, "Expected that size should be 17 not %d, msg_index=%d\n",
2300 size, msg_index);
2301 else
2302 ok(size == 17, "Expected that size should be 17 not %d, msg_index=%d\n",
2303 size, msg_index);
2304 ok((buffer = HeapAlloc(GetProcessHeap(), 0, size)) != NULL, "should not be null\n");
2305 rsize = DdeGetData(hdata, buffer, size, 0);
2306 if (msg_index == 10 || msg_index == 11 || msg_index == 16 || msg_index ==17)
2307 {
2308 ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2309 size, rsize, msg_index);
2310 if (msg_index == 10 || msg_index == 16)
2311 todo_wine {
2312 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_a_to_w),
2313 "Expected \"Test dde command\", msg_index=%d\n",
2314 msg_index);
2315 ok(size == 34, "Expected 34, got %d, msg_index=%d\n", size, msg_index);
2316 } else
2317 {
2318 ok(!lstrcmpW((WCHAR*)buffer, test_cmd_w_to_w),
2319 "Expected \"test dde command\", msg_index=%d\n",
2320 msg_index);
2321 ok(size == 34, "Expected 34, got %d, msg_index=%d\n", size, msg_index);
2322 }
2323 }else if (msg_index == 22)
2324 {
2325 ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2326 size, rsize, msg_index);
2327 } else
2328 {
2329 ok(rsize == size, "Incorrect size returned, expected %d got %d, msg_index=%d\n",
2330 size, rsize, msg_index);
2331 if (msg_index == 5)
2332 todo_wine {
2333 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2334 test_cmd_w_to_a, buffer, msg_index);
2335 ok(size == 17, "Expected size should be 17, got %d, msg_index=%d\n", size, msg_index);
2336 }
2337 else if (msg_index == 23)
2338 {
2339 ok(!lstrcmpA((CHAR*)buffer, test_cmd_w_to_a), "Expected %s, got %s, msg_index=%d\n",
2340 test_cmd_w_to_a, buffer, msg_index);
2341 ok(size == 17, "Expected size should be 17, got %d, msg_index=%d\n", size, msg_index);
2342 }
2343 else
2344 {
2345 ok(!lstrcmpA((CHAR*)buffer, test_cmd_a_to_a), "Expected %s, got %s, msg_index=%d\n",
2346 test_cmd_a_to_a, buffer, msg_index);
2347 ok(size == 17, "Expected size should be 17, got %d, msg_index=%d\n", size, msg_index);
2348 }
2349
2350 }
2351
2352 return (HDDEDATA) DDE_FACK;
2353 }
2354 case XTYP_DISCONNECT:
2355 return (HDDEDATA) TRUE;
2356
2357 default:
2358 ok(FALSE, "Unhandled msg: %08x, msg_index=%d\n", uType, msg_index);
2359 }
2360
2361 return NULL;
2362 }
2363
2364 static HDDEDATA CALLBACK client_end_to_end_callback(UINT uType, UINT uFmt, HCONV hconv,
2365 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
2366 ULONG_PTR dwData1, ULONG_PTR dwData2)
2367 {
2368 switch (uType)
2369 {
2370 case XTYP_DISCONNECT:
2371 return (HDDEDATA) TRUE;
2372
2373 default:
2374 ok(FALSE, "Unhandled msg: %08x\n", uType);
2375 }
2376
2377 return NULL;
2378 }
2379
2380 static void test_end_to_end_client(BOOL type_a)
2381 {
2382 DWORD ret, err;
2383 DWORD client_pid = 0;
2384 HSZ server, topic;
2385 HCONV hconv;
2386 HDDEDATA hdata;
2387 static char test_cmd[] = "Test dde command";
2388 static WCHAR test_cmd_w[] = {'t','e','s','t',' ','d','d','e',' ','c','o','m','m','a','n','d',0};
2389 static char test_service[] = "TestDDEService";
2390 static WCHAR test_service_w[] = {'T','e','s','t','D','D','E','S','e','r','v','i','c','e',0};
2391 static char test_topic[] = "TestDDETopic";
2392 static WCHAR test_topic_w[] = {'T','e','s','t','D','D','E','T','o','p','i','c',0};
2393
2394 trace("Start end to end client %s\n", type_a ? "ASCII" : "UNICODE");
2395
2396 if (type_a)
2397 ret = DdeInitializeA(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2398 else
2399 ret = DdeInitializeW(&client_pid, client_end_to_end_callback, APPCMD_CLIENTONLY, 0);
2400 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2401
2402 if (type_a)
2403 {
2404 server = DdeCreateStringHandleA(client_pid, test_service, CP_WINANSI);
2405 topic = DdeCreateStringHandleA(client_pid, test_topic, CP_WINANSI);
2406 }
2407 else {
2408 server = DdeCreateStringHandleW(client_pid, test_service_w, CP_WINUNICODE);
2409 topic = DdeCreateStringHandleW(client_pid, test_topic_w, CP_WINUNICODE);
2410 }
2411
2412 DdeGetLastError(client_pid);
2413 hconv = DdeConnect(client_pid, server, topic, NULL);
2414 ok(hconv != NULL, "Expected non-NULL conversation\n");
2415 ret = DdeGetLastError(client_pid);
2416 ok(ret == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %x\n", ret);
2417 DdeFreeStringHandle(client_pid, server);
2418
2419 /* Test both A and W data being passed to DdeClientTransaction */
2420 hdata = DdeClientTransaction((LPBYTE)test_cmd, strlen(test_cmd) + 1,
2421 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2422 ok(hdata != NULL, "DdeClientTransaction failed\n");
2423 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2424 err = DdeGetLastError(client_pid);
2425 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2426
2427 hdata = DdeClientTransaction((LPBYTE)test_cmd_w, lstrlenW(test_cmd_w) * sizeof(WCHAR) + 2,
2428 hconv, (HSZ)0xdead, 0xbeef, XTYP_EXECUTE, 1000, &ret);
2429 ok(hdata != NULL, "DdeClientTransaction failed\n");
2430 ok(ret == DDE_FACK, "wrong status code %x\n", ret);
2431 err = DdeGetLastError(client_pid);
2432 ok(err == DMLERR_NO_ERROR, "wrong dde error %x\n", err);
2433
2434 DdeFreeStringHandle(client_pid, topic);
2435 ret = DdeDisconnect(hconv);
2436 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2437
2438 ret = DdeUninitialize(client_pid);
2439 ok(ret == TRUE, "Expected TRUE, got %x\n", ret);
2440
2441 }
2442
2443 static void test_end_to_end_server(HANDLE hproc, HANDLE hthread, BOOL type_a)
2444 {
2445 MSG msg;
2446 HSZ server;
2447 BOOL ret;
2448 DWORD res;
2449 HDDEDATA hdata;
2450 static CHAR test_service[] = "TestDDEService";
2451
2452 trace("start end to end server %s\n", type_a ? "ASCII" : "UNICODE");
2453 server_pid = 0;
2454
2455 if (type_a)
2456 res = DdeInitializeA(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2457 else
2458 res = DdeInitializeW(&server_pid, server_end_to_end_callback, APPCLASS_STANDARD, 0);
2459 ok(res == DMLERR_NO_ERROR, "Expected DMLERR_NO_ERROR, got %d\n", res);
2460
2461 server = DdeCreateStringHandleA(server_pid, test_service, CP_WINANSI);
2462 ok(server != NULL, "Expected non-NULL string handle\n");
2463
2464 hdata = DdeNameService(server_pid, server, 0, DNS_REGISTER);
2465 ok(hdata == (HDDEDATA)TRUE, "Expected TRUE, got %p\n", hdata);
2466 ResumeThread( hthread );
2467
2468
2469 while (MsgWaitForMultipleObjects( 1, &hproc, FALSE, INFINITE, QS_ALLINPUT ) != 0)
2470 {
2471 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2472 }
2473
2474 ret = DdeUninitialize(server_pid);
2475 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
2476 GetExitCodeProcess( hproc, &res );
2477 ok( !res, "client failed with %u error(s)\n", res );
2478 }
2479
2480 START_TEST(dde)
2481 {
2482 int argc;
2483 char **argv;
2484 char buffer[MAX_PATH];
2485 STARTUPINFO startup;
2486 PROCESS_INFORMATION proc;
2487
2488 argc = winetest_get_mainargs(&argv);
2489 if (argc == 3)
2490 {
2491 if (!lstrcmpA(argv[2], "ddeml"))
2492 test_ddeml_client();
2493 else if (!lstrcmpA(argv[2], "msg"))
2494 test_msg_client();
2495 else if (!lstrcmpA(argv[2], "enda"))
2496 test_end_to_end_client(TRUE);
2497 else if (!lstrcmpA(argv[2], "endw"))
2498 test_end_to_end_client(FALSE);
2499
2500 return;
2501 }
2502
2503 test_initialisation();
2504
2505 ZeroMemory(&startup, sizeof(STARTUPINFO));
2506 sprintf(buffer, "%s dde ddeml", argv[0]);
2507 startup.cb = sizeof(startup);
2508 startup.dwFlags = STARTF_USESHOWWINDOW;
2509 startup.wShowWindow = SW_SHOWNORMAL;
2510
2511 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2512 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2513
2514 test_msg_server(proc.hProcess, proc.hThread);
2515
2516 sprintf(buffer, "%s dde msg", argv[0]);
2517 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2518 0, NULL, NULL, &startup, &proc);
2519
2520 test_ddeml_server(proc.hProcess);
2521
2522 /* Test the combinations of A and W interfaces with A and W data
2523 end to end to ensure that data conversions are accurate */
2524 sprintf(buffer, "%s dde enda", argv[0]);
2525 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2526 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2527
2528 test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
2529
2530 sprintf(buffer, "%s dde endw", argv[0]);
2531 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2532 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2533
2534 test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
2535
2536 sprintf(buffer, "%s dde enda", argv[0]);
2537 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2538 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2539
2540 test_end_to_end_server(proc.hProcess, proc.hThread, FALSE);
2541
2542 sprintf(buffer, "%s dde endw", argv[0]);
2543 CreateProcessA(NULL, buffer, NULL, NULL, FALSE,
2544 CREATE_SUSPENDED, NULL, NULL, &startup, &proc);
2545
2546 test_end_to_end_server(proc.hProcess, proc.hThread, TRUE);
2547
2548 test_dde_aw_transaction();
2549
2550 test_DdeCreateDataHandle();
2551 test_DdeCreateStringHandle();
2552 test_FreeDDElParam();
2553 test_PackDDElParam();
2554 test_UnpackDDElParam();
2555 }