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 EnterCriticalSection(&WDML_CritSect
);
74 pInstance
= WDML_GetInstance(idInst
);
76 if (pInstance
== NULL
|| pInstance
->links
== NULL
)
81 atom
= WDML_MakeAtomFromHsz(hszItem
);
82 if (!atom
) goto theError
;
84 /* first compute the number of links which will trigger a message */
86 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
88 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
93 if (count
>= CADV_LATEACK
)
95 FIXME("too high value for count\n");
99 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
101 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
103 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_ADVREQ
, pLink
->uFmt
, pLink
->hConv
,
104 hszTopic
, hszItem
, 0, --count
, 0);
106 if (hDdeData
== (HDDEDATA
)CBR_BLOCK
)
108 /* MS doc is not consistent here */
109 FIXME("CBR_BLOCK returned for ADVREQ\n");
114 if (pLink
->transactionType
& XTYPF_NODATA
)
121 TRACE("with data\n");
123 hItemData
= WDML_DataHandle2Global(hDdeData
, FALSE
, FALSE
, FALSE
, FALSE
);
126 pConv
= WDML_GetConv(pLink
->hConv
, TRUE
);
130 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
134 if (!PostMessageW(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
135 PackDDElParam(WM_DDE_DATA
, (UINT_PTR
)hItemData
, atom
)))
137 ERR("post message failed\n");
138 pConv
->wStatus
&= ~ST_CONNECTED
;
139 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
140 GlobalFree(hItemData
);
143 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
147 LeaveCriticalSection(&WDML_CritSect
);
150 LeaveCriticalSection(&WDML_CritSect
);
151 if (atom
) GlobalDeleteAtom(atom
);
156 /******************************************************************************
157 * DdeNameService [USER32.@] {Un}registers service name of DDE server
160 * idInst [I] Instance identifier
161 * hsz1 [I] Handle to service name string
163 * afCmd [I] Service name flags
169 HDDEDATA WINAPI
DdeNameService(DWORD idInst
, HSZ hsz1
, HSZ hsz2
, UINT afCmd
)
171 WDML_SERVER
* pServer
;
172 WDML_INSTANCE
* pInstance
;
175 WNDCLASSEXW wndclass
;
179 TRACE("(%d,%p,%p,%x)\n", idInst
, hsz1
, hsz2
, afCmd
);
181 EnterCriticalSection(&WDML_CritSect
);
183 /* First check instance
185 pInstance
= WDML_GetInstance(idInst
);
186 if (pInstance
== NULL
)
188 TRACE("Instance not found as initialised\n");
189 /* Nothing has been initialised - exit now ! can return TRUE since effect is the same */
195 /* Illegal, reserved parameter
197 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
198 WARN("Reserved parameter no-zero !!\n");
201 if (hsz1
== 0 && !(afCmd
& DNS_UNREGISTER
))
203 /* don't know if we should check this but it makes sense
204 * why supply REGISTER or filter flags if de-registering all
206 TRACE("General unregister unexpected flags\n");
207 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
211 switch (afCmd
& (DNS_REGISTER
| DNS_UNREGISTER
))
214 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
217 ERR("Trying to register already registered service!\n");
218 pInstance
->lastError
= DMLERR_DLL_USAGE
;
222 TRACE("Adding service name\n");
224 WDML_IncHSZ(pInstance
, hsz1
);
226 pServer
= WDML_AddServer(pInstance
, hsz1
, 0);
228 WDML_BroadcastDDEWindows(WDML_szEventClass
, WM_WDML_REGISTER
,
229 pServer
->atomService
, pServer
->atomServiceSpec
);
231 wndclass
.cbSize
= sizeof(wndclass
);
233 wndclass
.lpfnWndProc
= WDML_ServerNameProc
;
234 wndclass
.cbClsExtra
= 0;
235 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
236 wndclass
.hInstance
= 0;
238 wndclass
.hCursor
= 0;
239 wndclass
.hbrBackground
= 0;
240 wndclass
.lpszMenuName
= NULL
;
241 wndclass
.lpszClassName
= szServerNameClass
;
242 wndclass
.hIconSm
= 0;
244 RegisterClassExW(&wndclass
);
246 LeaveCriticalSection(&WDML_CritSect
);
247 hwndServer
= CreateWindowW(szServerNameClass
, NULL
,
248 WS_POPUP
, 0, 0, 0, 0,
250 EnterCriticalSection(&WDML_CritSect
);
252 SetWindowLongPtrW(hwndServer
, GWL_WDML_INSTANCE
, (ULONG_PTR
)pInstance
);
253 SetWindowLongPtrW(hwndServer
, GWL_WDML_SERVER
, (ULONG_PTR
)pServer
);
254 TRACE("Created nameServer=%p for instance=%08x\n", hwndServer
, idInst
);
256 pServer
->hwndServer
= hwndServer
;
262 /* General unregister situation
263 * terminate all server side pending conversations
265 while (pInstance
->servers
)
266 WDML_RemoveServer(pInstance
, pInstance
->servers
->hszService
, 0);
267 pInstance
->servers
= NULL
;
268 TRACE("General de-register - finished\n");
272 WDML_RemoveServer(pInstance
, hsz1
, 0L);
277 if (afCmd
& (DNS_FILTERON
| DNS_FILTEROFF
))
279 /* Set filter flags on to hold notifications of connection
281 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
284 /* trying to filter where no service names !!
286 pInstance
->lastError
= DMLERR_DLL_USAGE
;
291 pServer
->filterOn
= (afCmd
& DNS_FILTERON
) != 0;
294 LeaveCriticalSection(&WDML_CritSect
);
295 return (HDDEDATA
)TRUE
;
298 LeaveCriticalSection(&WDML_CritSect
);
302 /******************************************************************
303 * WDML_CreateServerConv
307 static WDML_CONV
* WDML_CreateServerConv(WDML_INSTANCE
* pInstance
, HWND hwndClient
,
308 HWND hwndServerName
, HSZ hszApp
, HSZ hszTopic
)
313 if (pInstance
->unicode
)
315 WNDCLASSEXW wndclass
;
317 wndclass
.cbSize
= sizeof(wndclass
);
319 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
320 wndclass
.cbClsExtra
= 0;
321 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
322 wndclass
.hInstance
= 0;
324 wndclass
.hCursor
= 0;
325 wndclass
.hbrBackground
= 0;
326 wndclass
.lpszMenuName
= NULL
;
327 wndclass
.lpszClassName
= WDML_szServerConvClassW
;
328 wndclass
.hIconSm
= 0;
330 RegisterClassExW(&wndclass
);
332 hwndServerConv
= CreateWindowW(WDML_szServerConvClassW
, 0,
333 WS_CHILD
, 0, 0, 0, 0,
334 hwndServerName
, 0, 0, 0);
338 WNDCLASSEXA wndclass
;
340 wndclass
.cbSize
= sizeof(wndclass
);
342 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
343 wndclass
.cbClsExtra
= 0;
344 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
345 wndclass
.hInstance
= 0;
347 wndclass
.hCursor
= 0;
348 wndclass
.hbrBackground
= 0;
349 wndclass
.lpszMenuName
= NULL
;
350 wndclass
.lpszClassName
= WDML_szServerConvClassA
;
351 wndclass
.hIconSm
= 0;
353 RegisterClassExA(&wndclass
);
355 hwndServerConv
= CreateWindowA(WDML_szServerConvClassA
, 0,
356 WS_CHILD
, 0, 0, 0, 0,
357 hwndServerName
, 0, 0, 0);
360 TRACE("Created convServer=%p (nameServer=%p) for instance=%08x\n",
361 hwndServerConv
, hwndServerName
, pInstance
->instanceID
);
363 pConv
= WDML_AddConv(pInstance
, WDML_SERVER_SIDE
, hszApp
, hszTopic
,
364 hwndClient
, hwndServerConv
);
367 SetWindowLongPtrW(hwndServerConv
, GWL_WDML_INSTANCE
, (ULONG_PTR
)pInstance
);
368 SetWindowLongPtrW(hwndServerConv
, GWL_WDML_CONVERSATION
, (ULONG_PTR
)pConv
);
370 /* this should be the only place using SendMessage for WM_DDE_ACK */
371 /* note: sent messages shall not use packing */
372 SendMessageW(hwndClient
, WM_DDE_ACK
, (WPARAM
)hwndServerConv
,
373 MAKELPARAM(WDML_MakeAtomFromHsz(hszApp
), WDML_MakeAtomFromHsz(hszTopic
)));
374 /* we assume we're connected since we've sent an answer...
375 * I'm not sure what we can do... it doesn't look like the return value
376 * of SendMessage is used... sigh...
378 pConv
->wStatus
|= ST_CONNECTED
;
382 DestroyWindow(hwndServerConv
);
387 /******************************************************************
388 * WDML_ServerNameProc
392 static LRESULT CALLBACK
WDML_ServerNameProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
396 HDDEDATA hDdeData
= 0;
397 WDML_INSTANCE
* pInstance
;
402 case WM_DDE_INITIATE
:
404 /* wParam -- sending window handle
405 LOWORD(lParam) -- application atom
406 HIWORD(lParam) -- topic atom */
408 TRACE("WM_DDE_INITIATE message received!\n");
409 hwndClient
= (HWND
)wParam
;
411 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
412 TRACE("idInst=%d, threadID=0x%x\n", pInstance
->instanceID
, GetCurrentThreadId());
413 if (!pInstance
) return 0;
415 /* don't free DDEParams, since this is a broadcast */
416 UnpackDDElParam(WM_DDE_INITIATE
, lParam
, &uiLo
, &uiHi
);
418 hszApp
= WDML_MakeHszFromAtom(pInstance
, uiLo
);
419 hszTop
= WDML_MakeHszFromAtom(pInstance
, uiHi
);
421 if (!(pInstance
->CBFflags
& CBF_FAIL_CONNECTIONS
))
425 CONVCONTEXT
* pcc
= NULL
;
429 if (GetWindowThreadProcessId(hwndClient
, NULL
) == GetWindowThreadProcessId(hwndServer
, NULL
) &&
430 WDML_GetInstanceFromWnd(hwndClient
) == WDML_GetInstanceFromWnd(hwndServer
))
434 /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
435 * handled under DDEML, and if so build a default context
437 if ((GetClassNameA(hwndClient
, buf
, sizeof(buf
)) &&
438 lstrcmpiA(buf
, WDML_szClientConvClassA
) == 0) ||
439 (GetClassNameW(hwndClient
, (LPWSTR
)buf
, sizeof(buf
)/sizeof(WCHAR
)) &&
440 lstrcmpiW((LPWSTR
)buf
, WDML_szClientConvClassW
) == 0))
443 memset(pcc
, 0, sizeof(*pcc
));
444 pcc
->cb
= sizeof(*pcc
);
445 pcc
->iCodePage
= IsWindowUnicode(hwndClient
) ? CP_WINUNICODE
: CP_WINANSI
;
447 if ((pInstance
->CBFflags
& CBF_FAIL_SELFCONNECTIONS
) && self
)
449 TRACE("Don't do self connection as requested\n");
451 else if (hszApp
&& hszTop
)
453 WDML_SERVER
* pServer
= (WDML_SERVER
*)GetWindowLongPtrW(hwndServer
, GWL_WDML_SERVER
);
455 /* check filters for name service */
456 if (!pServer
->filterOn
|| DdeCmpStringHandles(pServer
->hszService
, hszApp
) == 0)
458 /* pass on to the callback */
459 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_CONNECT
,
460 0, 0, hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
461 if ((ULONG_PTR
)hDdeData
)
463 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
467 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
468 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
469 hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
474 else if (pInstance
->servers
)
476 /* pass on to the callback */
477 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_WILDCONNECT
,
478 0, 0, hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
480 if (hDdeData
== (HDDEDATA
)CBR_BLOCK
)
482 /* MS doc is not consistent here */
483 FIXME("CBR_BLOCK returned for WILDCONNECT\n");
485 else if ((ULONG_PTR
)hDdeData
!= 0)
489 hszp
= (HSZPAIR
*)DdeAccessData(hDdeData
, NULL
);
493 for (i
= 0; hszp
[i
].hszSvc
&& hszp
[i
].hszTopic
; i
++)
495 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
496 hszp
[i
].hszSvc
, hszp
[i
].hszTopic
);
499 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
500 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
501 hszp
[i
].hszTopic
, hszp
[i
].hszSvc
, 0, (ULONG_PTR
)pcc
, self
);
504 DdeUnaccessData(hDdeData
);
506 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
514 FIXME("WM_DDE_REQUEST message received!\n");
517 FIXME("WM_DDE_ADVISE message received!\n");
519 case WM_DDE_UNADVISE
:
520 FIXME("WM_DDE_UNADVISE message received!\n");
523 FIXME("WM_DDE_EXECUTE message received!\n");
526 FIXME("WM_DDE_POKE message received!\n");
528 case WM_DDE_TERMINATE
:
529 FIXME("WM_DDE_TERMINATE message received!\n");
535 return DefWindowProcW(hwndServer
, iMsg
, wParam
, lParam
);
538 /******************************************************************
539 * WDML_ServerQueueRequest
543 static WDML_XACT
* WDML_ServerQueueRequest(WDML_CONV
* pConv
, LPARAM lParam
)
548 UnpackDDElParam(WM_DDE_REQUEST
, lParam
, &uiLo
, &uiHi
);
550 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_REQUEST
,
551 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
552 if (pXAct
) pXAct
->atom
= uiHi
;
556 /******************************************************************
557 * WDML_ServerHandleRequest
561 static WDML_QUEUE_STATE
WDML_ServerHandleRequest(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
563 HDDEDATA hDdeData
= 0;
566 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_REQUESTS
))
569 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_REQUEST
, pXAct
->wFmt
, (HCONV
)pConv
,
570 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
573 switch ((ULONG_PTR
)hDdeData
)
576 TRACE("No data returned from the Callback\n");
580 case (ULONG_PTR
)CBR_BLOCK
:
581 return WDML_QS_BLOCK
;
585 HGLOBAL hMem
= WDML_DataHandle2Global(hDdeData
, TRUE
, FALSE
, FALSE
, FALSE
);
586 if (!PostMessageW(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
587 ReuseDDElParam(pXAct
->lParam
, WM_DDE_REQUEST
, WM_DDE_DATA
,
588 (UINT_PTR
)hMem
, (UINT_PTR
)pXAct
->atom
)))
590 DdeFreeDataHandle(hDdeData
);
598 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_REQUEST
);
600 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
602 return WDML_QS_HANDLED
;
605 /******************************************************************
606 * WDML_ServerQueueAdvise
610 static WDML_XACT
* WDML_ServerQueueAdvise(WDML_CONV
* pConv
, LPARAM lParam
)
615 /* XTYP_ADVSTART transaction:
616 establish link and save link info to InstanceInfoTable */
618 if (!UnpackDDElParam(WM_DDE_ADVISE
, lParam
, &uiLo
, &uiHi
))
621 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_ADVISE
,
622 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
625 pXAct
->hMem
= (HGLOBAL
)uiLo
;
631 /******************************************************************
632 * WDML_ServerHandleAdvise
636 static WDML_QUEUE_STATE
WDML_ServerHandleAdvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
640 DDEADVISE
* pDdeAdvise
;
641 HDDEDATA hDdeData
= 0;
644 pDdeAdvise
= (DDEADVISE
*)GlobalLock(pXAct
->hMem
);
645 uType
= XTYP_ADVSTART
|
646 (pDdeAdvise
->fDeferUpd
? XTYPF_NODATA
: 0) |
647 (pDdeAdvise
->fAckReq
? XTYPF_ACKREQ
: 0);
649 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
651 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTART
, pDdeAdvise
->cfFormat
,
652 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
655 switch ((ULONG_PTR
)hDdeData
)
658 TRACE("No data returned from the Callback\n");
662 case (ULONG_PTR
)CBR_BLOCK
:
663 return WDML_QS_BLOCK
;
666 /* billx: first to see if the link is already created. */
667 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
668 pXAct
->hszItem
, TRUE
, pDdeAdvise
->cfFormat
);
672 /* we found a link, and only need to modify it in case it changes */
673 pLink
->transactionType
= uType
;
677 TRACE("Adding Link with hConv %p\n", pConv
);
678 WDML_AddLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
679 uType
, pXAct
->hszItem
, pDdeAdvise
->cfFormat
);
684 GlobalUnlock(pXAct
->hMem
);
687 GlobalFree(pXAct
->hMem
);
691 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_ADVISE
);
693 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
695 return WDML_QS_HANDLED
;
698 /******************************************************************
699 * WDML_ServerQueueUnadvise
703 static WDML_XACT
* WDML_ServerQueueUnadvise(WDML_CONV
* pConv
, LPARAM lParam
)
708 UnpackDDElParam(WM_DDE_UNADVISE
, lParam
, &uiLo
, &uiHi
);
710 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_UNADVISE
,
711 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
712 if (pXAct
) pXAct
->atom
= uiHi
;
716 /******************************************************************
717 * WDML_ServerHandleUnadvise
721 static WDML_QUEUE_STATE
WDML_ServerHandleUnadvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
725 if (pXAct
->hszItem
== NULL
|| pXAct
->wFmt
== 0)
727 ERR("Unsupported yet options (null item or clipboard format)\n");
728 return WDML_QS_ERROR
;
731 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
732 pXAct
->hszItem
, TRUE
, pXAct
->wFmt
);
735 ERR("Couln'd find link for %p, dropping request\n", pXAct
->hszItem
);
736 FreeDDElParam(WM_DDE_UNADVISE
, pXAct
->lParam
);
737 return WDML_QS_ERROR
;
740 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
742 WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTOP
, pXAct
->wFmt
, (HCONV
)pConv
,
743 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
746 WDML_RemoveLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
747 pXAct
->hszItem
, pXAct
->wFmt
);
750 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, TRUE
, pXAct
->atom
,
751 pXAct
->lParam
, WM_DDE_UNADVISE
);
753 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
755 return WDML_QS_HANDLED
;
758 /******************************************************************
763 static WDML_XACT
* WDML_ServerQueueExecute(WDML_CONV
* pConv
, LPARAM lParam
)
767 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_EXECUTE
, 0, 0);
770 pXAct
->hMem
= (HGLOBAL
)lParam
;
775 /******************************************************************
776 * WDML_ServerHandleExecute
780 static WDML_QUEUE_STATE
WDML_ServerHandleExecute(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
782 HDDEDATA hDdeData
= DDE_FNOTPROCESSED
;
783 BOOL fAck
= FALSE
, fBusy
= FALSE
;
785 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_EXECUTES
))
787 LPVOID ptr
= GlobalLock(pXAct
->hMem
);
791 hDdeData
= DdeCreateDataHandle(0, ptr
, GlobalSize(pXAct
->hMem
),
793 GlobalUnlock(pXAct
->hMem
);
795 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_EXECUTE
, 0, (HCONV
)pConv
,
796 pConv
->hszTopic
, 0, hDdeData
, 0L, 0L);
799 switch ((ULONG_PTR
)hDdeData
)
801 case (ULONG_PTR
)CBR_BLOCK
:
802 return WDML_QS_BLOCK
;
811 FIXME("Unsupported returned value %p\n", hDdeData
);
813 case DDE_FNOTPROCESSED
:
816 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, (UINT
)pXAct
->hMem
, 0, 0);
818 return WDML_QS_HANDLED
;
821 /******************************************************************
822 * WDML_ServerQueuePoke
826 static WDML_XACT
* WDML_ServerQueuePoke(WDML_CONV
* pConv
, LPARAM lParam
)
831 UnpackDDElParam(WM_DDE_POKE
, lParam
, &uiLo
, &uiHi
);
833 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_POKE
,
834 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
838 pXAct
->hMem
= (HGLOBAL
)uiLo
;
843 /******************************************************************
844 * WDML_ServerHandlePoke
848 static WDML_QUEUE_STATE
WDML_ServerHandlePoke(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
852 BOOL fBusy
= FALSE
, fAck
= FALSE
;
854 pDdePoke
= (DDEPOKE
*)GlobalLock(pXAct
->hMem
);
857 return WDML_QS_ERROR
;
860 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_POKES
))
862 hDdeData
= DdeCreateDataHandle(pConv
->instance
->instanceID
, pDdePoke
->Value
,
863 GlobalSize(pXAct
->hMem
) - sizeof(DDEPOKE
) + 1,
864 0, 0, pDdePoke
->cfFormat
, 0);
867 HDDEDATA hDdeDataOut
;
869 hDdeDataOut
= WDML_InvokeCallback(pConv
->instance
, XTYP_POKE
, pDdePoke
->cfFormat
,
870 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
,
872 switch ((ULONG_PTR
)hDdeDataOut
)
881 FIXME("Unsupported returned value %p\n", hDdeDataOut
);
883 case DDE_FNOTPROCESSED
:
886 DdeFreeDataHandle(hDdeData
);
889 GlobalUnlock(pXAct
->hMem
);
893 GlobalFree(pXAct
->hMem
);
895 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_POKE
);
897 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
899 return WDML_QS_HANDLED
;
902 /******************************************************************
903 * WDML_ServerQueueTerminate
907 static WDML_XACT
* WDML_ServerQueueTerminate(WDML_CONV
* pConv
, LPARAM lParam
)
911 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_TERMINATE
, 0, 0);
915 /******************************************************************
916 * WDML_ServerHandleTerminate
920 static WDML_QUEUE_STATE
WDML_ServerHandleTerminate(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
922 /* billx: two things to remove: the conv, and associated links.
923 * Respond with another WM_DDE_TERMINATE iMsg.
925 if (!(pConv
->instance
->CBFflags
& CBF_SKIP_DISCONNECTS
))
927 WDML_InvokeCallback(pConv
->instance
, XTYP_DISCONNECT
, 0, (HCONV
)pConv
, 0, 0,
928 0, 0, (pConv
->wStatus
& ST_ISSELF
) ? 1 : 0);
930 PostMessageW(pConv
->hwndClient
, WM_DDE_TERMINATE
, (WPARAM
)pConv
->hwndServer
, 0);
931 WDML_RemoveConv(pConv
, WDML_SERVER_SIDE
);
933 return WDML_QS_HANDLED
;
936 /******************************************************************
941 WDML_QUEUE_STATE
WDML_ServerHandle(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
943 WDML_QUEUE_STATE qs
= WDML_QS_ERROR
;
945 switch (pXAct
->ddeMsg
)
947 case WM_DDE_INITIATE
:
948 FIXME("WM_DDE_INITIATE shouldn't be there!\n");
951 qs
= WDML_ServerHandleRequest(pConv
, pXAct
);
955 qs
= WDML_ServerHandleAdvise(pConv
, pXAct
);
958 case WM_DDE_UNADVISE
:
959 qs
= WDML_ServerHandleUnadvise(pConv
, pXAct
);
963 qs
= WDML_ServerHandleExecute(pConv
, pXAct
);
967 qs
= WDML_ServerHandlePoke(pConv
, pXAct
);
970 case WM_DDE_TERMINATE
:
971 qs
= WDML_ServerHandleTerminate(pConv
, pXAct
);
975 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
979 FIXME("Unsupported message %d\n", pXAct
->ddeMsg
);
984 /******************************************************************
985 * WDML_ServerConvProc
989 static LRESULT CALLBACK
WDML_ServerConvProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
991 WDML_INSTANCE
* pInstance
;
993 WDML_XACT
* pXAct
= NULL
;
995 TRACE("%p %04x %08x %08lx\n", hwndServer
, iMsg
, wParam
, lParam
);
997 if (iMsg
== WM_DESTROY
)
999 EnterCriticalSection(&WDML_CritSect
);
1000 pConv
= WDML_GetConvFromWnd(hwndServer
);
1001 if (pConv
&& !(pConv
->wStatus
& ST_TERMINATED
))
1003 WDML_ServerHandleTerminate(pConv
, NULL
);
1005 LeaveCriticalSection(&WDML_CritSect
);
1007 if (iMsg
< WM_DDE_FIRST
|| iMsg
> WM_DDE_LAST
)
1009 return IsWindowUnicode(hwndServer
) ? DefWindowProcW(hwndServer
, iMsg
, wParam
, lParam
) :
1010 DefWindowProcA(hwndServer
, iMsg
, wParam
, lParam
);
1013 EnterCriticalSection(&WDML_CritSect
);
1015 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
1016 pConv
= WDML_GetConvFromWnd(hwndServer
);
1020 ERR("Got a message (%x) on a not known conversation, dropping request\n", iMsg
);
1023 if (pConv
->hwndClient
!= WIN_GetFullHandle( (HWND
)wParam
) || pConv
->hwndServer
!= hwndServer
)
1025 ERR("mismatch between C/S windows and converstation\n");
1028 if (pConv
->instance
!= pInstance
|| pConv
->instance
== NULL
)
1030 ERR("mismatch in instances\n");
1036 case WM_DDE_INITIATE
:
1037 FIXME("WM_DDE_INITIATE message received!\n");
1040 case WM_DDE_REQUEST
:
1041 pXAct
= WDML_ServerQueueRequest(pConv
, lParam
);
1045 pXAct
= WDML_ServerQueueAdvise(pConv
, lParam
);
1048 case WM_DDE_UNADVISE
:
1049 pXAct
= WDML_ServerQueueUnadvise(pConv
, lParam
);
1052 case WM_DDE_EXECUTE
:
1053 pXAct
= WDML_ServerQueueExecute(pConv
, lParam
);
1057 pXAct
= WDML_ServerQueuePoke(pConv
, lParam
);
1060 case WM_DDE_TERMINATE
:
1061 pXAct
= WDML_ServerQueueTerminate(pConv
, lParam
);
1065 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
1069 FIXME("Unsupported message %x\n", iMsg
);
1074 pXAct
->lParam
= lParam
;
1075 if (WDML_ServerHandle(pConv
, pXAct
) == WDML_QS_BLOCK
)
1077 WDML_QueueTransaction(pConv
, pXAct
);
1081 WDML_FreeTransaction(pInstance
, pXAct
, TRUE
);
1085 LeaveCriticalSection(&WDML_CritSect
);