Change some TRACEing formats to make more sense.
[wine/multimedia.git] / dlls / user / dde_client.c
blob6b74e590955199421d7ed7eea3313bdd47264615
1 /*
2 * DDEML library
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Len White
6 * Copyright 1999 Keith Matthews
7 * Copyright 2000 Corel
8 * Copyright 2001 Eric Pouech
9 * Copyright 2004, 2005 Dmitry Timoshkov
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <stdarg.h>
27 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "winnls.h"
34 #include "dde.h"
35 #include "ddeml.h"
36 #include "win.h"
37 #include "wine/debug.h"
38 #include "dde_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
42 static LRESULT CALLBACK WDML_ClientProc(HWND, UINT, WPARAM, LPARAM); /* only for one client, not conv list */
43 const char WDML_szClientConvClassA[] = "WineDdeClientA";
44 const WCHAR WDML_szClientConvClassW[] = {'W','i','n','e','D','d','e','C','l','i','e','n','t','W',0};
46 /******************************************************************************
47 * DdeConnectList [USER32.@] Establishes conversation with DDE servers
49 * PARAMS
50 * idInst [I] Instance identifier
51 * hszService [I] Handle to service name string
52 * hszTopic [I] Handle to topic name string
53 * hConvList [I] Handle to conversation list
54 * pCC [I] Pointer to structure with context data
56 * RETURNS
57 * Success: Handle to new conversation list
58 * Failure: 0
60 HCONVLIST WINAPI DdeConnectList(DWORD idInst, HSZ hszService, HSZ hszTopic,
61 HCONVLIST hConvList, PCONVCONTEXT pCC)
63 FIXME("(%ld,%p,%p,%p,%p): stub\n", idInst, hszService, hszTopic, hConvList, pCC);
64 return (HCONVLIST)1;
67 /*****************************************************************
68 * DdeQueryNextServer [USER32.@]
70 HCONV WINAPI DdeQueryNextServer(HCONVLIST hConvList, HCONV hConvPrev)
72 FIXME("(%p,%p): stub\n", hConvList, hConvPrev);
73 return 0;
76 /******************************************************************************
77 * DdeDisconnectList [USER32.@] Destroys list and terminates conversations
80 * PARAMS
81 * hConvList [I] Handle to conversation list
83 * RETURNS
84 * Success: TRUE
85 * Failure: FALSE
87 BOOL WINAPI DdeDisconnectList(HCONVLIST hConvList)
89 FIXME("(%p): stub\n", hConvList);
90 return TRUE;
93 /*****************************************************************
94 * DdeConnect (USER32.@)
96 HCONV WINAPI DdeConnect(DWORD idInst, HSZ hszService, HSZ hszTopic,
97 PCONVCONTEXT pCC)
99 HWND hwndClient;
100 WDML_INSTANCE* pInstance;
101 WDML_CONV* pConv = NULL;
102 ATOM aSrv = 0, aTpc = 0;
104 TRACE("(0x%lx,%p,%p,%p)\n", idInst, hszService, hszTopic, pCC);
106 EnterCriticalSection(&WDML_CritSect);
108 pInstance = WDML_GetInstance(idInst);
109 if (!pInstance)
111 goto theEnd;
114 /* make sure this conv is never created */
115 pConv = WDML_FindConv(pInstance, WDML_CLIENT_SIDE, hszService, hszTopic);
116 if (pConv != NULL)
118 ERR("This Conv already exists: (%p)\n", pConv);
119 goto theEnd;
122 /* we need to establish a conversation with
123 server, so create a window for it */
125 if (pInstance->unicode)
127 WNDCLASSEXW wndclass;
129 wndclass.cbSize = sizeof(wndclass);
130 wndclass.style = 0;
131 wndclass.lpfnWndProc = WDML_ClientProc;
132 wndclass.cbClsExtra = 0;
133 wndclass.cbWndExtra = 2 * sizeof(ULONG_PTR);
134 wndclass.hInstance = 0;
135 wndclass.hIcon = 0;
136 wndclass.hCursor = 0;
137 wndclass.hbrBackground = 0;
138 wndclass.lpszMenuName = NULL;
139 wndclass.lpszClassName = WDML_szClientConvClassW;
140 wndclass.hIconSm = 0;
142 RegisterClassExW(&wndclass);
144 hwndClient = CreateWindowW(WDML_szClientConvClassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
146 else
148 WNDCLASSEXA wndclass;
150 wndclass.cbSize = sizeof(wndclass);
151 wndclass.style = 0;
152 wndclass.lpfnWndProc = WDML_ClientProc;
153 wndclass.cbClsExtra = 0;
154 wndclass.cbWndExtra = 2 * sizeof(ULONG_PTR);
155 wndclass.hInstance = 0;
156 wndclass.hIcon = 0;
157 wndclass.hCursor = 0;
158 wndclass.hbrBackground = 0;
159 wndclass.lpszMenuName = NULL;
160 wndclass.lpszClassName = WDML_szClientConvClassA;
161 wndclass.hIconSm = 0;
163 RegisterClassExA(&wndclass);
165 hwndClient = CreateWindowA(WDML_szClientConvClassA, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
168 SetWindowLongPtrW(hwndClient, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
170 if (hszService)
172 aSrv = WDML_MakeAtomFromHsz(hszService);
173 if (!aSrv) goto theEnd;
175 if (hszTopic)
177 aTpc = WDML_MakeAtomFromHsz(hszTopic);
178 if (!aTpc) goto theEnd;
181 LeaveCriticalSection(&WDML_CritSect);
183 /* note: sent messages shall not use packing */
184 SendMessageTimeoutW( HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndClient, MAKELPARAM(aSrv, aTpc),
185 SMTO_ABORTIFHUNG, 2000, NULL );
187 EnterCriticalSection(&WDML_CritSect);
189 pInstance = WDML_GetInstance(idInst);
190 if (!pInstance)
192 goto theEnd;
195 /* At this point, Client WM_DDE_ACK should have saved hwndServer
196 for this instance id and hwndClient if server responds.
197 So get HCONV and return it. And add it to conv list */
198 pConv = WDML_GetConvFromWnd(hwndClient);
199 if (pConv == NULL || pConv->hwndServer == 0)
201 ERR("Done with INITIATE, but no Server window available\n");
202 pConv = NULL;
203 goto theEnd;
205 TRACE("Connected to Server window (%p)\n", pConv->hwndServer);
206 pConv->wConvst = XST_CONNECTED;
208 /* finish init of pConv */
209 if (pCC != NULL)
211 pConv->convContext = *pCC;
213 else
215 memset(&pConv->convContext, 0, sizeof(pConv->convContext));
216 pConv->convContext.cb = sizeof(pConv->convContext);
217 pConv->convContext.iCodePage = (pInstance->unicode) ? CP_WINUNICODE : CP_WINANSI;
220 theEnd:
221 LeaveCriticalSection(&WDML_CritSect);
223 if (aSrv) GlobalDeleteAtom(aSrv);
224 if (aTpc) GlobalDeleteAtom(aTpc);
225 return (HCONV)pConv;
228 /*****************************************************************
229 * DdeReconnect (DDEML.37)
230 * DdeReconnect (USER32.@)
232 HCONV WINAPI DdeReconnect(HCONV hConv)
234 WDML_CONV* pConv;
235 WDML_CONV* pNewConv = NULL;
236 ATOM aSrv = 0, aTpc = 0;
238 TRACE("(%p)\n", hConv);
240 EnterCriticalSection(&WDML_CritSect);
241 pConv = WDML_GetConv(hConv, FALSE);
242 if (pConv != NULL && (pConv->wStatus & ST_CLIENT))
244 BOOL ret;
246 /* to reestablist a connection, we have to make sure that:
247 * 1/ pConv is the converstation attached to the client window (it wouldn't be
248 * if a call to DdeReconnect would have already been done...)
249 * FIXME: is this really an error ???
250 * 2/ the pConv conversation had really been deconnected
252 if (pConv == WDML_GetConvFromWnd(pConv->hwndClient) &&
253 (pConv->wStatus & ST_TERMINATED) && !(pConv->wStatus & ST_CONNECTED))
255 HWND hwndClient = pConv->hwndClient;
256 HWND hwndServer = pConv->hwndServer;
257 ATOM aSrv, aTpc;
259 SetWindowLongPtrW(pConv->hwndClient, GWL_WDML_CONVERSATION, 0);
261 aSrv = WDML_MakeAtomFromHsz(pConv->hszService);
262 aTpc = WDML_MakeAtomFromHsz(pConv->hszTopic);
263 if (!aSrv || !aTpc) goto theEnd;
265 LeaveCriticalSection(&WDML_CritSect);
267 /* note: sent messages shall not use packing */
268 ret = SendMessageW(hwndServer, WM_DDE_INITIATE, (WPARAM)hwndClient,
269 MAKELPARAM(aSrv, aTpc));
271 EnterCriticalSection(&WDML_CritSect);
273 pConv = WDML_GetConv(hConv, FALSE);
274 if (pConv == NULL)
276 FIXME("Should fail reconnection\n");
277 goto theEnd;
280 if (ret && (pNewConv = WDML_GetConvFromWnd(pConv->hwndClient)) != NULL)
282 /* re-establish all links... */
283 WDML_LINK* pLink;
285 for (pLink = pConv->instance->links[WDML_CLIENT_SIDE]; pLink; pLink = pLink->next)
287 if (pLink->hConv == hConv)
289 /* try to reestablish the links... */
290 DdeClientTransaction(NULL, 0, (HCONV)pNewConv, pLink->hszItem, pLink->uFmt,
291 pLink->transactionType, 1000, NULL);
295 else
297 /* reset the conversation as it was */
298 SetWindowLongPtrW(pConv->hwndClient, GWL_WDML_CONVERSATION, (ULONG_PTR)pConv);
303 theEnd:
304 LeaveCriticalSection(&WDML_CritSect);
306 if (aSrv) GlobalDeleteAtom(aSrv);
307 if (aTpc) GlobalDeleteAtom(aTpc);
308 return (HCONV)pNewConv;
311 /******************************************************************
312 * WDML_ClientQueueAdvise
314 * Creates and queue an WM_DDE_ADVISE transaction
316 static WDML_XACT* WDML_ClientQueueAdvise(WDML_CONV* pConv, UINT wType, UINT wFmt, HSZ hszItem)
318 DDEADVISE* pDdeAdvise;
319 WDML_XACT* pXAct;
320 ATOM atom;
322 TRACE("XTYP_ADVSTART (with%s data) transaction\n", (wType & XTYPF_NODATA) ? "out" : "");
324 atom = WDML_MakeAtomFromHsz(hszItem);
325 if (!atom) return NULL;
327 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_ADVISE, wFmt, hszItem);
328 if (!pXAct)
330 GlobalDeleteAtom(atom);
331 return NULL;
334 pXAct->wType = wType & ~0x0F;
335 pXAct->hMem = GlobalAlloc(GHND | GMEM_DDESHARE, sizeof(DDEADVISE));
336 /* FIXME: hMem is unfreed for now... should be deleted in server */
338 /* pack DdeAdvise */
339 pDdeAdvise = (DDEADVISE*)GlobalLock(pXAct->hMem);
340 pDdeAdvise->fAckReq = (wType & XTYPF_ACKREQ) ? TRUE : FALSE;
341 pDdeAdvise->fDeferUpd = (wType & XTYPF_NODATA) ? TRUE : FALSE;
342 pDdeAdvise->cfFormat = wFmt;
343 GlobalUnlock(pXAct->hMem);
345 pXAct->lParam = PackDDElParam(WM_DDE_ADVISE, (UINT_PTR)pXAct->hMem, atom);
347 return pXAct;
350 /******************************************************************
351 * WDML_HandleAdviseReply
353 * handles the reply to an advise request
355 static WDML_QUEUE_STATE WDML_HandleAdviseReply(WDML_CONV* pConv, MSG* msg, WDML_XACT* pXAct, DWORD *ack)
357 DDEACK ddeAck;
358 UINT_PTR uiLo, uiHi;
359 HSZ hsz;
361 if (msg->message != WM_DDE_ACK || WIN_GetFullHandle((HWND)msg->wParam) != pConv->hwndServer)
363 return WDML_QS_PASS;
366 UnpackDDElParam(WM_DDE_ACK, msg->lParam, &uiLo, &uiHi);
367 hsz = WDML_MakeHszFromAtom(pConv->instance, uiHi);
369 if (DdeCmpStringHandles(hsz, pXAct->hszItem) != 0)
370 return WDML_QS_PASS;
372 GlobalDeleteAtom(uiHi);
373 FreeDDElParam(WM_DDE_ACK, msg->lParam);
375 if (ack) *ack = uiLo;
376 WDML_ExtractAck(uiLo, &ddeAck);
378 if (ddeAck.fAck)
380 WDML_LINK* pLink;
382 /* billx: first to see if the link is already created. */
383 pLink = WDML_FindLink(pConv->instance, (HCONV)pConv, WDML_CLIENT_SIDE,
384 pXAct->hszItem, TRUE, pXAct->wFmt);
385 if (pLink != NULL)
387 /* we found a link, and only need to modify it in case it changes */
388 pLink->transactionType = pXAct->wType;
390 else
392 WDML_AddLink(pConv->instance, (HCONV)pConv, WDML_CLIENT_SIDE,
393 pXAct->wType, pXAct->hszItem, pXAct->wFmt);
395 pXAct->hDdeData = (HDDEDATA)1;
397 else
399 TRACE("Returning FALSE on XTYP_ADVSTART - fAck was FALSE\n");
400 GlobalFree(pXAct->hMem);
401 pXAct->hDdeData = NULL;
404 return WDML_QS_HANDLED;
407 /******************************************************************
408 * WDML_ClientQueueUnadvise
410 * queues an unadvise transaction
412 static WDML_XACT* WDML_ClientQueueUnadvise(WDML_CONV* pConv, UINT wFmt, HSZ hszItem)
414 WDML_XACT* pXAct;
415 ATOM atom;
417 TRACE("XTYP_ADVSTOP transaction\n");
419 atom = WDML_MakeAtomFromHsz(hszItem);
420 if (!atom) return NULL;
422 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_UNADVISE, wFmt, hszItem);
423 if (!pXAct)
425 GlobalDeleteAtom(atom);
426 return NULL;
429 /* end advise loop: post WM_DDE_UNADVISE to server to terminate link
430 * on the specified item.
432 pXAct->lParam = PackDDElParam(WM_DDE_UNADVISE, wFmt, atom);
433 return pXAct;
436 /******************************************************************
437 * WDML_HandleUnadviseReply
441 static WDML_QUEUE_STATE WDML_HandleUnadviseReply(WDML_CONV* pConv, MSG* msg, WDML_XACT* pXAct, DWORD *ack)
443 DDEACK ddeAck;
444 UINT_PTR uiLo, uiHi;
445 HSZ hsz;
447 if (msg->message != WM_DDE_ACK || WIN_GetFullHandle((HWND)msg->wParam) != pConv->hwndServer)
449 return WDML_QS_PASS;
452 UnpackDDElParam(WM_DDE_ACK, msg->lParam, &uiLo, &uiHi);
453 hsz = WDML_MakeHszFromAtom(pConv->instance, uiHi);
455 if (DdeCmpStringHandles(hsz, pXAct->hszItem) != 0)
456 return WDML_QS_PASS;
458 FreeDDElParam(WM_DDE_ACK, msg->lParam);
459 GlobalDeleteAtom(uiHi);
461 if (ack) *ack = uiLo;
462 WDML_ExtractAck(uiLo, &ddeAck);
464 TRACE("WM_DDE_ACK received while waiting for a timeout\n");
466 if (!ddeAck.fAck)
468 TRACE("Returning FALSE on XTYP_ADVSTOP - fAck was FALSE\n");
469 pXAct->hDdeData = NULL;
471 else
473 /* billx: remove the link */
474 WDML_RemoveLink(pConv->instance, (HCONV)pConv, WDML_CLIENT_SIDE,
475 pXAct->hszItem, pXAct->wFmt);
476 pXAct->hDdeData = (HDDEDATA)1;
478 return WDML_QS_HANDLED;
481 /******************************************************************
482 * WDML_ClientQueueRequest
486 static WDML_XACT* WDML_ClientQueueRequest(WDML_CONV* pConv, UINT wFmt, HSZ hszItem)
488 WDML_XACT* pXAct;
489 ATOM atom;
491 TRACE("XTYP_REQUEST transaction\n");
493 atom = WDML_MakeAtomFromHsz(hszItem);
494 if (!atom) return NULL;
496 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_REQUEST, wFmt, hszItem);
497 if (!pXAct)
499 GlobalDeleteAtom(atom);
500 return NULL;
503 pXAct->lParam = PackDDElParam(WM_DDE_REQUEST, wFmt, atom);
505 return pXAct;
508 /******************************************************************
509 * WDML_HandleRequestReply
513 static WDML_QUEUE_STATE WDML_HandleRequestReply(WDML_CONV* pConv, MSG* msg, WDML_XACT* pXAct, DWORD *ack)
515 DDEACK ddeAck;
516 WINE_DDEHEAD wdh;
517 UINT_PTR uiLo, uiHi;
518 HSZ hsz;
520 if (WIN_GetFullHandle((HWND)msg->wParam) != pConv->hwndServer)
521 return WDML_QS_PASS;
523 switch (msg->message)
525 case WM_DDE_ACK:
526 UnpackDDElParam(WM_DDE_ACK, msg->lParam, &uiLo, &uiHi);
527 FreeDDElParam(WM_DDE_ACK, msg->lParam);
528 GlobalDeleteAtom(uiHi);
529 if (ack) *ack = uiLo;
530 WDML_ExtractAck(uiLo, &ddeAck);
531 pXAct->hDdeData = 0;
532 if (ddeAck.fAck)
533 ERR("Positive answer should appear in NACK for a request, assuming negative\n");
534 TRACE("Negative answer...\n");
535 break;
537 case WM_DDE_DATA:
538 UnpackDDElParam(WM_DDE_DATA, msg->lParam, &uiLo, &uiHi);
539 TRACE("Got the result (%08x)\n", uiLo);
541 hsz = WDML_MakeHszFromAtom(pConv->instance, uiHi);
543 if (DdeCmpStringHandles(hsz, pXAct->hszItem) != 0)
544 return WDML_QS_PASS;
546 pXAct->hDdeData = WDML_Global2DataHandle((HGLOBAL)uiLo, &wdh);
547 if (wdh.fRelease)
549 GlobalFree((HGLOBAL)uiLo);
551 if (wdh.fAckReq)
553 WDML_PostAck(pConv, WDML_CLIENT_SIDE, 0, FALSE, TRUE, uiHi, msg->lParam, WM_DDE_DATA);
555 else
557 GlobalDeleteAtom(uiHi);
558 FreeDDElParam(WM_DDE_ACK, msg->lParam);
560 break;
562 default:
563 FreeDDElParam(msg->message, msg->lParam);
564 return WDML_QS_PASS;
567 return WDML_QS_HANDLED;
570 /******************************************************************
571 * WDML_BuildExecuteCommand
573 * Creates a DDE block suitable for sending in WM_DDE_COMMAND
574 * It also takes care of string conversion between the two window procedures
576 static HGLOBAL WDML_BuildExecuteCommand(WDML_CONV* pConv, LPCVOID pData, DWORD cbData)
578 HGLOBAL hMem;
579 BOOL clientUnicode, serverUnicode;
580 DWORD memSize;
582 clientUnicode = pConv->instance->unicode;
583 TRACE("client %p uses unicode = %d\n", pConv->hwndClient, clientUnicode);
584 /* FIXME: how exactly Windows determines what to use for the server side? */
585 serverUnicode = IsWindowUnicode(pConv->hwndServer) && IsWindowUnicode(pConv->hwndClient);
586 TRACE("server %p uses unicode = %d\n", pConv->hwndServer, serverUnicode);
588 if (clientUnicode == serverUnicode)
590 memSize = cbData;
592 else
594 if (clientUnicode)
596 memSize = WideCharToMultiByte( CP_ACP, 0, pData, cbData, NULL, 0, NULL, NULL);
598 else
600 memSize = MultiByteToWideChar( CP_ACP, 0, pData, cbData, NULL, 0) * sizeof(WCHAR);
604 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, memSize);
606 if (hMem)
608 LPSTR pDst;
610 pDst = GlobalLock(hMem);
611 if (pDst)
613 if (clientUnicode == serverUnicode)
615 memcpy(pDst, pData, cbData);
617 else
619 if (clientUnicode)
621 WideCharToMultiByte( CP_ACP, 0, pData, cbData, pDst, memSize, NULL, NULL);
623 else
625 MultiByteToWideChar( CP_ACP, 0, pData, cbData, (LPWSTR)pDst, memSize/sizeof(WCHAR));
629 GlobalUnlock(hMem);
631 else
633 GlobalFree(hMem);
634 hMem = 0;
637 return hMem;
640 /******************************************************************
641 * WDML_ClientQueueExecute
645 static WDML_XACT* WDML_ClientQueueExecute(WDML_CONV* pConv, LPCVOID pData, DWORD cbData)
647 WDML_XACT* pXAct;
649 TRACE("XTYP_EXECUTE transaction\n");
651 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_EXECUTE, 0, 0);
652 if (!pXAct)
653 return NULL;
655 if (cbData == (DWORD)-1)
657 HDDEDATA hDdeData = (HDDEDATA)pData;
659 pData = DdeAccessData(hDdeData, &cbData);
660 if (pData)
662 pXAct->hMem = WDML_BuildExecuteCommand(pConv, pData, cbData);
663 DdeUnaccessData(hDdeData);
666 else
668 pXAct->hMem = WDML_BuildExecuteCommand(pConv, pData, cbData);
671 pXAct->lParam = (LPARAM)pXAct->hMem;
673 return pXAct;
676 /******************************************************************
677 * WDML_HandleExecuteReply
681 static WDML_QUEUE_STATE WDML_HandleExecuteReply(WDML_CONV* pConv, MSG* msg, WDML_XACT* pXAct, DWORD *ack)
683 DDEACK ddeAck;
684 UINT_PTR uiLo, uiHi;
686 if (msg->message != WM_DDE_ACK || WIN_GetFullHandle((HWND)msg->wParam) != pConv->hwndServer)
688 return WDML_QS_PASS;
691 UnpackDDElParam(WM_DDE_ACK, msg->lParam, &uiLo, &uiHi);
692 FreeDDElParam(WM_DDE_ACK, msg->lParam);
694 if ((HANDLE)uiHi != pXAct->hMem)
696 return WDML_QS_PASS;
699 if (ack) *ack = uiLo;
700 WDML_ExtractAck(uiLo, &ddeAck);
701 pXAct->hDdeData = (HDDEDATA)(UINT_PTR)ddeAck.fAck;
703 TRACE("hDdeData = %p\n", pXAct->hDdeData);
704 pConv->instance->lastError = (pXAct->hDdeData != 0) ? DMLERR_NO_ERROR : DMLERR_NOTPROCESSED;
706 return WDML_QS_HANDLED;
709 /******************************************************************
710 * WDML_ClientQueuePoke
714 static WDML_XACT* WDML_ClientQueuePoke(WDML_CONV* pConv, LPCVOID pData, DWORD cbData,
715 UINT wFmt, HSZ hszItem)
717 WDML_XACT* pXAct;
718 ATOM atom;
720 TRACE("XTYP_POKE transaction\n");
722 atom = WDML_MakeAtomFromHsz(hszItem);
723 if (!atom) return NULL;
725 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_POKE, wFmt, hszItem);
726 if (!pXAct)
728 GlobalDeleteAtom(atom);
729 return NULL;
732 if (cbData == (DWORD)-1)
734 pXAct->hMem = (HDDEDATA)pData;
736 else
738 DDEPOKE* ddePoke;
740 pXAct->hMem = GlobalAlloc(GHND | GMEM_DDESHARE, sizeof(DDEPOKE) + cbData);
741 ddePoke = GlobalLock(pXAct->hMem);
742 if (ddePoke)
744 memcpy(ddePoke->Value, pData, cbData);
745 ddePoke->fRelease = FALSE; /* FIXME: app owned ? */
746 ddePoke->cfFormat = wFmt;
747 GlobalUnlock(pXAct->hMem);
751 pXAct->lParam = PackDDElParam(WM_DDE_POKE, (UINT_PTR)pXAct->hMem, atom);
753 return pXAct;
756 /******************************************************************
757 * WDML_HandlePokeReply
761 static WDML_QUEUE_STATE WDML_HandlePokeReply(WDML_CONV* pConv, MSG* msg, WDML_XACT* pXAct, DWORD *ack)
763 UINT_PTR uiLo, uiHi;
764 HSZ hsz;
766 if (msg->message != WM_DDE_ACK && WIN_GetFullHandle((HWND)msg->wParam) != pConv->hwndServer)
768 return WDML_QS_PASS;
771 UnpackDDElParam(WM_DDE_ACK, msg->lParam, &uiLo, &uiHi);
772 hsz = WDML_MakeHszFromAtom(pConv->instance, uiHi);
773 if (DdeCmpStringHandles(hsz, pXAct->hszItem) != 0)
775 return WDML_QS_PASS;
777 FreeDDElParam(WM_DDE_ACK, msg->lParam);
778 GlobalDeleteAtom(uiHi);
780 if (ack) *ack = uiLo;
781 GlobalFree(pXAct->hMem);
783 pXAct->hDdeData = (HDDEDATA)TRUE;
784 return TRUE;
787 /******************************************************************
788 * WDML_ClientQueueTerminate
790 * Creates and queue an WM_DDE_TERMINATE transaction
792 static WDML_XACT* WDML_ClientQueueTerminate(WDML_CONV* pConv)
794 WDML_XACT* pXAct;
796 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_TERMINATE, 0, 0);
797 if (!pXAct)
798 return NULL;
800 pXAct->lParam = 0;
801 pConv->wStatus &= ~ST_CONNECTED;
803 return pXAct;
806 /******************************************************************
807 * WDML_HandleTerminateReply
809 * handles the reply to a terminate request
811 static WDML_QUEUE_STATE WDML_HandleTerminateReply(WDML_CONV* pConv, MSG* msg, WDML_XACT* pXAct)
813 if (msg->message != WM_DDE_TERMINATE)
815 /* FIXME: should delete data passed here */
816 return WDML_QS_SWALLOWED;
819 if (WIN_GetFullHandle((HWND)msg->wParam) != pConv->hwndServer)
821 FIXME("hmmm shouldn't happen\n");
822 return WDML_QS_PASS;
824 if (!pConv->instance->CBFflags & CBF_SKIP_DISCONNECTS)
826 WDML_InvokeCallback(pConv->instance, XTYP_DISCONNECT, 0, (HCONV)pConv,
827 0, 0, 0, 0, (pConv->wStatus & ST_ISSELF) ? 1 : 0);
829 WDML_RemoveConv(pConv, WDML_CLIENT_SIDE);
830 return WDML_QS_HANDLED;
833 /******************************************************************
834 * WDML_HandleReplyData
838 static WDML_QUEUE_STATE WDML_HandleIncomingData(WDML_CONV* pConv, MSG* msg, HDDEDATA* hdd)
840 UINT_PTR uiLo, uiHi;
841 HDDEDATA hDdeDataIn, hDdeDataOut;
842 WDML_LINK* pLink;
843 WINE_DDEHEAD wdh;
844 HSZ hsz;
846 TRACE("WM_DDE_DATA message received in the Client Proc!\n");
847 /* wParam -- sending window handle */
848 /* lParam -- hDdeData & item HSZ */
850 UnpackDDElParam(WM_DDE_DATA, msg->lParam, &uiLo, &uiHi);
851 hsz = WDML_MakeHszFromAtom(pConv->instance, uiHi);
853 hDdeDataIn = WDML_Global2DataHandle((HGLOBAL)uiLo, &wdh);
855 /* billx:
856 * For hot link, data should be passed to its callback with
857 * XTYP_ADVDATA and callback should return the proper status.
859 pLink = WDML_FindLink(pConv->instance, (HCONV)pConv, WDML_CLIENT_SIDE, hsz,
860 uiLo ? TRUE : FALSE, wdh.cfFormat);
861 if (!pLink)
863 WDML_DecHSZ(pConv->instance, hsz);
864 DdeFreeDataHandle(hDdeDataIn);
865 return WDML_QS_PASS;
868 if (hDdeDataIn != 0 && wdh.fAckReq)
870 WDML_PostAck(pConv, WDML_CLIENT_SIDE, 0, FALSE, TRUE, uiHi, msg->lParam, WM_DDE_DATA);
871 if (msg->lParam)
872 msg->lParam = 0;
874 else
876 GlobalDeleteAtom(uiHi);
879 hDdeDataOut = WDML_InvokeCallback(pConv->instance, XTYP_ADVDATA, pLink->uFmt, pLink->hConv,
880 pConv->hszTopic, pLink->hszItem, hDdeDataIn, 0, 0);
882 if (hDdeDataOut != (HDDEDATA)DDE_FACK || wdh.fRelease)
884 if (uiLo) GlobalFree((HANDLE)uiLo);
887 DdeFreeDataHandle(hDdeDataIn);
889 WDML_DecHSZ(pConv->instance, hsz);
890 if (msg->lParam)
891 FreeDDElParam(WM_DDE_DATA, msg->lParam);
893 return WDML_QS_HANDLED;
896 /******************************************************************
897 * WDML_HandleIncomingTerminate
901 static WDML_QUEUE_STATE WDML_HandleIncomingTerminate(WDML_CONV* pConv, MSG* msg, HDDEDATA* hdd)
903 if (pConv->hwndServer != WIN_GetFullHandle((HWND)msg->wParam))
904 return WDML_QS_PASS;
906 pConv->wStatus |= ST_TERMINATED;
907 if (!pConv->instance->CBFflags & CBF_SKIP_DISCONNECTS)
909 WDML_InvokeCallback(pConv->instance, XTYP_DISCONNECT, 0, (HCONV)pConv,
910 0, 0, 0, 0, (pConv->wStatus & ST_ISSELF) ? 1 : 0);
912 if (pConv->wStatus & ST_CONNECTED)
914 /* don't care about result code (if server exists or not) */
915 PostMessageW(pConv->hwndServer, WM_DDE_TERMINATE, (WPARAM)pConv->hwndClient, 0L);
916 pConv->wStatus &= ~ST_CONNECTED;
918 /* have to keep connection around to allow reconnection */
919 return WDML_QS_HANDLED;
922 /******************************************************************
923 * WDML_HandleReply
925 * handles any incoming reply, and try to match to an already sent request
927 static WDML_QUEUE_STATE WDML_HandleReply(WDML_CONV* pConv, MSG* msg, HDDEDATA* hdd, DWORD *ack)
929 WDML_XACT* pXAct = pConv->transactions;
930 WDML_QUEUE_STATE qs;
932 if (pConv->transactions)
934 /* first check message against a pending transaction, if any */
935 switch (pXAct->ddeMsg)
937 case WM_DDE_ADVISE:
938 qs = WDML_HandleAdviseReply(pConv, msg, pXAct, ack);
939 break;
940 case WM_DDE_UNADVISE:
941 qs = WDML_HandleUnadviseReply(pConv, msg, pXAct, ack);
942 break;
943 case WM_DDE_EXECUTE:
944 qs = WDML_HandleExecuteReply(pConv, msg, pXAct, ack);
945 break;
946 case WM_DDE_REQUEST:
947 qs = WDML_HandleRequestReply(pConv, msg, pXAct, ack);
948 break;
949 case WM_DDE_POKE:
950 qs = WDML_HandlePokeReply(pConv, msg, pXAct, ack);
951 break;
952 case WM_DDE_TERMINATE:
953 qs = WDML_HandleTerminateReply(pConv, msg, pXAct);
954 break;
955 default:
956 qs = WDML_QS_ERROR;
957 FIXME("oooch\n");
960 else
962 qs = WDML_QS_PASS;
965 /* now check the results */
966 switch (qs)
968 case WDML_QS_ERROR:
969 case WDML_QS_SWALLOWED:
970 *hdd = 0;
971 break;
972 case WDML_QS_HANDLED:
973 /* ok, we have resolved a pending transaction
974 * notify callback if asynchronous, and remove it in any case
976 WDML_UnQueueTransaction(pConv, pXAct);
977 if (pXAct->dwTimeout == TIMEOUT_ASYNC && pXAct->ddeMsg != WM_DDE_TERMINATE)
979 WDML_InvokeCallback(pConv->instance, XTYP_XACT_COMPLETE, pXAct->wFmt,
980 (HCONV)pConv, pConv->hszTopic, pXAct->hszItem,
981 pXAct->hDdeData, MAKELONG(0, pXAct->xActID), 0 /* FIXME */);
982 qs = WDML_QS_PASS;
984 else
986 *hdd = pXAct->hDdeData;
988 WDML_FreeTransaction(pConv->instance, pXAct, TRUE);
989 break;
990 case WDML_QS_PASS:
991 /* no pending transaction found, try a warm/hot link or a termination request */
992 switch (msg->message)
994 case WM_DDE_DATA:
995 qs = WDML_HandleIncomingData(pConv, msg, hdd);
996 break;
997 case WM_DDE_TERMINATE:
998 qs = WDML_HandleIncomingTerminate(pConv, msg, hdd);
999 break;
1001 break;
1002 case WDML_QS_BLOCK:
1003 FIXME("shouldn't be used on client side\n");
1004 break;
1007 return qs;
1010 /******************************************************************
1011 * WDML_SyncWaitTransactionReply
1013 * waits until an answer for a sent request is received
1014 * time out is also handled. only used for synchronous transactions
1016 static HDDEDATA WDML_SyncWaitTransactionReply(HCONV hConv, DWORD dwTimeout, WDML_XACT* pXAct, DWORD *ack)
1018 DWORD dwTime;
1019 DWORD err;
1020 WDML_CONV* pConv;
1022 TRACE("Starting wait for a timeout of %ld ms\n", dwTimeout);
1024 /* FIXME: time 32 bit wrap around */
1025 dwTimeout += GetCurrentTime();
1027 while ((dwTime = GetCurrentTime()) < dwTimeout)
1029 /* we cannot be in the crit sect all the time because when client and server run in a
1030 * single process they need to share the access to the internal data
1032 if (MsgWaitForMultipleObjects(0, NULL, FALSE,
1033 dwTimeout - dwTime, QS_POSTMESSAGE) == WAIT_OBJECT_0)
1035 MSG msg;
1037 while (PeekMessageW(&msg, 0, WM_DDE_FIRST, WM_DDE_LAST, PM_REMOVE))
1039 WDML_CONV *pConv;
1040 HDDEDATA hdd;
1042 EnterCriticalSection(&WDML_CritSect);
1044 pConv = WDML_GetConv(hConv, FALSE);
1045 if (pConv == NULL)
1047 LeaveCriticalSection(&WDML_CritSect);
1048 /* conversation no longer available... return failure */
1049 return 0;
1051 if (msg.hwnd == pConv->hwndClient)
1053 /* check that either pXAct has been processed or no more xActions are pending */
1054 BOOL ret = (pConv->transactions == pXAct);
1055 if (WDML_HandleReply(pConv, &msg, &hdd, ack) == WDML_QS_HANDLED)
1057 TRACE("WDML_HandleReply returned WDML_QS_HANDLED\n");
1058 ret = TRUE;
1060 else
1061 ret = (pConv->transactions == NULL || ret);
1063 if (ret)
1065 pConv->instance->lastError = hdd ? DMLERR_NO_ERROR : DMLERR_NOTPROCESSED;
1066 LeaveCriticalSection(&WDML_CritSect);
1067 return hdd;
1070 else
1072 LeaveCriticalSection(&WDML_CritSect);
1073 DispatchMessageW(&msg);
1079 TRACE("Timeout !!\n");
1081 EnterCriticalSection(&WDML_CritSect);
1083 pConv = WDML_GetConv(hConv, FALSE);
1084 if (pConv != NULL)
1086 if (pConv->transactions)
1088 switch (pConv->transactions->ddeMsg)
1090 case WM_DDE_ADVISE: err = DMLERR_ADVACKTIMEOUT; break;
1091 case WM_DDE_REQUEST: err = DMLERR_DATAACKTIMEOUT; break;
1092 case WM_DDE_EXECUTE: err = DMLERR_EXECACKTIMEOUT; break;
1093 case WM_DDE_POKE: err = DMLERR_POKEACKTIMEOUT; break;
1094 case WM_DDE_UNADVISE: err = DMLERR_UNADVACKTIMEOUT; break;
1095 default: err = DMLERR_INVALIDPARAMETER; break;
1098 pConv->instance->lastError = err;
1101 LeaveCriticalSection(&WDML_CritSect);
1103 return 0;
1106 /*****************************************************************
1107 * DdeClientTransaction (USER32.@)
1109 HDDEDATA WINAPI DdeClientTransaction(LPBYTE pData, DWORD cbData, HCONV hConv, HSZ hszItem, UINT wFmt,
1110 UINT wType, DWORD dwTimeout, LPDWORD pdwResult)
1112 WDML_CONV* pConv;
1113 WDML_XACT* pXAct;
1114 HDDEDATA hDdeData = 0;
1116 TRACE("(%p,%ld,%p,%p,%x,%x,%ld,%p)\n",
1117 pData, cbData, hConv, hszItem, wFmt, wType, dwTimeout, pdwResult);
1119 if (hConv == 0)
1121 ERR("Invalid conversation handle\n");
1122 return 0;
1125 EnterCriticalSection(&WDML_CritSect);
1127 pConv = WDML_GetConv(hConv, TRUE);
1128 if (pConv == NULL)
1130 /* cannot set error... cannot get back to DDE instance */
1131 goto theError;
1134 switch (wType)
1136 case XTYP_EXECUTE:
1137 /* Windows simply ignores hszItem and wFmt in this case */
1138 pXAct = WDML_ClientQueueExecute(pConv, pData, cbData);
1139 break;
1140 case XTYP_POKE:
1141 pXAct = WDML_ClientQueuePoke(pConv, pData, cbData, wFmt, hszItem);
1142 break;
1143 case XTYP_ADVSTART|XTYPF_NODATA:
1144 case XTYP_ADVSTART|XTYPF_NODATA|XTYPF_ACKREQ:
1145 case XTYP_ADVSTART:
1146 case XTYP_ADVSTART|XTYPF_ACKREQ:
1147 if (pData)
1149 pConv->instance->lastError = DMLERR_INVALIDPARAMETER;
1150 goto theError;
1152 pXAct = WDML_ClientQueueAdvise(pConv, wType, wFmt, hszItem);
1153 break;
1154 case XTYP_ADVSTOP:
1155 if (pData)
1157 pConv->instance->lastError = DMLERR_INVALIDPARAMETER;
1158 goto theError;
1160 pXAct = WDML_ClientQueueUnadvise(pConv, wFmt, hszItem);
1161 break;
1162 case XTYP_REQUEST:
1163 if (pData)
1165 pConv->instance->lastError = DMLERR_INVALIDPARAMETER;
1166 goto theError;
1168 pXAct = WDML_ClientQueueRequest(pConv, wFmt, hszItem);
1169 break;
1170 default:
1171 FIXME("Unknown transation\n");
1172 /* unknown transaction type */
1173 pConv->instance->lastError = DMLERR_INVALIDPARAMETER;
1174 goto theError;
1177 if (pXAct == NULL)
1179 pConv->instance->lastError = DMLERR_MEMORY_ERROR;
1180 goto theError;
1183 WDML_QueueTransaction(pConv, pXAct);
1185 if (!PostMessageW(pConv->hwndServer, pXAct->ddeMsg, (WPARAM)pConv->hwndClient, pXAct->lParam))
1187 WARN("Failed posting message %x to %p (error=0x%lx)\n",
1188 pXAct->ddeMsg, pConv->hwndServer, GetLastError());
1189 pConv->wStatus &= ~ST_CONNECTED;
1190 WDML_UnQueueTransaction(pConv, pXAct);
1191 WDML_FreeTransaction(pConv->instance, pXAct, TRUE);
1192 goto theError;
1194 pXAct->dwTimeout = dwTimeout;
1195 /* FIXME: should set the app bits on *pdwResult */
1197 if (dwTimeout == TIMEOUT_ASYNC)
1199 if (pdwResult)
1201 *pdwResult = MAKELONG(0, pXAct->xActID);
1203 hDdeData = (HDDEDATA)1;
1205 else
1207 DWORD count, i;
1209 count = WDML_CritSect.RecursionCount;
1210 for (i = 0; i < count; i++)
1211 LeaveCriticalSection(&WDML_CritSect);
1212 hDdeData = WDML_SyncWaitTransactionReply((HCONV)pConv, dwTimeout, pXAct, pdwResult);
1213 for (i = 0; i < count; i++)
1214 EnterCriticalSection(&WDML_CritSect);
1216 LeaveCriticalSection(&WDML_CritSect);
1218 return hDdeData;
1219 theError:
1220 LeaveCriticalSection(&WDML_CritSect);
1221 return 0;
1224 /*****************************************************************
1225 * DdeAbandonTransaction (USER32.@)
1227 BOOL WINAPI DdeAbandonTransaction(DWORD idInst, HCONV hConv, DWORD idTransaction)
1229 WDML_INSTANCE* pInstance;
1230 WDML_CONV* pConv;
1231 WDML_XACT* pXAct;
1233 TRACE("(%08lx,%p,%08lx);\n", idInst, hConv, idTransaction);
1235 EnterCriticalSection(&WDML_CritSect);
1236 if ((pInstance = WDML_GetInstance(idInst)))
1238 if (hConv)
1240 if ((pConv = WDML_GetConv(hConv, TRUE)) && pConv->instance == pInstance)
1242 for (pXAct = pConv->transactions; pXAct; pXAct = pXAct->next)
1244 if (pXAct->dwTimeout == TIMEOUT_ASYNC &&
1245 (idTransaction == 0 || pXAct->xActID == idTransaction))
1247 WDML_UnQueueTransaction(pConv, pXAct);
1248 WDML_FreeTransaction(pInstance, pXAct, TRUE);
1253 else
1255 for (pConv = pInstance->convs[WDML_CLIENT_SIDE]; pConv; pConv = pConv->next)
1257 if (!(pConv->wStatus & ST_CONNECTED)) continue;
1258 for (pXAct = pConv->transactions; pXAct; pXAct = pXAct->next)
1260 if (pXAct->dwTimeout == TIMEOUT_ASYNC)
1262 WDML_UnQueueTransaction(pConv, pXAct);
1263 WDML_FreeTransaction(pInstance, pXAct, TRUE);
1269 LeaveCriticalSection(&WDML_CritSect);
1271 return TRUE;
1274 /******************************************************************
1275 * WDML_ClientProc
1277 * Window Proc created on client side for each conversation
1279 static LRESULT CALLBACK WDML_ClientProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
1281 UINT uiLo, uiHi;
1282 WDML_CONV* pConv = NULL;
1283 HSZ hszSrv, hszTpc;
1285 TRACE("%p %04x %08x %08lx\n", hwnd, iMsg, wParam , lParam);
1287 if (iMsg == WM_DDE_ACK &&
1288 /* in the initial WM_INITIATE sendmessage */
1289 ((pConv = WDML_GetConvFromWnd(hwnd)) == NULL || pConv->wStatus == XST_INIT1))
1291 /* In response to WM_DDE_INITIATE, save server window */
1292 char buf[256];
1293 WDML_INSTANCE* pInstance;
1295 /* note: sent messages do not need packing */
1296 uiLo = LOWORD(lParam);
1297 uiHi = HIWORD(lParam);
1299 /* FIXME: convlist should be handled here */
1300 if (pConv)
1302 /* we already have started the conv with a server, drop other replies */
1303 GlobalDeleteAtom(uiLo);
1304 GlobalDeleteAtom(uiHi);
1305 PostMessageW((HWND)wParam, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
1306 return 0;
1309 pInstance = WDML_GetInstanceFromWnd(hwnd);
1311 hszSrv = WDML_MakeHszFromAtom(pInstance, uiLo);
1312 hszTpc = WDML_MakeHszFromAtom(pInstance, uiHi);
1314 pConv = WDML_AddConv(pInstance, WDML_CLIENT_SIDE, hszSrv, hszTpc, hwnd, (HWND)wParam);
1316 SetWindowLongPtrW(hwnd, GWL_WDML_CONVERSATION, (ULONG_PTR)pConv);
1317 pConv->wStatus |= ST_CONNECTED;
1318 pConv->wConvst = XST_INIT1;
1320 /* check if server is handled by DDEML */
1321 if ((GetClassNameA((HWND)wParam, buf, sizeof(buf)) &&
1322 lstrcmpiA(buf, WDML_szServerConvClassA) == 0) ||
1323 (GetClassNameW((HWND)wParam, (LPWSTR)buf, sizeof(buf)/sizeof(WCHAR)) &&
1324 lstrcmpiW((LPWSTR)buf, WDML_szServerConvClassW) == 0))
1326 pConv->wStatus |= ST_ISLOCAL;
1329 WDML_BroadcastDDEWindows(WDML_szEventClass, WM_WDML_CONNECT_CONFIRM, (WPARAM)hwnd, wParam);
1331 GlobalDeleteAtom(uiLo);
1332 GlobalDeleteAtom(uiHi);
1334 /* accept conversation */
1335 return 1;
1338 if (iMsg >= WM_DDE_FIRST && iMsg <= WM_DDE_LAST)
1340 EnterCriticalSection(&WDML_CritSect);
1342 pConv = WDML_GetConvFromWnd(hwnd);
1344 if (pConv)
1346 MSG msg;
1347 HDDEDATA hdd;
1349 msg.hwnd = hwnd;
1350 msg.message = iMsg;
1351 msg.wParam = wParam;
1352 msg.lParam = lParam;
1354 WDML_HandleReply(pConv, &msg, &hdd, NULL);
1357 LeaveCriticalSection(&WDML_CritSect);
1358 return 0;
1361 return IsWindowUnicode(hwnd) ? DefWindowProcW(hwnd, iMsg, wParam, lParam) :
1362 DefWindowProcA(hwnd, iMsg, wParam, lParam);
1365 /*****************************************************************
1366 * DdeDisconnect (USER32.@)
1368 BOOL WINAPI DdeDisconnect(HCONV hConv)
1370 WDML_CONV* pConv = NULL;
1371 WDML_XACT* pXAct;
1372 DWORD count, i;
1373 BOOL ret = FALSE;
1375 TRACE("(%p)\n", hConv);
1377 if (hConv == 0)
1379 ERR("DdeDisconnect(): hConv = 0\n");
1380 return FALSE;
1383 EnterCriticalSection(&WDML_CritSect);
1384 pConv = WDML_GetConv(hConv, TRUE);
1385 if (pConv != NULL)
1387 if (pConv->wStatus & ST_CLIENT)
1389 /* FIXME: should abandon all pending transactions */
1390 pXAct = WDML_ClientQueueTerminate(pConv);
1391 if (pXAct != NULL)
1393 count = WDML_CritSect.RecursionCount;
1394 for (i = 0; i < count; i++)
1395 LeaveCriticalSection(&WDML_CritSect);
1396 if (PostMessageW(pConv->hwndServer, pXAct->ddeMsg,
1397 (WPARAM)pConv->hwndClient, pXAct->lParam))
1398 WDML_SyncWaitTransactionReply(hConv, 10000, pXAct, NULL);
1399 for (i = 0; i < count; i++)
1400 EnterCriticalSection(&WDML_CritSect);
1401 ret = TRUE;
1402 WDML_FreeTransaction(pConv->instance, pXAct, TRUE);
1403 /* still have to destroy data assosiated with conversation */
1404 WDML_RemoveConv(pConv, WDML_CLIENT_SIDE);
1406 else
1408 FIXME("Not implemented yet for a server side conversation\n");
1412 LeaveCriticalSection(&WDML_CritSect);
1414 return ret;
1417 /*****************************************************************
1418 * DdeImpersonateClient (USER32.@)
1420 BOOL WINAPI DdeImpersonateClient(HCONV hConv)
1422 WDML_CONV* pConv;
1423 BOOL ret = FALSE;
1425 TRACE("(%p)\n", hConv);
1427 EnterCriticalSection(&WDML_CritSect);
1428 pConv = WDML_GetConv(hConv, TRUE);
1429 if (pConv)
1431 ret = ImpersonateDdeClientWindow(pConv->hwndClient, pConv->hwndServer);
1433 LeaveCriticalSection(&WDML_CritSect);
1434 return ret;