1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1997 Alexandre Julliard
7 * Copyright 1997 Len White
8 * Copyright 1999 Keith Matthews
10 * Copyright 2001 Eric Pouech
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 #include "wine/debug.h"
38 #include "dde/dde_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ddeml
);
42 static const char szServerNameClassA
[] = "DdeServerNameAnsi";
43 const char WDML_szServerConvClassA
[] = "DdeServerConvAnsi";
44 const WCHAR WDML_szServerConvClassW
[] = {'D','d','e','S','e','r','v','e','r','C','o','n','v','U','n','i','c','o','d','e',0};
46 static LRESULT CALLBACK
WDML_ServerNameProc(HWND
, UINT
, WPARAM
, LPARAM
);
47 static LRESULT CALLBACK
WDML_ServerConvProc(HWND
, UINT
, WPARAM
, LPARAM
);
49 /******************************************************************************
50 * DdePostAdvise [USER32.@] Send transaction to DDE callback function.
53 * idInst [I] Instance identifier
54 * hszTopic [I] Handle to topic name string
55 * hszItem [I] Handle to item name string
61 BOOL WINAPI
DdePostAdvise(DWORD idInst
, HSZ hszTopic
, HSZ hszItem
)
63 WDML_INSTANCE
* pInstance
= NULL
;
64 WDML_LINK
* pLink
= NULL
;
65 HDDEDATA hDdeData
= 0;
66 HGLOBAL hItemData
= 0;
67 WDML_CONV
* pConv
= NULL
;
71 TRACE("(%ld,%p,%p)\n", idInst
, hszTopic
, hszItem
);
73 EnterCriticalSection(&WDML_CritSect
);
75 pInstance
= WDML_GetInstance(idInst
);
77 if (pInstance
== NULL
|| pInstance
->links
== NULL
)
82 atom
= WDML_MakeAtomFromHsz(hszItem
);
83 if (!atom
) goto theError
;
85 /* first compute the number of links which will trigger a message */
87 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
89 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
94 if (count
>= CADV_LATEACK
)
96 FIXME("too high value for count\n");
100 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
102 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
104 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_ADVREQ
, pLink
->uFmt
, pLink
->hConv
,
105 hszTopic
, hszItem
, 0, --count
, 0);
107 if (hDdeData
== (HDDEDATA
)CBR_BLOCK
)
109 /* MS doc is not consistent here */
110 FIXME("CBR_BLOCK returned for ADVREQ\n");
115 if (pLink
->transactionType
& XTYPF_NODATA
)
122 TRACE("with data\n");
124 hItemData
= WDML_DataHandle2Global(hDdeData
, FALSE
, FALSE
, FALSE
, FALSE
);
127 pConv
= WDML_GetConv(pLink
->hConv
, TRUE
);
131 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
135 if (!PostMessageA(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
136 PackDDElParam(WM_DDE_DATA
, (UINT_PTR
)hItemData
, atom
)))
138 ERR("post message failed\n");
139 pConv
->wStatus
&= ~ST_CONNECTED
;
140 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
141 GlobalFree(hItemData
);
144 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
148 LeaveCriticalSection(&WDML_CritSect
);
151 LeaveCriticalSection(&WDML_CritSect
);
152 if (atom
) GlobalDeleteAtom(atom
);
157 /******************************************************************************
158 * DdeNameService [USER32.@] {Un}registers service name of DDE server
161 * idInst [I] Instance identifier
162 * hsz1 [I] Handle to service name string
164 * afCmd [I] Service name flags
170 HDDEDATA WINAPI
DdeNameService(DWORD idInst
, HSZ hsz1
, HSZ hsz2
, UINT afCmd
)
172 WDML_SERVER
* pServer
;
173 WDML_INSTANCE
* pInstance
;
176 WNDCLASSEXA wndclass
;
180 TRACE("(%ld,%p,%p,%x)\n", idInst
, hsz1
, hsz2
, afCmd
);
182 EnterCriticalSection(&WDML_CritSect
);
184 /* First check instance
186 pInstance
= WDML_GetInstance(idInst
);
187 if (pInstance
== NULL
)
189 TRACE("Instance not found as initialised\n");
190 /* Nothing has been initialised - exit now ! can return TRUE since effect is the same */
196 /* Illegal, reserved parameter
198 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
199 WARN("Reserved parameter no-zero !!\n");
202 if (hsz1
== 0 && !(afCmd
& DNS_UNREGISTER
))
204 /* don't know if we should check this but it makes sense
205 * why supply REGISTER or filter flags if de-registering all
207 TRACE("General unregister unexpected flags\n");
208 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
212 switch (afCmd
& (DNS_REGISTER
| DNS_UNREGISTER
))
215 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
218 ERR("Trying to register already registered service!\n");
219 pInstance
->lastError
= DMLERR_DLL_USAGE
;
223 TRACE("Adding service name\n");
225 WDML_IncHSZ(pInstance
, hsz1
);
227 pServer
= WDML_AddServer(pInstance
, hsz1
, 0);
229 WDML_BroadcastDDEWindows(WDML_szEventClass
, WM_WDML_REGISTER
,
230 pServer
->atomService
, pServer
->atomServiceSpec
);
232 wndclass
.cbSize
= sizeof(wndclass
);
234 wndclass
.lpfnWndProc
= WDML_ServerNameProc
;
235 wndclass
.cbClsExtra
= 0;
236 wndclass
.cbWndExtra
= 2 * sizeof(DWORD
);
237 wndclass
.hInstance
= 0;
239 wndclass
.hCursor
= 0;
240 wndclass
.hbrBackground
= 0;
241 wndclass
.lpszMenuName
= NULL
;
242 wndclass
.lpszClassName
= szServerNameClassA
;
243 wndclass
.hIconSm
= 0;
245 RegisterClassExA(&wndclass
);
247 LeaveCriticalSection(&WDML_CritSect
);
248 hwndServer
= CreateWindowA(szServerNameClassA
, NULL
,
249 WS_POPUP
, 0, 0, 0, 0,
251 EnterCriticalSection(&WDML_CritSect
);
253 SetWindowLongA(hwndServer
, GWL_WDML_INSTANCE
, (DWORD
)pInstance
);
254 SetWindowLongA(hwndServer
, GWL_WDML_SERVER
, (DWORD
)pServer
);
255 TRACE("Created nameServer=%p for instance=%08lx\n", hwndServer
, idInst
);
257 pServer
->hwndServer
= hwndServer
;
263 /* General unregister situation
264 * terminate all server side pending conversations
266 while (pInstance
->servers
)
267 WDML_RemoveServer(pInstance
, pInstance
->servers
->hszService
, 0);
268 pInstance
->servers
= NULL
;
269 TRACE("General de-register - finished\n");
273 WDML_RemoveServer(pInstance
, hsz1
, 0L);
278 if (afCmd
& (DNS_FILTERON
| DNS_FILTEROFF
))
280 /* Set filter flags on to hold notifications of connection
282 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
285 /* trying to filter where no service names !!
287 pInstance
->lastError
= DMLERR_DLL_USAGE
;
292 pServer
->filterOn
= (afCmd
& DNS_FILTERON
) != 0;
295 LeaveCriticalSection(&WDML_CritSect
);
296 return (HDDEDATA
)TRUE
;
299 LeaveCriticalSection(&WDML_CritSect
);
303 /******************************************************************
304 * WDML_CreateServerConv
308 static WDML_CONV
* WDML_CreateServerConv(WDML_INSTANCE
* pInstance
, HWND hwndClient
,
309 HWND hwndServerName
, HSZ hszApp
, HSZ hszTopic
)
314 if (pInstance
->unicode
)
316 WNDCLASSEXW wndclass
;
318 wndclass
.cbSize
= sizeof(wndclass
);
320 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
321 wndclass
.cbClsExtra
= 0;
322 wndclass
.cbWndExtra
= 2 * sizeof(DWORD
);
323 wndclass
.hInstance
= 0;
325 wndclass
.hCursor
= 0;
326 wndclass
.hbrBackground
= 0;
327 wndclass
.lpszMenuName
= NULL
;
328 wndclass
.lpszClassName
= WDML_szServerConvClassW
;
329 wndclass
.hIconSm
= 0;
331 RegisterClassExW(&wndclass
);
333 hwndServerConv
= CreateWindowW(WDML_szServerConvClassW
, 0,
334 WS_CHILD
, 0, 0, 0, 0,
335 hwndServerName
, 0, 0, 0);
339 WNDCLASSEXA wndclass
;
341 wndclass
.cbSize
= sizeof(wndclass
);
343 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
344 wndclass
.cbClsExtra
= 0;
345 wndclass
.cbWndExtra
= 2 * sizeof(DWORD
);
346 wndclass
.hInstance
= 0;
348 wndclass
.hCursor
= 0;
349 wndclass
.hbrBackground
= 0;
350 wndclass
.lpszMenuName
= NULL
;
351 wndclass
.lpszClassName
= WDML_szServerConvClassA
;
352 wndclass
.hIconSm
= 0;
354 RegisterClassExA(&wndclass
);
356 hwndServerConv
= CreateWindowA(WDML_szServerConvClassA
, 0,
357 WS_CHILD
, 0, 0, 0, 0,
358 hwndServerName
, 0, 0, 0);
361 TRACE("Created convServer=%p (nameServer=%p) for instance=%08lx\n",
362 hwndServerConv
, hwndServerName
, pInstance
->instanceID
);
364 pConv
= WDML_AddConv(pInstance
, WDML_SERVER_SIDE
, hszApp
, hszTopic
,
365 hwndClient
, hwndServerConv
);
368 SetWindowLongA(hwndServerConv
, GWL_WDML_INSTANCE
, (DWORD
)pInstance
);
369 SetWindowLongA(hwndServerConv
, GWL_WDML_CONVERSATION
, (DWORD
)pConv
);
371 /* this should be the only place using SendMessage for WM_DDE_ACK */
372 /* note: sent messages shall not use packing */
373 SendMessageA(hwndClient
, WM_DDE_ACK
, (WPARAM
)hwndServerConv
,
374 MAKELPARAM(WDML_MakeAtomFromHsz(hszApp
), WDML_MakeAtomFromHsz(hszTopic
)));
375 /* we assume we're connected since we've sent an answer...
376 * I'm not sure what we can do... it doesn't look like the return value
377 * of SendMessage is used... sigh...
379 pConv
->wStatus
|= ST_CONNECTED
;
383 DestroyWindow(hwndServerConv
);
388 /******************************************************************
389 * WDML_ServerNameProc
393 static LRESULT CALLBACK
WDML_ServerNameProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
397 HDDEDATA hDdeData
= 0;
398 WDML_INSTANCE
* pInstance
;
403 case WM_DDE_INITIATE
:
405 /* wParam -- sending window handle
406 LOWORD(lParam) -- application atom
407 HIWORD(lParam) -- topic atom */
409 TRACE("WM_DDE_INITIATE message received!\n");
410 hwndClient
= (HWND
)wParam
;
412 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
413 TRACE("idInst=%ld, threadID=0x%lx\n", pInstance
->instanceID
, GetCurrentThreadId());
414 if (!pInstance
) return 0;
416 /* don't free DDEParams, since this is a broadcast */
417 UnpackDDElParam(WM_DDE_INITIATE
, lParam
, &uiLo
, &uiHi
);
419 hszApp
= WDML_MakeHszFromAtom(pInstance
, uiLo
);
420 hszTop
= WDML_MakeHszFromAtom(pInstance
, uiHi
);
422 if (!(pInstance
->CBFflags
& CBF_FAIL_CONNECTIONS
))
426 CONVCONTEXT
* pcc
= NULL
;
430 if (GetWindowThreadProcessId(hwndClient
, NULL
) == GetWindowThreadProcessId(hwndServer
, NULL
) &&
431 WDML_GetInstanceFromWnd(hwndClient
) == WDML_GetInstanceFromWnd(hwndServer
))
435 /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
436 * handled under DDEML, and if so build a default context
438 if ((GetClassNameA(hwndClient
, buf
, sizeof(buf
)) &&
439 strcmp(buf
, WDML_szClientConvClassA
) == 0) ||
440 (GetClassNameW(hwndClient
, (LPWSTR
)buf
, sizeof(buf
)/sizeof(WCHAR
)) &&
441 lstrcmpW((LPWSTR
)buf
, WDML_szClientConvClassW
) == 0))
444 memset(pcc
, 0, sizeof(*pcc
));
445 pcc
->cb
= sizeof(*pcc
);
446 pcc
->iCodePage
= IsWindowUnicode(hwndClient
) ? CP_WINUNICODE
: CP_WINANSI
;
448 if ((pInstance
->CBFflags
& CBF_FAIL_SELFCONNECTIONS
) && self
)
450 TRACE("Don't do self connection as requested\n");
452 else if (hszApp
&& hszTop
)
454 WDML_SERVER
* pServer
= (WDML_SERVER
*)GetWindowLongA(hwndServer
, GWL_WDML_SERVER
);
456 /* check filters for name service */
457 if (!pServer
->filterOn
|| DdeCmpStringHandles(pServer
->hszService
, hszApp
) == 0)
459 /* pass on to the callback */
460 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_CONNECT
,
461 0, 0, hszTop
, hszApp
, 0, (DWORD
)pcc
, self
);
464 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
468 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
469 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
470 hszTop
, hszApp
, 0, (DWORD
)pcc
, self
);
475 else if (pInstance
->servers
)
477 /* pass on to the callback */
478 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_WILDCONNECT
,
479 0, 0, hszTop
, hszApp
, 0, (DWORD
)pcc
, self
);
481 if (hDdeData
== (HDDEDATA
)CBR_BLOCK
)
483 /* MS doc is not consistent here */
484 FIXME("CBR_BLOCK returned for WILDCONNECT\n");
486 else if ((UINT
)hDdeData
!= 0)
490 hszp
= (HSZPAIR
*)DdeAccessData(hDdeData
, NULL
);
494 for (i
= 0; hszp
[i
].hszSvc
&& hszp
[i
].hszTopic
; i
++)
496 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
497 hszp
[i
].hszSvc
, hszp
[i
].hszTopic
);
500 if (pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
501 WDML_InvokeCallback(pInstance
, XTYP_CONNECT_CONFIRM
, 0, (HCONV
)pConv
,
502 hszp
[i
].hszTopic
, hszp
[i
].hszSvc
, 0, (DWORD
)pcc
, self
);
505 DdeUnaccessData(hDdeData
);
507 if (!WDML_IsAppOwned(hDdeData
)) DdeFreeDataHandle(hDdeData
);
516 FIXME("WM_DDE_REQUEST message received!\n");
519 FIXME("WM_DDE_ADVISE message received!\n");
521 case WM_DDE_UNADVISE
:
522 FIXME("WM_DDE_UNADVISE message received!\n");
525 FIXME("WM_DDE_EXECUTE message received!\n");
528 FIXME("WM_DDE_POKE message received!\n");
530 case WM_DDE_TERMINATE
:
531 FIXME("WM_DDE_TERMINATE message received!\n");
536 return DefWindowProcA(hwndServer
, iMsg
, wParam
, lParam
);
539 /******************************************************************
540 * WDML_ServerQueueRequest
544 static WDML_XACT
* WDML_ServerQueueRequest(WDML_CONV
* pConv
, LPARAM lParam
)
549 UnpackDDElParam(WM_DDE_REQUEST
, lParam
, &uiLo
, &uiHi
);
551 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_REQUEST
,
552 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
553 if (pXAct
) pXAct
->atom
= uiHi
;
557 /******************************************************************
558 * WDML_ServerHandleRequest
562 static WDML_QUEUE_STATE
WDML_ServerHandleRequest(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
564 HDDEDATA hDdeData
= 0;
565 WDML_QUEUE_STATE ret
= WDML_QS_HANDLED
;
567 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_REQUESTS
))
570 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_REQUEST
, pXAct
->wFmt
, (HCONV
)pConv
,
571 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
574 switch ((ULONG_PTR
)hDdeData
)
577 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, FALSE
, pXAct
->atom
,
578 pXAct
->lParam
, WM_DDE_REQUEST
);
585 HGLOBAL hMem
= WDML_DataHandle2Global(hDdeData
, TRUE
, FALSE
, FALSE
, FALSE
);
586 if (!PostMessageA(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
);
596 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
600 /******************************************************************
601 * WDML_ServerQueueAdvise
605 static WDML_XACT
* WDML_ServerQueueAdvise(WDML_CONV
* pConv
, LPARAM lParam
)
610 /* XTYP_ADVSTART transaction:
611 establish link and save link info to InstanceInfoTable */
613 if (!UnpackDDElParam(WM_DDE_ADVISE
, lParam
, &uiLo
, &uiHi
))
616 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_ADVISE
,
617 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
620 pXAct
->hMem
= (HGLOBAL
)uiLo
;
626 /******************************************************************
627 * WDML_ServerHandleAdvise
631 static WDML_QUEUE_STATE
WDML_ServerHandleAdvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
635 DDEADVISE
* pDdeAdvise
;
639 pDdeAdvise
= (DDEADVISE
*)GlobalLock(pXAct
->hMem
);
640 uType
= XTYP_ADVSTART
|
641 (pDdeAdvise
->fDeferUpd
? XTYPF_NODATA
: 0) |
642 (pDdeAdvise
->fAckReq
? XTYPF_ACKREQ
: 0);
644 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
646 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTART
, pDdeAdvise
->cfFormat
,
647 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
658 /* billx: first to see if the link is already created. */
659 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
660 pXAct
->hszItem
, TRUE
, pDdeAdvise
->cfFormat
);
664 /* we found a link, and only need to modify it in case it changes */
665 pLink
->transactionType
= uType
;
669 TRACE("Adding Link with hConv %p\n", pConv
);
670 WDML_AddLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
671 uType
, pXAct
->hszItem
, pDdeAdvise
->cfFormat
);
676 TRACE("No data returned from the Callback\n");
680 GlobalUnlock(pXAct
->hMem
);
683 GlobalFree(pXAct
->hMem
);
687 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_ADVISE
);
689 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
691 return WDML_QS_HANDLED
;
694 /******************************************************************
695 * WDML_ServerQueueUnadvise
699 static WDML_XACT
* WDML_ServerQueueUnadvise(WDML_CONV
* pConv
, LPARAM lParam
)
704 UnpackDDElParam(WM_DDE_UNADVISE
, lParam
, &uiLo
, &uiHi
);
706 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_UNADVISE
,
707 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
708 if (pXAct
) pXAct
->atom
= uiHi
;
712 /******************************************************************
713 * WDML_ServerHandleUnadvise
717 static WDML_QUEUE_STATE
WDML_ServerHandleUnadvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
721 if (pXAct
->hszItem
== NULL
|| pXAct
->wFmt
== 0)
723 ERR("Unsupported yet options (null item or clipboard format)\n");
724 return WDML_QS_ERROR
;
727 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
728 pXAct
->hszItem
, TRUE
, pXAct
->wFmt
);
731 ERR("Couln'd find link for %p, dropping request\n", pXAct
->hszItem
);
732 FreeDDElParam(WM_DDE_UNADVISE
, pXAct
->lParam
);
733 return WDML_QS_ERROR
;
736 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
738 WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTOP
, pXAct
->wFmt
, (HCONV
)pConv
,
739 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
742 WDML_RemoveLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
743 pXAct
->hszItem
, pXAct
->wFmt
);
746 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, TRUE
, pXAct
->atom
,
747 pXAct
->lParam
, WM_DDE_UNADVISE
);
749 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
751 return WDML_QS_HANDLED
;
754 /******************************************************************
759 static WDML_XACT
* WDML_ServerQueueExecute(WDML_CONV
* pConv
, LPARAM lParam
)
763 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_EXECUTE
, 0, 0);
766 pXAct
->hMem
= (HGLOBAL
)lParam
;
771 /******************************************************************
772 * WDML_ServerHandleExecute
776 static WDML_QUEUE_STATE
WDML_ServerHandleExecute(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
778 HDDEDATA hDdeData
= DDE_FNOTPROCESSED
;
779 BOOL fAck
= FALSE
, fBusy
= FALSE
;
781 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_EXECUTES
))
783 LPVOID ptr
= GlobalLock(pXAct
->hMem
);
787 hDdeData
= DdeCreateDataHandle(0, ptr
, GlobalSize(pXAct
->hMem
),
789 GlobalUnlock(pXAct
->hMem
);
791 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_EXECUTE
, 0, (HCONV
)pConv
,
792 pConv
->hszTopic
, 0, hDdeData
, 0L, 0L);
795 switch ((UINT
)hDdeData
)
804 WARN("Bad result code\n");
806 case DDE_FNOTPROCESSED
:
809 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, (UINT
)pXAct
->hMem
, 0, 0);
811 return WDML_QS_HANDLED
;
814 /******************************************************************
815 * WDML_ServerQueuePoke
819 static WDML_XACT
* WDML_ServerQueuePoke(WDML_CONV
* pConv
, LPARAM lParam
)
824 UnpackDDElParam(WM_DDE_POKE
, lParam
, &uiLo
, &uiHi
);
826 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_POKE
,
827 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
831 pXAct
->hMem
= (HGLOBAL
)uiLo
;
836 /******************************************************************
837 * WDML_ServerHandlePoke
841 static WDML_QUEUE_STATE
WDML_ServerHandlePoke(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
845 BOOL fBusy
= FALSE
, fAck
= FALSE
;
847 pDdePoke
= (DDEPOKE
*)GlobalLock(pXAct
->hMem
);
850 return WDML_QS_ERROR
;
853 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_POKES
))
855 hDdeData
= DdeCreateDataHandle(pConv
->instance
->instanceID
, pDdePoke
->Value
,
856 GlobalSize(pXAct
->hMem
) - sizeof(DDEPOKE
) + 1,
857 0, 0, pDdePoke
->cfFormat
, 0);
860 HDDEDATA hDdeDataOut
;
862 hDdeDataOut
= WDML_InvokeCallback(pConv
->instance
, XTYP_POKE
, pDdePoke
->cfFormat
,
863 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
,
865 switch ((ULONG_PTR
)hDdeDataOut
)
874 FIXME("Unsupported returned value %p\n", hDdeDataOut
);
876 case DDE_FNOTPROCESSED
:
879 DdeFreeDataHandle(hDdeData
);
882 GlobalUnlock(pXAct
->hMem
);
886 GlobalFree(pXAct
->hMem
);
888 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_POKE
);
890 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
892 return WDML_QS_HANDLED
;
895 /******************************************************************
896 * WDML_ServerQueueTerminate
900 static WDML_XACT
* WDML_ServerQueueTerminate(WDML_CONV
* pConv
, LPARAM lParam
)
904 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_TERMINATE
, 0, 0);
908 /******************************************************************
909 * WDML_ServerHandleTerminate
913 static WDML_QUEUE_STATE
WDML_ServerHandleTerminate(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
915 /* billx: two things to remove: the conv, and associated links.
916 * Respond with another WM_DDE_TERMINATE iMsg.
918 if (!(pConv
->instance
->CBFflags
& CBF_SKIP_DISCONNECTS
))
920 WDML_InvokeCallback(pConv
->instance
, XTYP_DISCONNECT
, 0, (HCONV
)pConv
, 0, 0,
921 0, 0, (pConv
->wStatus
& ST_ISSELF
) ? 1 : 0);
923 PostMessageA(pConv
->hwndClient
, WM_DDE_TERMINATE
, (WPARAM
)pConv
->hwndServer
, 0);
924 WDML_RemoveConv(pConv
, WDML_SERVER_SIDE
);
926 return WDML_QS_HANDLED
;
929 /******************************************************************
934 WDML_QUEUE_STATE
WDML_ServerHandle(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
936 WDML_QUEUE_STATE qs
= WDML_QS_ERROR
;
938 switch (pXAct
->ddeMsg
)
940 case WM_DDE_INITIATE
:
941 FIXME("WM_DDE_INITIATE shouldn't be there!\n");
944 qs
= WDML_ServerHandleRequest(pConv
, pXAct
);
948 qs
= WDML_ServerHandleAdvise(pConv
, pXAct
);
951 case WM_DDE_UNADVISE
:
952 qs
= WDML_ServerHandleUnadvise(pConv
, pXAct
);
956 qs
= WDML_ServerHandleExecute(pConv
, pXAct
);
960 qs
= WDML_ServerHandlePoke(pConv
, pXAct
);
963 case WM_DDE_TERMINATE
:
964 qs
= WDML_ServerHandleTerminate(pConv
, pXAct
);
968 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
972 FIXME("Unsupported message %d\n", pXAct
->ddeMsg
);
977 /******************************************************************
978 * WDML_ServerConvProc
982 static LRESULT CALLBACK
WDML_ServerConvProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
984 WDML_INSTANCE
* pInstance
;
986 WDML_XACT
* pXAct
= NULL
;
988 if (iMsg
== WM_DESTROY
)
990 EnterCriticalSection(&WDML_CritSect
);
991 pConv
= WDML_GetConvFromWnd(hwndServer
);
992 if (pConv
&& !(pConv
->wStatus
& ST_TERMINATED
))
994 WDML_ServerHandleTerminate(pConv
, NULL
);
996 LeaveCriticalSection(&WDML_CritSect
);
998 if (iMsg
< WM_DDE_FIRST
|| iMsg
> WM_DDE_LAST
)
1000 return DefWindowProcA(hwndServer
, iMsg
, wParam
, lParam
);
1003 EnterCriticalSection(&WDML_CritSect
);
1005 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
1006 pConv
= WDML_GetConvFromWnd(hwndServer
);
1010 ERR("Got a message (%x) on a not known conversation, dropping request\n", iMsg
);
1013 if (pConv
->hwndClient
!= WIN_GetFullHandle( (HWND
)wParam
) || pConv
->hwndServer
!= hwndServer
)
1015 ERR("mismatch between C/S windows and converstation\n");
1018 if (pConv
->instance
!= pInstance
|| pConv
->instance
== NULL
)
1020 ERR("mismatch in instances\n");
1026 case WM_DDE_INITIATE
:
1027 FIXME("WM_DDE_INITIATE message received!\n");
1030 case WM_DDE_REQUEST
:
1031 pXAct
= WDML_ServerQueueRequest(pConv
, lParam
);
1035 pXAct
= WDML_ServerQueueAdvise(pConv
, lParam
);
1038 case WM_DDE_UNADVISE
:
1039 pXAct
= WDML_ServerQueueUnadvise(pConv
, lParam
);
1042 case WM_DDE_EXECUTE
:
1043 pXAct
= WDML_ServerQueueExecute(pConv
, lParam
);
1047 pXAct
= WDML_ServerQueuePoke(pConv
, lParam
);
1050 case WM_DDE_TERMINATE
:
1051 pXAct
= WDML_ServerQueueTerminate(pConv
, lParam
);
1055 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
1059 FIXME("Unsupported message %x\n", iMsg
);
1064 pXAct
->lParam
= lParam
;
1065 if (WDML_ServerHandle(pConv
, pXAct
) == WDML_QS_BLOCK
)
1067 WDML_QueueTransaction(pConv
, pXAct
);
1071 WDML_FreeTransaction(pInstance
, pXAct
, TRUE
);
1075 LeaveCriticalSection(&WDML_CritSect
);