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
35 #include "wine/debug.h"
36 #include "dde_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ddeml
);
40 static const WCHAR szServerNameClass
[] = {'W','i','n','e','D','d','e','S','e','r','v','e','r','N','a','m','e',0};
41 const char WDML_szServerConvClassA
[] = "WineDdeServerConvA";
42 const WCHAR WDML_szServerConvClassW
[] = {'W','i','n','e','D','d','e','S','e','r','v','e','r','C','o','n','v','W',0};
44 static LRESULT CALLBACK
WDML_ServerNameProc(HWND
, UINT
, WPARAM
, LPARAM
);
45 static LRESULT CALLBACK
WDML_ServerConvProc(HWND
, UINT
, WPARAM
, LPARAM
);
47 /******************************************************************************
48 * DdePostAdvise [USER32.@] Send transaction to DDE callback function.
51 * idInst [I] Instance identifier
52 * hszTopic [I] Handle to topic name string
53 * hszItem [I] Handle to item name string
59 BOOL WINAPI
DdePostAdvise(DWORD idInst
, HSZ hszTopic
, HSZ hszItem
)
61 WDML_INSTANCE
* pInstance
= NULL
;
62 WDML_LINK
* pLink
= NULL
;
63 HDDEDATA hDdeData
= 0;
64 HGLOBAL hItemData
= 0;
65 WDML_CONV
* pConv
= NULL
;
69 TRACE("(%d,%p,%p)\n", idInst
, hszTopic
, hszItem
);
71 pInstance
= WDML_GetInstance(idInst
);
73 if (pInstance
== NULL
|| pInstance
->links
== NULL
)
76 atom
= WDML_MakeAtomFromHsz(hszItem
);
77 if (!atom
) return FALSE
;
79 /* first compute the number of links which will trigger a message */
81 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
83 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
88 if (count
>= CADV_LATEACK
)
90 FIXME("too high value for count\n");
94 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
96 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
98 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_ADVREQ
, pLink
->uFmt
, pLink
->hConv
,
99 hszTopic
, hszItem
, 0, --count
, 0);
101 if (hDdeData
== (HDDEDATA
)CBR_BLOCK
)
103 /* MS doc is not consistent here */
104 FIXME("CBR_BLOCK returned for ADVREQ\n");
109 if (pLink
->transactionType
& XTYPF_NODATA
)
116 TRACE("with data\n");
118 hItemData
= WDML_DataHandle2Global(hDdeData
, FALSE
, FALSE
, FALSE
, FALSE
);
121 pConv
= WDML_GetConv(pLink
->hConv
, TRUE
);
125 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
129 if (!PostMessageW(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
130 PackDDElParam(WM_DDE_DATA
, (UINT_PTR
)hItemData
, atom
)))
132 ERR("post message failed\n");
133 pConv
->wStatus
&= ~ST_CONNECTED
;
134 pConv
->instance
->lastError
= DMLERR_POSTMSG_FAILED
;
135 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
136 GlobalFree(hItemData
);
139 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
146 if (atom
) GlobalDeleteAtom(atom
);
151 /******************************************************************************
152 * DdeNameService [USER32.@] {Un}registers service name of DDE server
155 * idInst [I] Instance identifier
156 * hsz1 [I] Handle to service name string
158 * afCmd [I] Service name flags
164 HDDEDATA WINAPI
DdeNameService(DWORD idInst
, HSZ hsz1
, HSZ hsz2
, UINT afCmd
)
166 WDML_SERVER
* pServer
;
167 WDML_INSTANCE
* pInstance
;
170 WNDCLASSEXW wndclass
;
174 TRACE("(%d,%p,%p,%x)\n", idInst
, hsz1
, hsz2
, afCmd
);
176 /* First check instance
178 pInstance
= WDML_GetInstance(idInst
);
179 if (pInstance
== NULL
)
181 TRACE("Instance not found as initialised\n");
182 /* Nothing has been initialised - exit now ! can return TRUE since effect is the same */
188 /* Illegal, reserved parameter
190 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
191 WARN("Reserved parameter no-zero !!\n");
194 if (hsz1
== 0 && !(afCmd
& DNS_UNREGISTER
))
196 /* don't know if we should check this but it makes sense
197 * why supply REGISTER or filter flags if de-registering all
199 TRACE("General unregister unexpected flags\n");
200 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
204 switch (afCmd
& (DNS_REGISTER
| DNS_UNREGISTER
))
207 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
210 ERR("Trying to register already registered service!\n");
211 pInstance
->lastError
= DMLERR_DLL_USAGE
;
215 TRACE("Adding service name\n");
217 WDML_IncHSZ(pInstance
, hsz1
);
219 pServer
= WDML_AddServer(pInstance
, hsz1
, 0);
221 WDML_BroadcastDDEWindows(WDML_szEventClass
, WM_WDML_REGISTER
,
222 pServer
->atomService
, pServer
->atomServiceSpec
);
224 wndclass
.cbSize
= sizeof(wndclass
);
226 wndclass
.lpfnWndProc
= WDML_ServerNameProc
;
227 wndclass
.cbClsExtra
= 0;
228 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
229 wndclass
.hInstance
= 0;
231 wndclass
.hCursor
= 0;
232 wndclass
.hbrBackground
= 0;
233 wndclass
.lpszMenuName
= NULL
;
234 wndclass
.lpszClassName
= szServerNameClass
;
235 wndclass
.hIconSm
= 0;
237 RegisterClassExW(&wndclass
);
239 hwndServer
= CreateWindowW(szServerNameClass
, NULL
,
240 WS_POPUP
, 0, 0, 0, 0,
243 SetWindowLongPtrW(hwndServer
, GWL_WDML_INSTANCE
, (ULONG_PTR
)pInstance
);
244 SetWindowLongPtrW(hwndServer
, GWL_WDML_SERVER
, (ULONG_PTR
)pServer
);
245 TRACE("Created nameServer=%p for instance=%08x\n", hwndServer
, idInst
);
247 pServer
->hwndServer
= hwndServer
;
253 /* General unregister situation
254 * terminate all server side pending conversations
256 while (pInstance
->servers
)
257 WDML_RemoveServer(pInstance
, pInstance
->servers
->hszService
, 0);
258 pInstance
->servers
= NULL
;
259 TRACE("General de-register - finished\n");
263 WDML_RemoveServer(pInstance
, hsz1
, 0L);
268 if (afCmd
& (DNS_FILTERON
| DNS_FILTEROFF
))
270 /* Set filter flags on to hold notifications of connection
272 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
275 /* trying to filter where no service names !!
277 pInstance
->lastError
= DMLERR_DLL_USAGE
;
282 pServer
->filterOn
= (afCmd
& DNS_FILTERON
) != 0;
285 return (HDDEDATA
)TRUE
;
288 /******************************************************************
289 * WDML_CreateServerConv
293 static WDML_CONV
* WDML_CreateServerConv(WDML_INSTANCE
* pInstance
, HWND hwndClient
,
294 HWND hwndServerName
, HSZ hszApp
, HSZ hszTopic
)
299 if (pInstance
->unicode
)
301 WNDCLASSEXW wndclass
;
303 wndclass
.cbSize
= sizeof(wndclass
);
305 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
306 wndclass
.cbClsExtra
= 0;
307 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
308 wndclass
.hInstance
= 0;
310 wndclass
.hCursor
= 0;
311 wndclass
.hbrBackground
= 0;
312 wndclass
.lpszMenuName
= NULL
;
313 wndclass
.lpszClassName
= WDML_szServerConvClassW
;
314 wndclass
.hIconSm
= 0;
316 RegisterClassExW(&wndclass
);
318 hwndServerConv
= CreateWindowW(WDML_szServerConvClassW
, 0,
319 WS_CHILD
, 0, 0, 0, 0,
320 hwndServerName
, 0, 0, 0);
324 WNDCLASSEXA wndclass
;
326 wndclass
.cbSize
= sizeof(wndclass
);
328 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
329 wndclass
.cbClsExtra
= 0;
330 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
331 wndclass
.hInstance
= 0;
333 wndclass
.hCursor
= 0;
334 wndclass
.hbrBackground
= 0;
335 wndclass
.lpszMenuName
= NULL
;
336 wndclass
.lpszClassName
= WDML_szServerConvClassA
;
337 wndclass
.hIconSm
= 0;
339 RegisterClassExA(&wndclass
);
341 hwndServerConv
= CreateWindowA(WDML_szServerConvClassA
, 0,
342 WS_CHILD
, 0, 0, 0, 0,
343 hwndServerName
, 0, 0, 0);
346 TRACE("Created convServer=%p (nameServer=%p) for instance=%08x\n",
347 hwndServerConv
, hwndServerName
, pInstance
->instanceID
);
349 pConv
= WDML_AddConv(pInstance
, WDML_SERVER_SIDE
, hszApp
, hszTopic
,
350 hwndClient
, hwndServerConv
);
353 SetWindowLongPtrW(hwndServerConv
, GWL_WDML_INSTANCE
, (ULONG_PTR
)pInstance
);
354 SetWindowLongPtrW(hwndServerConv
, GWL_WDML_CONVERSATION
, (ULONG_PTR
)pConv
);
356 /* this should be the only place using SendMessage for WM_DDE_ACK */
357 /* note: sent messages shall not use packing */
358 SendMessageW(hwndClient
, WM_DDE_ACK
, (WPARAM
)hwndServerConv
,
359 MAKELPARAM(WDML_MakeAtomFromHsz(hszApp
), WDML_MakeAtomFromHsz(hszTopic
)));
360 /* we assume we're connected since we've sent an answer...
361 * I'm not sure what we can do... it doesn't look like the return value
362 * of SendMessage is used... sigh...
364 pConv
->wStatus
|= ST_CONNECTED
;
368 DestroyWindow(hwndServerConv
);
373 /******************************************************************
374 * WDML_ServerNameProc
378 static LRESULT CALLBACK
WDML_ServerNameProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
382 HDDEDATA hDdeData
= 0;
383 WDML_INSTANCE
* pInstance
;
388 case WM_DDE_INITIATE
:
390 /* wParam -- sending window handle
391 LOWORD(lParam) -- application atom
392 HIWORD(lParam) -- topic atom */
394 TRACE("WM_DDE_INITIATE message received!\n");
395 hwndClient
= (HWND
)wParam
;
397 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
398 TRACE("idInst=%d, threadID=0x%x\n", pInstance
->instanceID
, GetCurrentThreadId());
399 if (!pInstance
) return 0;
401 /* don't free DDEParams, since this is a broadcast */
402 UnpackDDElParam(WM_DDE_INITIATE
, lParam
, &uiLo
, &uiHi
);
404 hszApp
= WDML_MakeHszFromAtom(pInstance
, uiLo
);
405 hszTop
= WDML_MakeHszFromAtom(pInstance
, uiHi
);
407 if (!(pInstance
->CBFflags
& CBF_FAIL_CONNECTIONS
))
411 CONVCONTEXT
* pcc
= NULL
;
415 if (GetWindowThreadProcessId(hwndClient
, NULL
) == GetWindowThreadProcessId(hwndServer
, NULL
) &&
416 WDML_GetInstanceFromWnd(hwndClient
) == WDML_GetInstanceFromWnd(hwndServer
))
420 /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
421 * handled under DDEML, and if so build a default context
423 if ((GetClassNameA(hwndClient
, buf
, sizeof(buf
)) &&
424 lstrcmpiA(buf
, WDML_szClientConvClassA
) == 0) ||
425 (GetClassNameW(hwndClient
, (LPWSTR
)buf
, sizeof(buf
)/sizeof(WCHAR
)) &&
426 lstrcmpiW((LPWSTR
)buf
, WDML_szClientConvClassW
) == 0))
429 memset(pcc
, 0, sizeof(*pcc
));
430 pcc
->cb
= sizeof(*pcc
);
431 pcc
->iCodePage
= IsWindowUnicode(hwndClient
) ? CP_WINUNICODE
: CP_WINANSI
;
433 if ((pInstance
->CBFflags
& CBF_FAIL_SELFCONNECTIONS
) && self
)
435 TRACE("Don't do self connection as requested\n");
437 else if (hszApp
&& hszTop
)
439 WDML_SERVER
* pServer
= (WDML_SERVER
*)GetWindowLongPtrW(hwndServer
, GWL_WDML_SERVER
);
441 /* check filters for name service */
442 if (!pServer
->filterOn
|| DdeCmpStringHandles(pServer
->hszService
, hszApp
) == 0)
444 /* pass on to the callback */
445 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_CONNECT
,
446 0, 0, hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
447 if ((ULONG_PTR
)hDdeData
)
449 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
453 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
454 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
455 hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
460 else if (pInstance
->servers
)
462 /* pass on to the callback */
463 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_WILDCONNECT
,
464 0, 0, hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
466 if (hDdeData
== (HDDEDATA
)CBR_BLOCK
)
468 /* MS doc is not consistent here */
469 FIXME("CBR_BLOCK returned for WILDCONNECT\n");
471 else if ((ULONG_PTR
)hDdeData
!= 0)
475 hszp
= (HSZPAIR
*)DdeAccessData(hDdeData
, NULL
);
479 for (i
= 0; hszp
[i
].hszSvc
&& hszp
[i
].hszTopic
; i
++)
481 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
482 hszp
[i
].hszSvc
, hszp
[i
].hszTopic
);
485 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
486 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
487 hszp
[i
].hszTopic
, hszp
[i
].hszSvc
, 0, (ULONG_PTR
)pcc
, self
);
490 DdeUnaccessData(hDdeData
);
492 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
500 FIXME("WM_DDE_REQUEST message received!\n");
503 FIXME("WM_DDE_ADVISE message received!\n");
505 case WM_DDE_UNADVISE
:
506 FIXME("WM_DDE_UNADVISE message received!\n");
509 FIXME("WM_DDE_EXECUTE message received!\n");
512 FIXME("WM_DDE_POKE message received!\n");
514 case WM_DDE_TERMINATE
:
515 FIXME("WM_DDE_TERMINATE message received!\n");
521 return DefWindowProcW(hwndServer
, iMsg
, wParam
, lParam
);
524 /******************************************************************
525 * WDML_ServerQueueRequest
529 static WDML_XACT
* WDML_ServerQueueRequest(WDML_CONV
* pConv
, LPARAM lParam
)
534 UnpackDDElParam(WM_DDE_REQUEST
, lParam
, &uiLo
, &uiHi
);
536 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_REQUEST
,
537 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
538 if (pXAct
) pXAct
->atom
= uiHi
;
542 /******************************************************************
543 * WDML_ServerHandleRequest
547 static WDML_QUEUE_STATE
WDML_ServerHandleRequest(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
549 HDDEDATA hDdeData
= 0;
552 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_REQUESTS
))
555 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_REQUEST
, pXAct
->wFmt
, (HCONV
)pConv
,
556 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
559 switch ((ULONG_PTR
)hDdeData
)
562 TRACE("No data returned from the Callback\n");
566 case (ULONG_PTR
)CBR_BLOCK
:
567 return WDML_QS_BLOCK
;
571 HGLOBAL hMem
= WDML_DataHandle2Global(hDdeData
, TRUE
, FALSE
, FALSE
, FALSE
);
572 if (!PostMessageW(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
573 ReuseDDElParam(pXAct
->lParam
, WM_DDE_REQUEST
, WM_DDE_DATA
,
574 (UINT_PTR
)hMem
, (UINT_PTR
)pXAct
->atom
)))
576 pConv
->instance
->lastError
= DMLERR_POSTMSG_FAILED
;
577 DdeFreeDataHandle(hDdeData
);
585 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_REQUEST
);
587 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
589 return WDML_QS_HANDLED
;
592 /******************************************************************
593 * WDML_ServerQueueAdvise
597 static WDML_XACT
* WDML_ServerQueueAdvise(WDML_CONV
* pConv
, LPARAM lParam
)
602 /* XTYP_ADVSTART transaction:
603 establish link and save link info to InstanceInfoTable */
605 if (!UnpackDDElParam(WM_DDE_ADVISE
, lParam
, &uiLo
, &uiHi
))
608 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_ADVISE
,
609 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
612 pXAct
->hMem
= (HGLOBAL
)uiLo
;
618 /******************************************************************
619 * WDML_ServerHandleAdvise
623 static WDML_QUEUE_STATE
WDML_ServerHandleAdvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
627 DDEADVISE
* pDdeAdvise
;
628 HDDEDATA hDdeData
= 0;
631 pDdeAdvise
= (DDEADVISE
*)GlobalLock(pXAct
->hMem
);
632 uType
= XTYP_ADVSTART
|
633 (pDdeAdvise
->fDeferUpd
? XTYPF_NODATA
: 0) |
634 (pDdeAdvise
->fAckReq
? XTYPF_ACKREQ
: 0);
636 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
638 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTART
, pDdeAdvise
->cfFormat
,
639 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
642 switch ((ULONG_PTR
)hDdeData
)
645 TRACE("No data returned from the Callback\n");
649 case (ULONG_PTR
)CBR_BLOCK
:
650 return WDML_QS_BLOCK
;
653 /* billx: first to see if the link is already created. */
654 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
655 pXAct
->hszItem
, TRUE
, pDdeAdvise
->cfFormat
);
659 /* we found a link, and only need to modify it in case it changes */
660 pLink
->transactionType
= uType
;
664 TRACE("Adding Link with hConv %p\n", pConv
);
665 WDML_AddLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
666 uType
, pXAct
->hszItem
, pDdeAdvise
->cfFormat
);
671 GlobalUnlock(pXAct
->hMem
);
674 GlobalFree(pXAct
->hMem
);
678 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_ADVISE
);
680 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
682 return WDML_QS_HANDLED
;
685 /******************************************************************
686 * WDML_ServerQueueUnadvise
690 static WDML_XACT
* WDML_ServerQueueUnadvise(WDML_CONV
* pConv
, LPARAM lParam
)
695 UnpackDDElParam(WM_DDE_UNADVISE
, lParam
, &uiLo
, &uiHi
);
697 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_UNADVISE
,
698 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
699 if (pXAct
) pXAct
->atom
= uiHi
;
703 /******************************************************************
704 * WDML_ServerHandleUnadvise
708 static WDML_QUEUE_STATE
WDML_ServerHandleUnadvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
712 if (pXAct
->hszItem
== NULL
|| pXAct
->wFmt
== 0)
714 ERR("Unsupported yet options (null item or clipboard format)\n");
715 return WDML_QS_ERROR
;
718 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
719 pXAct
->hszItem
, TRUE
, pXAct
->wFmt
);
722 ERR("Couln'd find link for %p, dropping request\n", pXAct
->hszItem
);
723 FreeDDElParam(WM_DDE_UNADVISE
, pXAct
->lParam
);
724 return WDML_QS_ERROR
;
727 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
729 WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTOP
, pXAct
->wFmt
, (HCONV
)pConv
,
730 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
733 WDML_RemoveLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
734 pXAct
->hszItem
, pXAct
->wFmt
);
737 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, TRUE
, pXAct
->atom
,
738 pXAct
->lParam
, WM_DDE_UNADVISE
);
740 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
742 return WDML_QS_HANDLED
;
745 /******************************************************************
750 static WDML_XACT
* WDML_ServerQueueExecute(WDML_CONV
* pConv
, LPARAM lParam
)
754 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_EXECUTE
, 0, 0);
757 pXAct
->hMem
= (HGLOBAL
)lParam
;
762 /******************************************************************
763 * WDML_ServerHandleExecute
767 static WDML_QUEUE_STATE
WDML_ServerHandleExecute(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
769 HDDEDATA hDdeData
= DDE_FNOTPROCESSED
;
770 BOOL fAck
= FALSE
, fBusy
= FALSE
;
772 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_EXECUTES
))
774 LPVOID ptr
= GlobalLock(pXAct
->hMem
);
778 hDdeData
= DdeCreateDataHandle(0, ptr
, GlobalSize(pXAct
->hMem
),
780 GlobalUnlock(pXAct
->hMem
);
782 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_EXECUTE
, 0, (HCONV
)pConv
,
783 pConv
->hszTopic
, 0, hDdeData
, 0L, 0L);
786 switch ((ULONG_PTR
)hDdeData
)
788 case (ULONG_PTR
)CBR_BLOCK
:
789 return WDML_QS_BLOCK
;
798 FIXME("Unsupported returned value %p\n", hDdeData
);
800 case DDE_FNOTPROCESSED
:
803 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, (UINT_PTR
)pXAct
->hMem
, 0, 0);
805 return WDML_QS_HANDLED
;
808 /******************************************************************
809 * WDML_ServerQueuePoke
813 static WDML_XACT
* WDML_ServerQueuePoke(WDML_CONV
* pConv
, LPARAM lParam
)
818 UnpackDDElParam(WM_DDE_POKE
, lParam
, &uiLo
, &uiHi
);
820 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_POKE
,
821 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
825 pXAct
->hMem
= (HGLOBAL
)uiLo
;
830 /******************************************************************
831 * WDML_ServerHandlePoke
835 static WDML_QUEUE_STATE
WDML_ServerHandlePoke(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
839 BOOL fBusy
= FALSE
, fAck
= FALSE
;
841 pDdePoke
= (DDEPOKE
*)GlobalLock(pXAct
->hMem
);
844 return WDML_QS_ERROR
;
847 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_POKES
))
849 hDdeData
= DdeCreateDataHandle(pConv
->instance
->instanceID
, pDdePoke
->Value
,
850 GlobalSize(pXAct
->hMem
) - sizeof(DDEPOKE
) + 1,
851 0, 0, pDdePoke
->cfFormat
, 0);
854 HDDEDATA hDdeDataOut
;
856 hDdeDataOut
= WDML_InvokeCallback(pConv
->instance
, XTYP_POKE
, pDdePoke
->cfFormat
,
857 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
,
859 switch ((ULONG_PTR
)hDdeDataOut
)
868 FIXME("Unsupported returned value %p\n", hDdeDataOut
);
870 case DDE_FNOTPROCESSED
:
873 DdeFreeDataHandle(hDdeData
);
876 GlobalUnlock(pXAct
->hMem
);
880 GlobalFree(pXAct
->hMem
);
882 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_POKE
);
884 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
886 return WDML_QS_HANDLED
;
889 /******************************************************************
890 * WDML_ServerQueueTerminate
894 static WDML_XACT
* WDML_ServerQueueTerminate(WDML_CONV
* pConv
, LPARAM lParam
)
898 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_TERMINATE
, 0, 0);
902 /******************************************************************
903 * WDML_ServerHandleTerminate
907 static WDML_QUEUE_STATE
WDML_ServerHandleTerminate(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
909 /* billx: two things to remove: the conv, and associated links.
910 * Respond with another WM_DDE_TERMINATE iMsg.
912 if (!(pConv
->instance
->CBFflags
& CBF_SKIP_DISCONNECTS
))
914 WDML_InvokeCallback(pConv
->instance
, XTYP_DISCONNECT
, 0, (HCONV
)pConv
, 0, 0,
915 0, 0, (pConv
->wStatus
& ST_ISSELF
) ? 1 : 0);
917 PostMessageW(pConv
->hwndClient
, WM_DDE_TERMINATE
, (WPARAM
)pConv
->hwndServer
, 0);
918 WDML_RemoveConv(pConv
, WDML_SERVER_SIDE
);
920 return WDML_QS_HANDLED
;
923 /******************************************************************
928 WDML_QUEUE_STATE
WDML_ServerHandle(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
930 WDML_QUEUE_STATE qs
= WDML_QS_ERROR
;
932 switch (pXAct
->ddeMsg
)
934 case WM_DDE_INITIATE
:
935 FIXME("WM_DDE_INITIATE shouldn't be there!\n");
938 qs
= WDML_ServerHandleRequest(pConv
, pXAct
);
942 qs
= WDML_ServerHandleAdvise(pConv
, pXAct
);
945 case WM_DDE_UNADVISE
:
946 qs
= WDML_ServerHandleUnadvise(pConv
, pXAct
);
950 qs
= WDML_ServerHandleExecute(pConv
, pXAct
);
954 qs
= WDML_ServerHandlePoke(pConv
, pXAct
);
957 case WM_DDE_TERMINATE
:
958 qs
= WDML_ServerHandleTerminate(pConv
, pXAct
);
962 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
966 FIXME("Unsupported message %d\n", pXAct
->ddeMsg
);
971 /******************************************************************
972 * WDML_ServerConvProc
976 static LRESULT CALLBACK
WDML_ServerConvProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
978 WDML_INSTANCE
* pInstance
;
980 WDML_XACT
* pXAct
= NULL
;
982 TRACE("%p %04x %08lx %08lx\n", hwndServer
, iMsg
, wParam
, lParam
);
984 if (iMsg
== WM_DESTROY
)
986 pConv
= WDML_GetConvFromWnd(hwndServer
);
987 if (pConv
&& !(pConv
->wStatus
& ST_TERMINATED
))
989 WDML_ServerHandleTerminate(pConv
, NULL
);
992 if (iMsg
< WM_DDE_FIRST
|| iMsg
> WM_DDE_LAST
)
994 return IsWindowUnicode(hwndServer
) ? DefWindowProcW(hwndServer
, iMsg
, wParam
, lParam
) :
995 DefWindowProcA(hwndServer
, iMsg
, wParam
, lParam
);
998 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
999 pConv
= WDML_GetConvFromWnd(hwndServer
);
1003 ERR("Got a message (%x) on a not known conversation, dropping request\n", iMsg
);
1006 if (pConv
->hwndClient
!= WIN_GetFullHandle( (HWND
)wParam
) || pConv
->hwndServer
!= hwndServer
)
1008 ERR("mismatch between C/S windows and converstation\n");
1011 if (pConv
->instance
!= pInstance
|| pConv
->instance
== NULL
)
1013 ERR("mismatch in instances\n");
1019 case WM_DDE_INITIATE
:
1020 FIXME("WM_DDE_INITIATE message received!\n");
1023 case WM_DDE_REQUEST
:
1024 pXAct
= WDML_ServerQueueRequest(pConv
, lParam
);
1028 pXAct
= WDML_ServerQueueAdvise(pConv
, lParam
);
1031 case WM_DDE_UNADVISE
:
1032 pXAct
= WDML_ServerQueueUnadvise(pConv
, lParam
);
1035 case WM_DDE_EXECUTE
:
1036 pXAct
= WDML_ServerQueueExecute(pConv
, lParam
);
1040 pXAct
= WDML_ServerQueuePoke(pConv
, lParam
);
1043 case WM_DDE_TERMINATE
:
1044 pXAct
= WDML_ServerQueueTerminate(pConv
, lParam
);
1048 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
1052 FIXME("Unsupported message %x\n", iMsg
);
1058 pXAct
->lParam
= lParam
;
1060 if ((pConv
->wStatus
& ST_BLOCKED
) || WDML_ServerHandle(pConv
, pXAct
) == WDML_QS_BLOCK
)
1062 TRACE("Transactions are blocked, add to the queue and exit\n");
1063 WDML_QueueTransaction(pConv
, pXAct
);
1067 WDML_FreeTransaction(pInstance
, pXAct
, TRUE
);
1071 pConv
->instance
->lastError
= DMLERR_MEMORY_ERROR
;