4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Len White
6 * Copyright 1999 Keith Matthews
8 * Copyright 2001 Eric Pouech
9 * Copyright 2003, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
36 #include "wine/debug.h"
37 #include "dde_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
41 static const WCHAR szServerNameClass[] = {'W','i','n','e','D','d','e','S','e','r','v','e','r','N','a','m','e',0};
42 const char WDML_szServerConvClassA[] = "WineDdeServerConvA";
43 const WCHAR WDML_szServerConvClassW[] = {'W','i','n','e','D','d','e','S','e','r','v','e','r','C','o','n','v','W',0};
45 static LRESULT CALLBACK WDML_ServerNameProc(HWND, UINT, WPARAM, LPARAM);
46 static LRESULT CALLBACK WDML_ServerConvProc(HWND, UINT, WPARAM, LPARAM);
48 /******************************************************************************
49 * DdePostAdvise [USER32.@] Send transaction to DDE callback function.
52 * idInst [I] Instance identifier
53 * hszTopic [I] Handle to topic name string
54 * hszItem [I] Handle to item name string
60 BOOL WINAPI DdePostAdvise(DWORD idInst, HSZ hszTopic, HSZ hszItem)
62 WDML_INSTANCE* pInstance = NULL;
63 WDML_LINK* pLink = NULL;
64 HDDEDATA hDdeData = 0;
65 HGLOBAL hItemData = 0;
66 WDML_CONV* pConv = NULL;
70 TRACE("(%d,%p,%p)\n", idInst, hszTopic, hszItem);
72 pInstance = WDML_GetInstance(idInst);
74 if (pInstance == NULL || pInstance->links == NULL)
77 atom = WDML_MakeAtomFromHsz(hszItem);
78 if (!atom) return FALSE;
80 /* first compute the number of links which will trigger a message */
82 for (pLink = pInstance->links[WDML_SERVER_SIDE]; pLink != NULL; pLink = pLink->next)
84 if (DdeCmpStringHandles(hszItem, pLink->hszItem) == 0)
89 if (count >= CADV_LATEACK)
91 FIXME("too high value for count\n");
95 for (pLink = pInstance->links[WDML_SERVER_SIDE]; pLink != NULL; pLink = pLink->next)
97 if (DdeCmpStringHandles(hszItem, pLink->hszItem) == 0)
99 hDdeData = WDML_InvokeCallback(pInstance, XTYP_ADVREQ, pLink->uFmt, pLink->hConv,
100 hszTopic, hszItem, 0, --count, 0);
102 if (hDdeData == (HDDEDATA)CBR_BLOCK)
104 /* MS doc is not consistent here */
105 FIXME("CBR_BLOCK returned for ADVREQ\n");
110 if (pLink->transactionType & XTYPF_NODATA)
117 TRACE("with data\n");
119 hItemData = WDML_DataHandle2Global(hDdeData, FALSE, FALSE, FALSE, FALSE);
122 pConv = WDML_GetConv(pLink->hConv, TRUE);
126 if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData);
130 if (!PostMessageW(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer,
131 PackDDElParam(WM_DDE_DATA, (UINT_PTR)hItemData, atom)))
133 ERR("post message failed\n");
134 pConv->wStatus &= ~ST_CONNECTED;
135 pConv->instance->lastError = DMLERR_POSTMSG_FAILED;
136 if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData);
137 GlobalFree(hItemData);
140 if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData);
147 if (atom) GlobalDeleteAtom(atom);
152 /******************************************************************************
153 * DdeNameService [USER32.@] {Un}registers service name of DDE server
156 * idInst [I] Instance identifier
157 * hsz1 [I] Handle to service name string
159 * afCmd [I] Service name flags
165 HDDEDATA WINAPI DdeNameService(DWORD idInst, HSZ hsz1, HSZ hsz2, UINT afCmd)
167 WDML_SERVER* pServer;
168 WDML_INSTANCE* pInstance;
171 WNDCLASSEXW wndclass;
175 TRACE("(%d,%p,%p,%x)\n", idInst, hsz1, hsz2, afCmd);
177 /* First check instance
179 pInstance = WDML_GetInstance(idInst);
180 if (pInstance == NULL)
182 TRACE("Instance not found as initialised\n");
183 /* Nothing has been initialised - exit now ! can return TRUE since effect is the same */
189 /* Illegal, reserved parameter
191 pInstance->lastError = DMLERR_INVALIDPARAMETER;
192 WARN("Reserved parameter no-zero !!\n");
195 if (hsz1 == 0 && !(afCmd & DNS_UNREGISTER))
197 /* don't know if we should check this but it makes sense
198 * why supply REGISTER or filter flags if de-registering all
200 TRACE("General unregister unexpected flags\n");
201 pInstance->lastError = DMLERR_INVALIDPARAMETER;
205 switch (afCmd & (DNS_REGISTER | DNS_UNREGISTER))
208 pServer = WDML_FindServer(pInstance, hsz1, 0);
211 ERR("Trying to register already registered service!\n");
212 pInstance->lastError = DMLERR_DLL_USAGE;
216 TRACE("Adding service name\n");
218 WDML_IncHSZ(pInstance, hsz1);
220 pServer = WDML_AddServer(pInstance, hsz1, 0);
222 WDML_BroadcastDDEWindows(WDML_szEventClass, WM_WDML_REGISTER,
223 pServer->atomService, pServer->atomServiceSpec);
225 wndclass.cbSize = sizeof(wndclass);
227 wndclass.lpfnWndProc = WDML_ServerNameProc;
228 wndclass.cbClsExtra = 0;
229 wndclass.cbWndExtra = 2 * sizeof(ULONG_PTR);
230 wndclass.hInstance = 0;
232 wndclass.hCursor = 0;
233 wndclass.hbrBackground = 0;
234 wndclass.lpszMenuName = NULL;
235 wndclass.lpszClassName = szServerNameClass;
236 wndclass.hIconSm = 0;
238 RegisterClassExW(&wndclass);
240 hwndServer = CreateWindowW(szServerNameClass, NULL,
241 WS_POPUP, 0, 0, 0, 0,
244 SetWindowLongPtrW(hwndServer, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
245 SetWindowLongPtrW(hwndServer, GWL_WDML_SERVER, (ULONG_PTR)pServer);
246 TRACE("Created nameServer=%p for instance=%08x\n", hwndServer, idInst);
248 pServer->hwndServer = hwndServer;
254 /* General unregister situation
255 * terminate all server side pending conversations
257 while (pInstance->servers)
258 WDML_RemoveServer(pInstance, pInstance->servers->hszService, 0);
259 pInstance->servers = NULL;
260 TRACE("General de-register - finished\n");
264 WDML_RemoveServer(pInstance, hsz1, 0L);
269 if (afCmd & (DNS_FILTERON | DNS_FILTEROFF))
271 /* Set filter flags on to hold notifications of connection
273 pServer = WDML_FindServer(pInstance, hsz1, 0);
276 /* trying to filter where no service names !!
278 pInstance->lastError = DMLERR_DLL_USAGE;
283 pServer->filterOn = (afCmd & DNS_FILTERON) != 0;
286 return (HDDEDATA)TRUE;
289 /******************************************************************
290 * WDML_CreateServerConv
294 static WDML_CONV* WDML_CreateServerConv(WDML_INSTANCE* pInstance, HWND hwndClient,
295 HWND hwndServerName, HSZ hszApp, HSZ hszTopic)
300 if (pInstance->unicode)
302 WNDCLASSEXW wndclass;
304 wndclass.cbSize = sizeof(wndclass);
306 wndclass.lpfnWndProc = WDML_ServerConvProc;
307 wndclass.cbClsExtra = 0;
308 wndclass.cbWndExtra = 2 * sizeof(ULONG_PTR);
309 wndclass.hInstance = 0;
311 wndclass.hCursor = 0;
312 wndclass.hbrBackground = 0;
313 wndclass.lpszMenuName = NULL;
314 wndclass.lpszClassName = WDML_szServerConvClassW;
315 wndclass.hIconSm = 0;
317 RegisterClassExW(&wndclass);
319 hwndServerConv = CreateWindowW(WDML_szServerConvClassW, 0,
320 WS_CHILD, 0, 0, 0, 0,
321 hwndServerName, 0, 0, 0);
325 WNDCLASSEXA wndclass;
327 wndclass.cbSize = sizeof(wndclass);
329 wndclass.lpfnWndProc = WDML_ServerConvProc;
330 wndclass.cbClsExtra = 0;
331 wndclass.cbWndExtra = 2 * sizeof(ULONG_PTR);
332 wndclass.hInstance = 0;
334 wndclass.hCursor = 0;
335 wndclass.hbrBackground = 0;
336 wndclass.lpszMenuName = NULL;
337 wndclass.lpszClassName = WDML_szServerConvClassA;
338 wndclass.hIconSm = 0;
340 RegisterClassExA(&wndclass);
342 hwndServerConv = CreateWindowA(WDML_szServerConvClassA, 0,
343 WS_CHILD, 0, 0, 0, 0,
344 hwndServerName, 0, 0, 0);
347 TRACE("Created convServer=%p (nameServer=%p) for instance=%08x\n",
348 hwndServerConv, hwndServerName, pInstance->instanceID);
350 pConv = WDML_AddConv(pInstance, WDML_SERVER_SIDE, hszApp, hszTopic,
351 hwndClient, hwndServerConv);
354 SetWindowLongPtrW(hwndServerConv, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
355 SetWindowLongPtrW(hwndServerConv, GWL_WDML_CONVERSATION, (ULONG_PTR)pConv);
357 /* this should be the only place using SendMessage for WM_DDE_ACK */
358 /* note: sent messages shall not use packing */
359 SendMessageW(hwndClient, WM_DDE_ACK, (WPARAM)hwndServerConv,
360 MAKELPARAM(WDML_MakeAtomFromHsz(hszApp), WDML_MakeAtomFromHsz(hszTopic)));
361 /* we assume we're connected since we've sent an answer...
362 * I'm not sure what we can do... it doesn't look like the return value
363 * of SendMessage is used... sigh...
365 pConv->wStatus |= ST_CONNECTED;
369 DestroyWindow(hwndServerConv);
374 /******************************************************************
375 * WDML_ServerNameProc
379 static LRESULT CALLBACK WDML_ServerNameProc(HWND hwndServer, UINT iMsg, WPARAM wParam, LPARAM lParam)
383 HDDEDATA hDdeData = 0;
384 WDML_INSTANCE* pInstance;
389 case WM_DDE_INITIATE:
391 /* wParam -- sending window handle
392 LOWORD(lParam) -- application atom
393 HIWORD(lParam) -- topic atom */
395 TRACE("WM_DDE_INITIATE message received!\n");
396 hwndClient = (HWND)wParam;
398 pInstance = WDML_GetInstanceFromWnd(hwndServer);
399 TRACE("idInst=%d, threadID=0x%x\n", pInstance->instanceID, GetCurrentThreadId());
400 if (!pInstance) return 0;
402 /* don't free DDEParams, since this is a broadcast */
403 UnpackDDElParam(WM_DDE_INITIATE, lParam, &uiLo, &uiHi);
405 hszApp = WDML_MakeHszFromAtom(pInstance, uiLo);
406 hszTop = WDML_MakeHszFromAtom(pInstance, uiHi);
408 if (!(pInstance->CBFflags & CBF_FAIL_CONNECTIONS))
412 CONVCONTEXT* pcc = NULL;
416 if (GetWindowThreadProcessId(hwndClient, NULL) == GetWindowThreadProcessId(hwndServer, NULL) &&
417 WDML_GetInstanceFromWnd(hwndClient) == WDML_GetInstanceFromWnd(hwndServer))
421 /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
422 * handled under DDEML, and if so build a default context
424 if ((GetClassNameA(hwndClient, buf, sizeof(buf)) &&
425 lstrcmpiA(buf, WDML_szClientConvClassA) == 0) ||
426 (GetClassNameW(hwndClient, (LPWSTR)buf, sizeof(buf)/sizeof(WCHAR)) &&
427 lstrcmpiW((LPWSTR)buf, WDML_szClientConvClassW) == 0))
430 memset(pcc, 0, sizeof(*pcc));
431 pcc->cb = sizeof(*pcc);
432 pcc->iCodePage = IsWindowUnicode(hwndClient) ? CP_WINUNICODE : CP_WINANSI;
434 if ((pInstance->CBFflags & CBF_FAIL_SELFCONNECTIONS) && self)
436 TRACE("Don't do self connection as requested\n");
438 else if (hszApp && hszTop)
440 WDML_SERVER* pServer = (WDML_SERVER*)GetWindowLongPtrW(hwndServer, GWL_WDML_SERVER);
442 /* check filters for name service */
443 if (!pServer->filterOn || DdeCmpStringHandles(pServer->hszService, hszApp) == 0)
445 /* pass on to the callback */
446 hDdeData = WDML_InvokeCallback(pInstance, XTYP_CONNECT,
447 0, 0, hszTop, hszApp, 0, (ULONG_PTR)pcc, self);
448 if ((ULONG_PTR)hDdeData)
450 pConv = WDML_CreateServerConv(pInstance, hwndClient, hwndServer,
454 if (pcc) pConv->wStatus |= ST_ISLOCAL;
455 WDML_InvokeCallback(pInstance, XTYP_CONNECT_CONFIRM, 0, (HCONV)pConv,
456 hszTop, hszApp, 0, (ULONG_PTR)pcc, self);
461 else if (pInstance->servers)
463 /* pass on to the callback */
464 hDdeData = WDML_InvokeCallback(pInstance, XTYP_WILDCONNECT,
465 0, 0, hszTop, hszApp, 0, (ULONG_PTR)pcc, self);
467 if (hDdeData == (HDDEDATA)CBR_BLOCK)
469 /* MS doc is not consistent here */
470 FIXME("CBR_BLOCK returned for WILDCONNECT\n");
472 else if ((ULONG_PTR)hDdeData != 0)
476 hszp = (HSZPAIR*)DdeAccessData(hDdeData, NULL);
480 for (i = 0; hszp[i].hszSvc && hszp[i].hszTopic; i++)
482 pConv = WDML_CreateServerConv(pInstance, hwndClient, hwndServer,
483 hszp[i].hszSvc, hszp[i].hszTopic);
486 if (pcc) pConv->wStatus |= ST_ISLOCAL;
487 WDML_InvokeCallback(pInstance, XTYP_CONNECT_CONFIRM, 0, (HCONV)pConv,
488 hszp[i].hszTopic, hszp[i].hszSvc, 0, (ULONG_PTR)pcc, self);
491 DdeUnaccessData(hDdeData);
493 if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData);
501 FIXME("WM_DDE_REQUEST message received!\n");
504 FIXME("WM_DDE_ADVISE message received!\n");
506 case WM_DDE_UNADVISE:
507 FIXME("WM_DDE_UNADVISE message received!\n");
510 FIXME("WM_DDE_EXECUTE message received!\n");
513 FIXME("WM_DDE_POKE message received!\n");
515 case WM_DDE_TERMINATE:
516 FIXME("WM_DDE_TERMINATE message received!\n");
522 return DefWindowProcW(hwndServer, iMsg, wParam, lParam);
525 /******************************************************************
526 * WDML_ServerQueueRequest
530 static WDML_XACT* WDML_ServerQueueRequest(WDML_CONV* pConv, LPARAM lParam)
535 UnpackDDElParam(WM_DDE_REQUEST, lParam, &uiLo, &uiHi);
537 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_REQUEST,
538 uiLo, WDML_MakeHszFromAtom(pConv->instance, uiHi));
539 if (pXAct) pXAct->atom = uiHi;
543 /******************************************************************
544 * WDML_ServerHandleRequest
548 static WDML_QUEUE_STATE WDML_ServerHandleRequest(WDML_CONV* pConv, WDML_XACT* pXAct)
550 HDDEDATA hDdeData = 0;
553 if (!(pConv->instance->CBFflags & CBF_FAIL_REQUESTS))
556 hDdeData = WDML_InvokeCallback(pConv->instance, XTYP_REQUEST, pXAct->wFmt, (HCONV)pConv,
557 pConv->hszTopic, pXAct->hszItem, 0, 0, 0);
560 switch ((ULONG_PTR)hDdeData)
563 TRACE("No data returned from the Callback\n");
567 case (ULONG_PTR)CBR_BLOCK:
568 return WDML_QS_BLOCK;
572 HGLOBAL hMem = WDML_DataHandle2Global(hDdeData, TRUE, FALSE, FALSE, FALSE);
573 if (!PostMessageW(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer,
574 ReuseDDElParam(pXAct->lParam, WM_DDE_REQUEST, WM_DDE_DATA,
575 (UINT_PTR)hMem, (UINT_PTR)pXAct->atom)))
577 pConv->instance->lastError = DMLERR_POSTMSG_FAILED;
578 DdeFreeDataHandle(hDdeData);
586 WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, FALSE, fAck, pXAct->atom, pXAct->lParam, WM_DDE_REQUEST);
588 WDML_DecHSZ(pConv->instance, pXAct->hszItem);
590 return WDML_QS_HANDLED;
593 /******************************************************************
594 * WDML_ServerQueueAdvise
598 static WDML_XACT* WDML_ServerQueueAdvise(WDML_CONV* pConv, LPARAM lParam)
603 /* XTYP_ADVSTART transaction:
604 establish link and save link info to InstanceInfoTable */
606 if (!UnpackDDElParam(WM_DDE_ADVISE, lParam, &uiLo, &uiHi))
609 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_ADVISE,
610 0, WDML_MakeHszFromAtom(pConv->instance, uiHi));
613 pXAct->hMem = (HGLOBAL)uiLo;
619 /******************************************************************
620 * WDML_ServerHandleAdvise
624 static WDML_QUEUE_STATE WDML_ServerHandleAdvise(WDML_CONV* pConv, WDML_XACT* pXAct)
628 DDEADVISE* pDdeAdvise;
629 HDDEDATA hDdeData = 0;
632 pDdeAdvise = (DDEADVISE*)GlobalLock(pXAct->hMem);
633 uType = XTYP_ADVSTART |
634 (pDdeAdvise->fDeferUpd ? XTYPF_NODATA : 0) |
635 (pDdeAdvise->fAckReq ? XTYPF_ACKREQ : 0);
637 if (!(pConv->instance->CBFflags & CBF_FAIL_ADVISES))
639 hDdeData = WDML_InvokeCallback(pConv->instance, XTYP_ADVSTART, pDdeAdvise->cfFormat,
640 (HCONV)pConv, pConv->hszTopic, pXAct->hszItem, 0, 0, 0);
643 switch ((ULONG_PTR)hDdeData)
646 TRACE("No data returned from the Callback\n");
650 case (ULONG_PTR)CBR_BLOCK:
651 return WDML_QS_BLOCK;
654 /* billx: first to see if the link is already created. */
655 pLink = WDML_FindLink(pConv->instance, (HCONV)pConv, WDML_SERVER_SIDE,
656 pXAct->hszItem, TRUE, pDdeAdvise->cfFormat);
660 /* we found a link, and only need to modify it in case it changes */
661 pLink->transactionType = uType;
665 TRACE("Adding Link with hConv %p\n", pConv);
666 WDML_AddLink(pConv->instance, (HCONV)pConv, WDML_SERVER_SIDE,
667 uType, pXAct->hszItem, pDdeAdvise->cfFormat);
672 GlobalUnlock(pXAct->hMem);
675 GlobalFree(pXAct->hMem);
679 WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, FALSE, fAck, pXAct->atom, pXAct->lParam, WM_DDE_ADVISE);
681 WDML_DecHSZ(pConv->instance, pXAct->hszItem);
683 return WDML_QS_HANDLED;
686 /******************************************************************
687 * WDML_ServerQueueUnadvise
691 static WDML_XACT* WDML_ServerQueueUnadvise(WDML_CONV* pConv, LPARAM lParam)
696 UnpackDDElParam(WM_DDE_UNADVISE, lParam, &uiLo, &uiHi);
698 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_UNADVISE,
699 uiLo, WDML_MakeHszFromAtom(pConv->instance, uiHi));
700 if (pXAct) pXAct->atom = uiHi;
704 /******************************************************************
705 * WDML_ServerHandleUnadvise
709 static WDML_QUEUE_STATE WDML_ServerHandleUnadvise(WDML_CONV* pConv, WDML_XACT* pXAct)
713 if (pXAct->hszItem == NULL || pXAct->wFmt == 0)
715 ERR("Unsupported yet options (null item or clipboard format)\n");
716 return WDML_QS_ERROR;
719 pLink = WDML_FindLink(pConv->instance, (HCONV)pConv, WDML_SERVER_SIDE,
720 pXAct->hszItem, TRUE, pXAct->wFmt);
723 ERR("Couln'd find link for %p, dropping request\n", pXAct->hszItem);
724 FreeDDElParam(WM_DDE_UNADVISE, pXAct->lParam);
725 return WDML_QS_ERROR;
728 if (!(pConv->instance->CBFflags & CBF_FAIL_ADVISES))
730 WDML_InvokeCallback(pConv->instance, XTYP_ADVSTOP, pXAct->wFmt, (HCONV)pConv,
731 pConv->hszTopic, pXAct->hszItem, 0, 0, 0);
734 WDML_RemoveLink(pConv->instance, (HCONV)pConv, WDML_SERVER_SIDE,
735 pXAct->hszItem, pXAct->wFmt);
738 WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, FALSE, TRUE, pXAct->atom,
739 pXAct->lParam, WM_DDE_UNADVISE);
741 WDML_DecHSZ(pConv->instance, pXAct->hszItem);
743 return WDML_QS_HANDLED;
746 /******************************************************************
751 static WDML_XACT* WDML_ServerQueueExecute(WDML_CONV* pConv, LPARAM lParam)
755 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_EXECUTE, 0, 0);
758 pXAct->hMem = (HGLOBAL)lParam;
763 /******************************************************************
764 * WDML_ServerHandleExecute
768 static WDML_QUEUE_STATE WDML_ServerHandleExecute(WDML_CONV* pConv, WDML_XACT* pXAct)
770 HDDEDATA hDdeData = DDE_FNOTPROCESSED;
771 BOOL fAck = FALSE, fBusy = FALSE;
773 if (!(pConv->instance->CBFflags & CBF_FAIL_EXECUTES))
775 LPVOID ptr = GlobalLock(pXAct->hMem);
779 hDdeData = DdeCreateDataHandle(0, ptr, GlobalSize(pXAct->hMem),
781 GlobalUnlock(pXAct->hMem);
783 hDdeData = WDML_InvokeCallback(pConv->instance, XTYP_EXECUTE, 0, (HCONV)pConv,
784 pConv->hszTopic, 0, hDdeData, 0L, 0L);
787 switch ((ULONG_PTR)hDdeData)
789 case (ULONG_PTR)CBR_BLOCK:
790 return WDML_QS_BLOCK;
799 FIXME("Unsupported returned value %p\n", hDdeData);
801 case DDE_FNOTPROCESSED:
804 WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, fBusy, fAck, (UINT)pXAct->hMem, 0, 0);
806 return WDML_QS_HANDLED;
809 /******************************************************************
810 * WDML_ServerQueuePoke
814 static WDML_XACT* WDML_ServerQueuePoke(WDML_CONV* pConv, LPARAM lParam)
819 UnpackDDElParam(WM_DDE_POKE, lParam, &uiLo, &uiHi);
821 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_POKE,
822 0, WDML_MakeHszFromAtom(pConv->instance, uiHi));
826 pXAct->hMem = (HGLOBAL)uiLo;
831 /******************************************************************
832 * WDML_ServerHandlePoke
836 static WDML_QUEUE_STATE WDML_ServerHandlePoke(WDML_CONV* pConv, WDML_XACT* pXAct)
840 BOOL fBusy = FALSE, fAck = FALSE;
842 pDdePoke = (DDEPOKE*)GlobalLock(pXAct->hMem);
845 return WDML_QS_ERROR;
848 if (!(pConv->instance->CBFflags & CBF_FAIL_POKES))
850 hDdeData = DdeCreateDataHandle(pConv->instance->instanceID, pDdePoke->Value,
851 GlobalSize(pXAct->hMem) - sizeof(DDEPOKE) + 1,
852 0, 0, pDdePoke->cfFormat, 0);
855 HDDEDATA hDdeDataOut;
857 hDdeDataOut = WDML_InvokeCallback(pConv->instance, XTYP_POKE, pDdePoke->cfFormat,
858 (HCONV)pConv, pConv->hszTopic, pXAct->hszItem,
860 switch ((ULONG_PTR)hDdeDataOut)
869 FIXME("Unsupported returned value %p\n", hDdeDataOut);
871 case DDE_FNOTPROCESSED:
874 DdeFreeDataHandle(hDdeData);
877 GlobalUnlock(pXAct->hMem);
881 GlobalFree(pXAct->hMem);
883 WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, fBusy, fAck, pXAct->atom, pXAct->lParam, WM_DDE_POKE);
885 WDML_DecHSZ(pConv->instance, pXAct->hszItem);
887 return WDML_QS_HANDLED;
890 /******************************************************************
891 * WDML_ServerQueueTerminate
895 static WDML_XACT* WDML_ServerQueueTerminate(WDML_CONV* pConv, LPARAM lParam)
899 pXAct = WDML_AllocTransaction(pConv->instance, WM_DDE_TERMINATE, 0, 0);
903 /******************************************************************
904 * WDML_ServerHandleTerminate
908 static WDML_QUEUE_STATE WDML_ServerHandleTerminate(WDML_CONV* pConv, WDML_XACT* pXAct)
910 /* billx: two things to remove: the conv, and associated links.
911 * Respond with another WM_DDE_TERMINATE iMsg.
913 if (!(pConv->instance->CBFflags & CBF_SKIP_DISCONNECTS))
915 WDML_InvokeCallback(pConv->instance, XTYP_DISCONNECT, 0, (HCONV)pConv, 0, 0,
916 0, 0, (pConv->wStatus & ST_ISSELF) ? 1 : 0);
918 PostMessageW(pConv->hwndClient, WM_DDE_TERMINATE, (WPARAM)pConv->hwndServer, 0);
919 WDML_RemoveConv(pConv, WDML_SERVER_SIDE);
921 return WDML_QS_HANDLED;
924 /******************************************************************
929 WDML_QUEUE_STATE WDML_ServerHandle(WDML_CONV* pConv, WDML_XACT* pXAct)
931 WDML_QUEUE_STATE qs = WDML_QS_ERROR;
933 switch (pXAct->ddeMsg)
935 case WM_DDE_INITIATE:
936 FIXME("WM_DDE_INITIATE shouldn't be there!\n");
939 qs = WDML_ServerHandleRequest(pConv, pXAct);
943 qs = WDML_ServerHandleAdvise(pConv, pXAct);
946 case WM_DDE_UNADVISE:
947 qs = WDML_ServerHandleUnadvise(pConv, pXAct);
951 qs = WDML_ServerHandleExecute(pConv, pXAct);
955 qs = WDML_ServerHandlePoke(pConv, pXAct);
958 case WM_DDE_TERMINATE:
959 qs = WDML_ServerHandleTerminate(pConv, pXAct);
963 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
967 FIXME("Unsupported message %d\n", pXAct->ddeMsg);
972 /******************************************************************
973 * WDML_ServerConvProc
977 static LRESULT CALLBACK WDML_ServerConvProc(HWND hwndServer, UINT iMsg, WPARAM wParam, LPARAM lParam)
979 WDML_INSTANCE* pInstance;
981 WDML_XACT* pXAct = NULL;
983 TRACE("%p %04x %08x %08lx\n", hwndServer, iMsg, wParam , lParam);
985 if (iMsg == WM_DESTROY)
987 pConv = WDML_GetConvFromWnd(hwndServer);
988 if (pConv && !(pConv->wStatus & ST_TERMINATED))
990 WDML_ServerHandleTerminate(pConv, NULL);
993 if (iMsg < WM_DDE_FIRST || iMsg > WM_DDE_LAST)
995 return IsWindowUnicode(hwndServer) ? DefWindowProcW(hwndServer, iMsg, wParam, lParam) :
996 DefWindowProcA(hwndServer, iMsg, wParam, lParam);
999 pInstance = WDML_GetInstanceFromWnd(hwndServer);
1000 pConv = WDML_GetConvFromWnd(hwndServer);
1004 ERR("Got a message (%x) on a not known conversation, dropping request\n", iMsg);
1007 if (pConv->hwndClient != WIN_GetFullHandle( (HWND)wParam ) || pConv->hwndServer != hwndServer)
1009 ERR("mismatch between C/S windows and converstation\n");
1012 if (pConv->instance != pInstance || pConv->instance == NULL)
1014 ERR("mismatch in instances\n");
1020 case WM_DDE_INITIATE:
1021 FIXME("WM_DDE_INITIATE message received!\n");
1024 case WM_DDE_REQUEST:
1025 pXAct = WDML_ServerQueueRequest(pConv, lParam);
1029 pXAct = WDML_ServerQueueAdvise(pConv, lParam);
1032 case WM_DDE_UNADVISE:
1033 pXAct = WDML_ServerQueueUnadvise(pConv, lParam);
1036 case WM_DDE_EXECUTE:
1037 pXAct = WDML_ServerQueueExecute(pConv, lParam);
1041 pXAct = WDML_ServerQueuePoke(pConv, lParam);
1044 case WM_DDE_TERMINATE:
1045 pXAct = WDML_ServerQueueTerminate(pConv, lParam);
1049 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
1053 FIXME("Unsupported message %x\n", iMsg);
1059 pXAct->lParam = lParam;
1061 if ((pConv->wStatus & ST_BLOCKED) || WDML_ServerHandle(pConv, pXAct) == WDML_QS_BLOCK)
1063 TRACE("Transactions are blocked, add to the queue and exit\n");
1064 WDML_QueueTransaction(pConv, pXAct);
1068 WDML_FreeTransaction(pInstance, pXAct, TRUE);
1072 pConv->instance->lastError = DMLERR_MEMORY_ERROR;