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
== 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
;
169 WNDCLASSEXW wndclass
;
171 TRACE("(%d,%p,%p,%x)\n", idInst
, hsz1
, hsz2
, afCmd
);
173 /* First check instance
175 pInstance
= WDML_GetInstance(idInst
);
176 if (pInstance
== NULL
)
178 TRACE("Instance not found as initialised\n");
179 /* Nothing has been initialised - exit now ! can return TRUE since effect is the same */
185 /* Illegal, reserved parameter
187 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
188 WARN("Reserved parameter no-zero !!\n");
191 if (hsz1
== 0 && !(afCmd
& DNS_UNREGISTER
))
193 /* don't know if we should check this but it makes sense
194 * why supply REGISTER or filter flags if de-registering all
196 TRACE("General unregister unexpected flags\n");
197 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
201 switch (afCmd
& (DNS_REGISTER
| DNS_UNREGISTER
))
204 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
207 ERR("Trying to register already registered service!\n");
208 pInstance
->lastError
= DMLERR_DLL_USAGE
;
212 TRACE("Adding service name\n");
214 WDML_IncHSZ(pInstance
, hsz1
);
216 pServer
= WDML_AddServer(pInstance
, hsz1
, 0);
218 WDML_BroadcastDDEWindows(WDML_szEventClass
, WM_WDML_REGISTER
,
219 pServer
->atomService
, pServer
->atomServiceSpec
);
221 wndclass
.cbSize
= sizeof(wndclass
);
223 wndclass
.lpfnWndProc
= WDML_ServerNameProc
;
224 wndclass
.cbClsExtra
= 0;
225 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
226 wndclass
.hInstance
= 0;
228 wndclass
.hCursor
= 0;
229 wndclass
.hbrBackground
= 0;
230 wndclass
.lpszMenuName
= NULL
;
231 wndclass
.lpszClassName
= szServerNameClass
;
232 wndclass
.hIconSm
= 0;
234 RegisterClassExW(&wndclass
);
236 hwndServer
= CreateWindowW(szServerNameClass
, NULL
,
237 WS_POPUP
, 0, 0, 0, 0,
240 SetWindowLongPtrW(hwndServer
, GWL_WDML_INSTANCE
, (ULONG_PTR
)pInstance
);
241 SetWindowLongPtrW(hwndServer
, GWL_WDML_SERVER
, (ULONG_PTR
)pServer
);
242 TRACE("Created nameServer=%p for instance=%08x\n", hwndServer
, idInst
);
244 pServer
->hwndServer
= hwndServer
;
250 /* General unregister situation
251 * terminate all server side pending conversations
253 while (pInstance
->servers
)
254 WDML_RemoveServer(pInstance
, pInstance
->servers
->hszService
, 0);
255 pInstance
->servers
= NULL
;
256 TRACE("General de-register - finished\n");
260 WDML_RemoveServer(pInstance
, hsz1
, 0L);
265 if (afCmd
& (DNS_FILTERON
| DNS_FILTEROFF
))
267 /* Set filter flags on to hold notifications of connection
269 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
272 /* trying to filter where no service names !!
274 pInstance
->lastError
= DMLERR_DLL_USAGE
;
279 pServer
->filterOn
= (afCmd
& DNS_FILTERON
) != 0;
282 return (HDDEDATA
)TRUE
;
285 /******************************************************************
286 * WDML_CreateServerConv
290 static WDML_CONV
* WDML_CreateServerConv(WDML_INSTANCE
* pInstance
, HWND hwndClient
,
291 HWND hwndServerName
, HSZ hszApp
, HSZ hszTopic
)
296 if (pInstance
->unicode
)
298 WNDCLASSEXW wndclass
;
300 wndclass
.cbSize
= sizeof(wndclass
);
302 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
303 wndclass
.cbClsExtra
= 0;
304 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
305 wndclass
.hInstance
= 0;
307 wndclass
.hCursor
= 0;
308 wndclass
.hbrBackground
= 0;
309 wndclass
.lpszMenuName
= NULL
;
310 wndclass
.lpszClassName
= WDML_szServerConvClassW
;
311 wndclass
.hIconSm
= 0;
313 RegisterClassExW(&wndclass
);
315 hwndServerConv
= CreateWindowW(WDML_szServerConvClassW
, 0,
316 WS_CHILD
, 0, 0, 0, 0,
317 hwndServerName
, 0, 0, 0);
321 WNDCLASSEXA wndclass
;
323 wndclass
.cbSize
= sizeof(wndclass
);
325 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
326 wndclass
.cbClsExtra
= 0;
327 wndclass
.cbWndExtra
= 2 * sizeof(ULONG_PTR
);
328 wndclass
.hInstance
= 0;
330 wndclass
.hCursor
= 0;
331 wndclass
.hbrBackground
= 0;
332 wndclass
.lpszMenuName
= NULL
;
333 wndclass
.lpszClassName
= WDML_szServerConvClassA
;
334 wndclass
.hIconSm
= 0;
336 RegisterClassExA(&wndclass
);
338 hwndServerConv
= CreateWindowA(WDML_szServerConvClassA
, 0,
339 WS_CHILD
, 0, 0, 0, 0,
340 hwndServerName
, 0, 0, 0);
343 TRACE("Created convServer=%p (nameServer=%p) for instance=%08x unicode=%d\n",
344 hwndServerConv
, hwndServerName
, pInstance
->instanceID
, pInstance
->unicode
);
346 pConv
= WDML_AddConv(pInstance
, WDML_SERVER_SIDE
, hszApp
, hszTopic
,
347 hwndClient
, hwndServerConv
);
350 SetWindowLongPtrW(hwndServerConv
, GWL_WDML_INSTANCE
, (ULONG_PTR
)pInstance
);
351 SetWindowLongPtrW(hwndServerConv
, GWL_WDML_CONVERSATION
, (ULONG_PTR
)pConv
);
353 /* this should be the only place using SendMessage for WM_DDE_ACK */
354 /* note: sent messages shall not use packing */
355 SendMessageW(hwndClient
, WM_DDE_ACK
, (WPARAM
)hwndServerConv
,
356 MAKELPARAM(WDML_MakeAtomFromHsz(hszApp
), WDML_MakeAtomFromHsz(hszTopic
)));
357 /* we assume we're connected since we've sent an answer...
358 * I'm not sure what we can do... it doesn't look like the return value
359 * of SendMessage is used... sigh...
361 pConv
->wStatus
|= ST_CONNECTED
;
365 DestroyWindow(hwndServerConv
);
370 /******************************************************************
371 * WDML_ServerNameProc
375 static LRESULT CALLBACK
WDML_ServerNameProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
379 HDDEDATA hDdeData
= 0;
380 WDML_INSTANCE
* pInstance
;
385 case WM_DDE_INITIATE
:
387 /* wParam -- sending window handle
388 LOWORD(lParam) -- application atom
389 HIWORD(lParam) -- topic atom */
391 TRACE("WM_DDE_INITIATE message received!\n");
392 hwndClient
= (HWND
)wParam
;
394 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
395 TRACE("idInst=%d, threadID=0x%x\n", pInstance
->instanceID
, GetCurrentThreadId());
396 if (!pInstance
) return 0;
398 /* don't free DDEParams, since this is a broadcast */
399 UnpackDDElParam(WM_DDE_INITIATE
, lParam
, &uiLo
, &uiHi
);
401 hszApp
= WDML_MakeHszFromAtom(pInstance
, uiLo
);
402 hszTop
= WDML_MakeHszFromAtom(pInstance
, uiHi
);
404 if (!(pInstance
->CBFflags
& CBF_FAIL_CONNECTIONS
))
408 CONVCONTEXT
* pcc
= NULL
;
412 if (GetWindowThreadProcessId(hwndClient
, NULL
) == GetWindowThreadProcessId(hwndServer
, NULL
) &&
413 WDML_GetInstanceFromWnd(hwndClient
) == WDML_GetInstanceFromWnd(hwndServer
))
417 /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
418 * handled under DDEML, and if so build a default context
420 if ((GetClassNameA(hwndClient
, buf
, sizeof(buf
)) &&
421 lstrcmpiA(buf
, WDML_szClientConvClassA
) == 0) ||
422 (GetClassNameW(hwndClient
, (LPWSTR
)buf
, sizeof(buf
)/sizeof(WCHAR
)) &&
423 lstrcmpiW((LPWSTR
)buf
, WDML_szClientConvClassW
) == 0))
426 memset(pcc
, 0, sizeof(*pcc
));
427 pcc
->cb
= sizeof(*pcc
);
428 pcc
->iCodePage
= IsWindowUnicode(hwndClient
) ? CP_WINUNICODE
: CP_WINANSI
;
430 if ((pInstance
->CBFflags
& CBF_FAIL_SELFCONNECTIONS
) && self
)
432 TRACE("Don't do self connection as requested\n");
434 else if (hszApp
&& hszTop
)
436 WDML_SERVER
* pServer
= (WDML_SERVER
*)GetWindowLongPtrW(hwndServer
, GWL_WDML_SERVER
);
438 /* check filters for name service */
439 if (!pServer
->filterOn
|| DdeCmpStringHandles(pServer
->hszService
, hszApp
) == 0)
441 /* pass on to the callback */
442 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_CONNECT
,
443 0, 0, hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
444 if ((ULONG_PTR
)hDdeData
)
446 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
450 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
451 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
452 hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
457 else if (pInstance
->servers
)
459 /* pass on to the callback */
460 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_WILDCONNECT
,
461 0, 0, hszTop
, hszApp
, 0, (ULONG_PTR
)pcc
, self
);
463 if (hDdeData
== CBR_BLOCK
)
465 /* MS doc is not consistent here */
466 FIXME("CBR_BLOCK returned for WILDCONNECT\n");
468 else if ((ULONG_PTR
)hDdeData
!= 0)
472 hszp
= (HSZPAIR
*)DdeAccessData(hDdeData
, NULL
);
476 for (i
= 0; hszp
[i
].hszSvc
&& hszp
[i
].hszTopic
; i
++)
478 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
479 hszp
[i
].hszSvc
, hszp
[i
].hszTopic
);
482 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
483 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
484 hszp
[i
].hszTopic
, hszp
[i
].hszSvc
, 0, (ULONG_PTR
)pcc
, self
);
487 DdeUnaccessData(hDdeData
);
489 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
497 FIXME("WM_DDE_REQUEST message received!\n");
500 FIXME("WM_DDE_ADVISE message received!\n");
502 case WM_DDE_UNADVISE
:
503 FIXME("WM_DDE_UNADVISE message received!\n");
506 FIXME("WM_DDE_EXECUTE message received!\n");
509 FIXME("WM_DDE_POKE message received!\n");
511 case WM_DDE_TERMINATE
:
512 FIXME("WM_DDE_TERMINATE message received!\n");
518 return DefWindowProcW(hwndServer
, iMsg
, wParam
, lParam
);
521 /******************************************************************
522 * WDML_ServerQueueRequest
526 static WDML_XACT
* WDML_ServerQueueRequest(WDML_CONV
* pConv
, LPARAM lParam
)
531 UnpackDDElParam(WM_DDE_REQUEST
, lParam
, &uiLo
, &uiHi
);
533 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_REQUEST
,
534 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
535 if (pXAct
) pXAct
->atom
= uiHi
;
539 /******************************************************************
540 * WDML_ServerHandleRequest
544 static WDML_QUEUE_STATE
WDML_ServerHandleRequest(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
546 HDDEDATA hDdeData
= 0;
549 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_REQUESTS
))
552 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_REQUEST
, pXAct
->wFmt
, (HCONV
)pConv
,
553 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
556 switch ((ULONG_PTR
)hDdeData
)
559 TRACE("No data returned from the Callback\n");
563 case (ULONG_PTR
)CBR_BLOCK
:
564 return WDML_QS_BLOCK
;
568 HGLOBAL hMem
= WDML_DataHandle2Global(hDdeData
, TRUE
, FALSE
, FALSE
, FALSE
);
569 if (!PostMessageW(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
570 ReuseDDElParam(pXAct
->lParam
, WM_DDE_REQUEST
, WM_DDE_DATA
,
571 (UINT_PTR
)hMem
, (UINT_PTR
)pXAct
->atom
)))
573 pConv
->instance
->lastError
= DMLERR_POSTMSG_FAILED
;
574 DdeFreeDataHandle(hDdeData
);
582 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_REQUEST
);
584 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
586 return WDML_QS_HANDLED
;
589 /******************************************************************
590 * WDML_ServerQueueAdvise
594 static WDML_XACT
* WDML_ServerQueueAdvise(WDML_CONV
* pConv
, LPARAM lParam
)
599 /* XTYP_ADVSTART transaction:
600 establish link and save link info to InstanceInfoTable */
602 if (!UnpackDDElParam(WM_DDE_ADVISE
, lParam
, &uiLo
, &uiHi
))
605 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_ADVISE
,
606 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
609 pXAct
->hMem
= (HGLOBAL
)uiLo
;
615 /******************************************************************
616 * WDML_ServerHandleAdvise
620 static WDML_QUEUE_STATE
WDML_ServerHandleAdvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
624 DDEADVISE
* pDdeAdvise
;
625 HDDEDATA hDdeData
= 0;
628 pDdeAdvise
= (DDEADVISE
*)GlobalLock(pXAct
->hMem
);
629 uType
= XTYP_ADVSTART
|
630 (pDdeAdvise
->fDeferUpd
? XTYPF_NODATA
: 0) |
631 (pDdeAdvise
->fAckReq
? XTYPF_ACKREQ
: 0);
633 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
635 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTART
, pDdeAdvise
->cfFormat
,
636 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
639 switch ((ULONG_PTR
)hDdeData
)
642 TRACE("No data returned from the Callback\n");
646 case (ULONG_PTR
)CBR_BLOCK
:
647 return WDML_QS_BLOCK
;
650 /* billx: first to see if the link is already created. */
651 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
652 pXAct
->hszItem
, TRUE
, pDdeAdvise
->cfFormat
);
656 /* we found a link, and only need to modify it in case it changes */
657 pLink
->transactionType
= uType
;
661 TRACE("Adding Link with hConv %p\n", pConv
);
662 WDML_AddLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
663 uType
, pXAct
->hszItem
, pDdeAdvise
->cfFormat
);
668 GlobalUnlock(pXAct
->hMem
);
671 GlobalFree(pXAct
->hMem
);
675 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_ADVISE
);
677 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
679 return WDML_QS_HANDLED
;
682 /******************************************************************
683 * WDML_ServerQueueUnadvise
687 static WDML_XACT
* WDML_ServerQueueUnadvise(WDML_CONV
* pConv
, LPARAM lParam
)
692 UnpackDDElParam(WM_DDE_UNADVISE
, lParam
, &uiLo
, &uiHi
);
694 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_UNADVISE
,
695 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
696 if (pXAct
) pXAct
->atom
= uiHi
;
700 /******************************************************************
701 * WDML_ServerHandleUnadvise
705 static WDML_QUEUE_STATE
WDML_ServerHandleUnadvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
709 if (pXAct
->hszItem
== NULL
|| pXAct
->wFmt
== 0)
711 ERR("Unsupported yet options (null item or clipboard format)\n");
712 return WDML_QS_ERROR
;
715 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
716 pXAct
->hszItem
, TRUE
, pXAct
->wFmt
);
719 ERR("Couln'd find link for %p, dropping request\n", pXAct
->hszItem
);
720 FreeDDElParam(WM_DDE_UNADVISE
, pXAct
->lParam
);
721 return WDML_QS_ERROR
;
724 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
726 WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTOP
, pXAct
->wFmt
, (HCONV
)pConv
,
727 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
730 WDML_RemoveLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
731 pXAct
->hszItem
, pXAct
->wFmt
);
734 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, TRUE
, pXAct
->atom
,
735 pXAct
->lParam
, WM_DDE_UNADVISE
);
737 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
739 return WDML_QS_HANDLED
;
742 /******************************************************************
747 static WDML_XACT
* WDML_ServerQueueExecute(WDML_CONV
* pConv
, LPARAM lParam
)
751 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_EXECUTE
, 0, 0);
754 pXAct
->hMem
= (HGLOBAL
)lParam
;
759 /******************************************************************
760 * WDML_ServerHandleExecute
764 static WDML_QUEUE_STATE
WDML_ServerHandleExecute(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
766 HDDEDATA hDdeData
= DDE_FNOTPROCESSED
;
767 BOOL fAck
= FALSE
, fBusy
= FALSE
;
769 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_EXECUTES
))
771 LPVOID ptr
= GlobalLock(pXAct
->hMem
);
775 hDdeData
= DdeCreateDataHandle(0, ptr
, GlobalSize(pXAct
->hMem
),
777 GlobalUnlock(pXAct
->hMem
);
779 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_EXECUTE
, 0, (HCONV
)pConv
,
780 pConv
->hszTopic
, 0, hDdeData
, 0L, 0L);
783 switch ((ULONG_PTR
)hDdeData
)
785 case (ULONG_PTR
)CBR_BLOCK
:
786 return WDML_QS_BLOCK
;
795 FIXME("Unsupported returned value %p\n", hDdeData
);
797 case DDE_FNOTPROCESSED
:
800 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, (UINT_PTR
)pXAct
->hMem
, 0, 0);
802 return WDML_QS_HANDLED
;
805 /******************************************************************
806 * WDML_ServerQueuePoke
810 static WDML_XACT
* WDML_ServerQueuePoke(WDML_CONV
* pConv
, LPARAM lParam
)
815 UnpackDDElParam(WM_DDE_POKE
, lParam
, &uiLo
, &uiHi
);
817 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_POKE
,
818 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
822 pXAct
->hMem
= (HGLOBAL
)uiLo
;
827 /******************************************************************
828 * WDML_ServerHandlePoke
832 static WDML_QUEUE_STATE
WDML_ServerHandlePoke(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
836 BOOL fBusy
= FALSE
, fAck
= FALSE
;
838 pDdePoke
= (DDEPOKE
*)GlobalLock(pXAct
->hMem
);
841 return WDML_QS_ERROR
;
844 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_POKES
))
846 hDdeData
= DdeCreateDataHandle(pConv
->instance
->instanceID
, pDdePoke
->Value
,
847 GlobalSize(pXAct
->hMem
) - FIELD_OFFSET(DDEPOKE
, Value
),
848 0, 0, pDdePoke
->cfFormat
, 0);
851 HDDEDATA hDdeDataOut
;
853 hDdeDataOut
= WDML_InvokeCallback(pConv
->instance
, XTYP_POKE
, pDdePoke
->cfFormat
,
854 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
,
856 switch ((ULONG_PTR
)hDdeDataOut
)
865 FIXME("Unsupported returned value %p\n", hDdeDataOut
);
867 case DDE_FNOTPROCESSED
:
870 DdeFreeDataHandle(hDdeData
);
873 GlobalUnlock(pXAct
->hMem
);
877 GlobalFree(pXAct
->hMem
);
879 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_POKE
);
881 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
883 return WDML_QS_HANDLED
;
886 /******************************************************************
887 * WDML_ServerQueueTerminate
891 static WDML_XACT
* WDML_ServerQueueTerminate(WDML_CONV
* pConv
, LPARAM lParam
)
895 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_TERMINATE
, 0, 0);
899 /******************************************************************
900 * WDML_ServerHandleTerminate
904 static WDML_QUEUE_STATE
WDML_ServerHandleTerminate(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
906 /* billx: two things to remove: the conv, and associated links.
907 * Respond with another WM_DDE_TERMINATE iMsg.
909 if (!(pConv
->instance
->CBFflags
& CBF_SKIP_DISCONNECTS
))
911 WDML_InvokeCallback(pConv
->instance
, XTYP_DISCONNECT
, 0, (HCONV
)pConv
, 0, 0,
912 0, 0, (pConv
->wStatus
& ST_ISSELF
) ? 1 : 0);
914 PostMessageW(pConv
->hwndClient
, WM_DDE_TERMINATE
, (WPARAM
)pConv
->hwndServer
, 0);
915 WDML_RemoveConv(pConv
, WDML_SERVER_SIDE
);
917 return WDML_QS_HANDLED
;
920 /******************************************************************
925 WDML_QUEUE_STATE
WDML_ServerHandle(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
927 WDML_QUEUE_STATE qs
= WDML_QS_ERROR
;
929 switch (pXAct
->ddeMsg
)
931 case WM_DDE_INITIATE
:
932 FIXME("WM_DDE_INITIATE shouldn't be there!\n");
935 qs
= WDML_ServerHandleRequest(pConv
, pXAct
);
939 qs
= WDML_ServerHandleAdvise(pConv
, pXAct
);
942 case WM_DDE_UNADVISE
:
943 qs
= WDML_ServerHandleUnadvise(pConv
, pXAct
);
947 qs
= WDML_ServerHandleExecute(pConv
, pXAct
);
951 qs
= WDML_ServerHandlePoke(pConv
, pXAct
);
954 case WM_DDE_TERMINATE
:
955 qs
= WDML_ServerHandleTerminate(pConv
, pXAct
);
959 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
963 FIXME("Unsupported message %d\n", pXAct
->ddeMsg
);
968 /******************************************************************
969 * WDML_ServerConvProc
973 static LRESULT CALLBACK
WDML_ServerConvProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
975 WDML_INSTANCE
* pInstance
;
977 WDML_XACT
* pXAct
= NULL
;
979 TRACE("%p %04x %08lx %08lx\n", hwndServer
, iMsg
, wParam
, lParam
);
981 if (iMsg
== WM_DESTROY
)
983 pConv
= WDML_GetConvFromWnd(hwndServer
);
984 if (pConv
&& !(pConv
->wStatus
& ST_TERMINATED
))
986 WDML_ServerHandleTerminate(pConv
, NULL
);
989 if (iMsg
< WM_DDE_FIRST
|| iMsg
> WM_DDE_LAST
)
991 return IsWindowUnicode(hwndServer
) ? DefWindowProcW(hwndServer
, iMsg
, wParam
, lParam
) :
992 DefWindowProcA(hwndServer
, iMsg
, wParam
, lParam
);
995 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
996 pConv
= WDML_GetConvFromWnd(hwndServer
);
1000 ERR("Got a message (%x) on a not known conversation, dropping request\n", iMsg
);
1003 if (pConv
->hwndClient
!= WIN_GetFullHandle( (HWND
)wParam
) || pConv
->hwndServer
!= hwndServer
)
1005 ERR("mismatch between C/S windows and conversation\n");
1008 if (pConv
->instance
!= pInstance
|| pConv
->instance
== NULL
)
1010 ERR("mismatch in instances\n");
1016 case WM_DDE_INITIATE
:
1017 FIXME("WM_DDE_INITIATE message received!\n");
1020 case WM_DDE_REQUEST
:
1021 pXAct
= WDML_ServerQueueRequest(pConv
, lParam
);
1025 pXAct
= WDML_ServerQueueAdvise(pConv
, lParam
);
1028 case WM_DDE_UNADVISE
:
1029 pXAct
= WDML_ServerQueueUnadvise(pConv
, lParam
);
1032 case WM_DDE_EXECUTE
:
1033 pXAct
= WDML_ServerQueueExecute(pConv
, lParam
);
1037 pXAct
= WDML_ServerQueuePoke(pConv
, lParam
);
1040 case WM_DDE_TERMINATE
:
1041 pXAct
= WDML_ServerQueueTerminate(pConv
, lParam
);
1045 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
1049 FIXME("Unsupported message %x\n", iMsg
);
1055 pXAct
->lParam
= lParam
;
1057 if ((pConv
->wStatus
& ST_BLOCKED
) || WDML_ServerHandle(pConv
, pXAct
) == WDML_QS_BLOCK
)
1059 TRACE("Transactions are blocked, add to the queue and exit\n");
1060 WDML_QueueTransaction(pConv
, pXAct
);
1064 WDML_FreeTransaction(pInstance
, pXAct
, TRUE
);
1068 pConv
->instance
->lastError
= DMLERR_MEMORY_ERROR
;