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
22 #include "debugtools.h"
23 #include "dde/dde_private.h"
25 DEFAULT_DEBUG_CHANNEL(ddeml
);
27 static const char szServerNameClassA
[] = "DdeServerNameAnsi";
28 const char WDML_szServerConvClassA
[] = "DdeServerConvAnsi";
29 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};
31 static LRESULT CALLBACK
WDML_ServerNameProc(HWND
, UINT
, WPARAM
, LPARAM
);
32 static LRESULT CALLBACK
WDML_ServerConvProc(HWND
, UINT
, WPARAM
, LPARAM
);
34 /******************************************************************************
35 * DdePostAdvise [USER32.@] Send transaction to DDE callback function.
38 * idInst [I] Instance identifier
39 * hszTopic [I] Handle to topic name string
40 * hszItem [I] Handle to item name string
46 BOOL WINAPI
DdePostAdvise(DWORD idInst
, HSZ hszTopic
, HSZ hszItem
)
48 WDML_INSTANCE
* pInstance
= NULL
;
49 WDML_LINK
* pLink
= NULL
;
50 HDDEDATA hDdeData
= 0, hItemData
= 0;
51 WDML_CONV
* pConv
= NULL
;
55 TRACE("(%ld,0x%x,0x%x)\n", idInst
, hszTopic
, hszItem
);
57 EnterCriticalSection(&WDML_CritSect
);
59 pInstance
= WDML_GetInstance(idInst
);
61 if (pInstance
== NULL
|| pInstance
->links
== NULL
)
66 atom
= WDML_MakeAtomFromHsz(hszItem
);
67 if (!atom
) goto theError
;
69 /* first compute the number of links which will trigger a message */
71 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
73 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
78 if (count
>= CADV_LATEACK
)
80 FIXME("too high value for count\n");
84 for (pLink
= pInstance
->links
[WDML_SERVER_SIDE
]; pLink
!= NULL
; pLink
= pLink
->next
)
86 if (DdeCmpStringHandles(hszItem
, pLink
->hszItem
) == 0)
88 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_ADVREQ
, pLink
->uFmt
, pLink
->hConv
,
89 hszTopic
, hszItem
, 0, count
--, 0);
91 if (hDdeData
== CBR_BLOCK
)
93 /* MS doc is not consistent here */
94 FIXME("CBR_BLOCK returned for ADVREQ\n");
99 if (pLink
->transactionType
& XTYPF_NODATA
)
106 TRACE("with data\n");
108 hItemData
= WDML_DataHandle2Global(hDdeData
, FALSE
, FALSE
, FALSE
, FALSE
);
111 pConv
= WDML_GetConv(pLink
->hConv
, TRUE
);
115 /* FIXME: wrong if app owned... */
116 DdeFreeDataHandle(hDdeData
);
120 if (!PostMessageA(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
121 PackDDElParam(WM_DDE_DATA
, (UINT
)hItemData
, atom
)))
123 ERR("post message failed\n");
124 /* FIXME: wrong if app owned... */
125 DdeFreeDataHandle(hDdeData
);
126 GlobalFree(hItemData
);
132 LeaveCriticalSection(&WDML_CritSect
);
135 LeaveCriticalSection(&WDML_CritSect
);
136 if (atom
) GlobalDeleteAtom(atom
);
141 /******************************************************************************
142 * DdeNameService [USER32.@] {Un}registers service name of DDE server
145 * idInst [I] Instance identifier
146 * hsz1 [I] Handle to service name string
148 * afCmd [I] Service name flags
154 HDDEDATA WINAPI
DdeNameService(DWORD idInst
, HSZ hsz1
, HSZ hsz2
, UINT afCmd
)
156 WDML_SERVER
* pServer
;
157 WDML_INSTANCE
* pInstance
;
160 WNDCLASSEXA wndclass
;
162 hDdeData
= (HDDEDATA
)NULL
;
164 TRACE("(%ld,0x%x,0x%x,%d)\n", idInst
, hsz1
, hsz2
, afCmd
);
166 EnterCriticalSection(&WDML_CritSect
);
168 /* First check instance
170 pInstance
= WDML_GetInstance(idInst
);
171 if (pInstance
== NULL
)
173 TRACE("Instance not found as initialised\n");
174 /* Nothing has been initialised - exit now ! can return TRUE since effect is the same */
180 /* Illegal, reserved parameter
182 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
183 WARN("Reserved parameter no-zero !!\n");
186 if (hsz1
== 0 && afCmd
!= DNS_UNREGISTER
)
188 /* don't know if we should check this but it makes sense
189 * why supply REGISTER or filter flags if de-registering all
191 TRACE("General unregister unexpected flags\n");
192 pInstance
->lastError
= DMLERR_INVALIDPARAMETER
;
199 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
202 ERR("Trying to register already registered service!\n");
203 pInstance
->lastError
= DMLERR_DLL_USAGE
;
207 TRACE("Adding service name\n");
209 WDML_IncHSZ(pInstance
, hsz1
);
211 pServer
= WDML_AddServer(pInstance
, hsz1
, 0);
213 WDML_BroadcastDDEWindows(WDML_szEventClass
, WM_WDML_REGISTER
,
214 pServer
->atomService
, pServer
->atomServiceSpec
);
216 wndclass
.cbSize
= sizeof(wndclass
);
218 wndclass
.lpfnWndProc
= WDML_ServerNameProc
;
219 wndclass
.cbClsExtra
= 0;
220 wndclass
.cbWndExtra
= 2 * sizeof(DWORD
);
221 wndclass
.hInstance
= 0;
223 wndclass
.hCursor
= 0;
224 wndclass
.hbrBackground
= 0;
225 wndclass
.lpszMenuName
= NULL
;
226 wndclass
.lpszClassName
= szServerNameClassA
;
227 wndclass
.hIconSm
= 0;
229 RegisterClassExA(&wndclass
);
231 LeaveCriticalSection(&WDML_CritSect
);
232 hwndServer
= CreateWindowA(szServerNameClassA
, NULL
,
233 WS_POPUP
, 0, 0, 0, 0,
235 EnterCriticalSection(&WDML_CritSect
);
237 SetWindowLongA(hwndServer
, GWL_WDML_INSTANCE
, (DWORD
)pInstance
);
238 SetWindowLongA(hwndServer
, GWL_WDML_SERVER
, (DWORD
)pServer
);
239 TRACE("Created nameServer=%04x for instance=%08lx\n", hwndServer
, idInst
);
241 pServer
->hwndServer
= hwndServer
;
247 /* General unregister situation
248 * terminate all server side pending conversations
250 while (pInstance
->servers
)
251 WDML_RemoveServer(pInstance
, pInstance
->servers
->hszService
, 0);
252 pInstance
->servers
= NULL
;
253 TRACE("General de-register - finished\n");
257 WDML_RemoveServer(pInstance
, hsz1
, 0L);
262 /* Set filter flags on to hold notifications of connection
264 pServer
= WDML_FindServer(pInstance
, hsz1
, 0);
267 /* trying to filter where no service names !!
269 pInstance
->lastError
= DMLERR_DLL_USAGE
;
274 pServer
->filterOn
= (afCmd
== DNS_FILTERON
);
278 LeaveCriticalSection(&WDML_CritSect
);
279 return (HDDEDATA
)TRUE
;
282 LeaveCriticalSection(&WDML_CritSect
);
286 /******************************************************************
287 * WDML_CreateServerConv
291 static WDML_CONV
* WDML_CreateServerConv(WDML_INSTANCE
* pInstance
, HWND hwndClient
,
292 HWND hwndServerName
, HSZ hszApp
, HSZ hszTopic
)
297 if (pInstance
->unicode
)
299 WNDCLASSEXW wndclass
;
301 wndclass
.cbSize
= sizeof(wndclass
);
303 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
304 wndclass
.cbClsExtra
= 0;
305 wndclass
.cbWndExtra
= 2 * sizeof(DWORD
);
306 wndclass
.hInstance
= 0;
308 wndclass
.hCursor
= 0;
309 wndclass
.hbrBackground
= 0;
310 wndclass
.lpszMenuName
= NULL
;
311 wndclass
.lpszClassName
= WDML_szServerConvClassW
;
312 wndclass
.hIconSm
= 0;
314 RegisterClassExW(&wndclass
);
316 hwndServerConv
= CreateWindowW(WDML_szServerConvClassW
, 0,
317 WS_CHILD
, 0, 0, 0, 0,
318 hwndServerName
, 0, 0, 0);
322 WNDCLASSEXA wndclass
;
324 wndclass
.cbSize
= sizeof(wndclass
);
326 wndclass
.lpfnWndProc
= WDML_ServerConvProc
;
327 wndclass
.cbClsExtra
= 0;
328 wndclass
.cbWndExtra
= 2 * sizeof(DWORD
);
329 wndclass
.hInstance
= 0;
331 wndclass
.hCursor
= 0;
332 wndclass
.hbrBackground
= 0;
333 wndclass
.lpszMenuName
= NULL
;
334 wndclass
.lpszClassName
= WDML_szServerConvClassA
;
335 wndclass
.hIconSm
= 0;
337 RegisterClassExA(&wndclass
);
339 hwndServerConv
= CreateWindowA(WDML_szServerConvClassA
, 0,
340 WS_CHILD
, 0, 0, 0, 0,
341 hwndServerName
, 0, 0, 0);
344 TRACE("Created convServer=%04x (nameServer=%04x) for instance=%08lx\n",
345 hwndServerConv
, hwndServerName
, pInstance
->instanceID
);
347 pConv
= WDML_AddConv(pInstance
, WDML_SERVER_SIDE
, hszApp
, hszTopic
,
348 hwndClient
, hwndServerConv
);
351 SetWindowLongA(hwndServerConv
, GWL_WDML_INSTANCE
, (DWORD
)pInstance
);
352 SetWindowLongA(hwndServerConv
, GWL_WDML_CONVERSATION
, (DWORD
)pConv
);
354 /* this should be the only place using SendMessage for WM_DDE_ACK */
355 SendMessageA(hwndClient
, WM_DDE_ACK
, (WPARAM
)hwndServerConv
,
356 PackDDElParam(WM_DDE_ACK
,
357 WDML_MakeAtomFromHsz(hszApp
),
358 WDML_MakeAtomFromHsz(hszTopic
)));
359 /* we assume we're connected since we've sent an answer...
360 * I'm not sure what we can do... it doesn't look like the return value
361 * of SendMessage is used... sigh...
363 pConv
->wStatus
|= ST_CONNECTED
;
367 DestroyWindow(hwndServerConv
);
372 /******************************************************************
373 * WDML_ServerNameProc
377 static LRESULT CALLBACK
WDML_ServerNameProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
381 HDDEDATA hDdeData
= 0;
382 WDML_INSTANCE
* pInstance
;
387 case WM_DDE_INITIATE
:
389 /* wParam -- sending window handle
390 LOWORD(lParam) -- application atom
391 HIWORD(lParam) -- topic atom */
393 TRACE("WM_DDE_INITIATE message received!\n");
394 hwndClient
= (HWND
)wParam
;
396 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
397 TRACE("idInst=%ld, threadID=0x%lx\n", pInstance
->instanceID
, GetCurrentThreadId());
398 if (!pInstance
) return 0;
400 /* don't free DDEParams, since this is a broadcast */
401 UnpackDDElParam(WM_DDE_INITIATE
, lParam
, &uiLo
, &uiHi
);
403 hszApp
= WDML_MakeHszFromAtom(pInstance
, uiLo
);
404 hszTop
= WDML_MakeHszFromAtom(pInstance
, uiHi
);
406 if (!(pInstance
->CBFflags
& CBF_FAIL_CONNECTIONS
))
410 CONVCONTEXT
* pcc
= NULL
;
414 if (GetWindowThreadProcessId(hwndClient
, NULL
) == GetWindowThreadProcessId(hwndServer
, NULL
) &&
415 WDML_GetInstanceFromWnd(hwndClient
) == WDML_GetInstanceFromWnd(hwndServer
))
419 /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
420 * handled under DDEML, and if so build a default context
422 if ((GetClassNameA(hwndClient
, buf
, sizeof(buf
)) &&
423 strcmp(buf
, WDML_szClientConvClassA
) == 0) ||
424 (GetClassNameW(hwndClient
, (LPWSTR
)buf
, sizeof(buf
)/sizeof(WCHAR
)) &&
425 lstrcmpW((LPWSTR
)buf
, WDML_szClientConvClassW
) == 0))
428 memset(pcc
, 0, sizeof(*pcc
));
429 pcc
->cb
= sizeof(*pcc
);
430 pcc
->iCodePage
= IsWindowUnicode(hwndClient
) ? CP_WINUNICODE
: CP_WINANSI
;
432 if ((pInstance
->CBFflags
& CBF_FAIL_SELFCONNECTIONS
) && self
)
434 TRACE("Don't do self connection as requested\n");
436 else if (hszApp
&& hszTop
)
438 WDML_SERVER
* pServer
= (WDML_SERVER
*)GetWindowLongA(hwndServer
, GWL_WDML_SERVER
);
440 /* check filters for name service */
441 if (!pServer
->filterOn
|| DdeCmpStringHandles(pServer
->hszService
, hszApp
) == 0)
443 /* pass on to the callback */
444 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_CONNECT
,
445 0, 0, hszTop
, hszApp
, 0, (DWORD
)pcc
, self
);
448 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
450 if (pConv
&& pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
454 else if (pInstance
->servers
)
456 /* pass on to the callback */
457 hDdeData
= WDML_InvokeCallback(pInstance
, XTYP_WILDCONNECT
,
458 0, 0, hszTop
, hszApp
, 0, (DWORD
)pcc
, self
);
460 if (hDdeData
== CBR_BLOCK
)
462 /* MS doc is not consistent here */
463 FIXME("CBR_BLOCK returned for WILDCONNECT\n");
465 else if ((UINT
)hDdeData
!= 0)
469 hszp
= (HSZPAIR
*)DdeAccessData(hDdeData
, NULL
);
473 for (i
= 0; hszp
[i
].hszSvc
&& hszp
[i
].hszTopic
; i
++)
475 pConv
= WDML_CreateServerConv(pInstance
, hwndClient
, hwndServer
,
476 hszp
[i
].hszSvc
, hszp
[i
].hszTopic
);
477 if (pConv
&& pcc
) pConv
->wStatus
|= ST_ISLOCAL
;
479 DdeUnaccessData(hDdeData
);
485 billx: make a conv and add it to the server list -
486 this can be delayed when link is created for the conv. NO NEED !!!
493 FIXME("WM_DDE_REQUEST message received!\n");
496 FIXME("WM_DDE_ADVISE message received!\n");
498 case WM_DDE_UNADVISE
:
499 FIXME("WM_DDE_UNADVISE message received!\n");
502 FIXME("WM_DDE_EXECUTE message received!\n");
505 FIXME("WM_DDE_POKE message received!\n");
507 case WM_DDE_TERMINATE
:
508 FIXME("WM_DDE_TERMINATE message received!\n");
513 return DefWindowProcA(hwndServer
, iMsg
, wParam
, lParam
);
516 /******************************************************************
517 * WDML_ServerQueueRequest
521 static WDML_XACT
* WDML_ServerQueueRequest(WDML_CONV
* pConv
, LPARAM lParam
)
526 UnpackDDElParam(WM_DDE_REQUEST
, lParam
, &uiLo
, &uiHi
);
528 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_REQUEST
,
529 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
530 if (pXAct
) pXAct
->atom
= uiHi
;
534 /******************************************************************
535 * WDML_ServerHandleRequest
539 static WDML_QUEUE_STATE
WDML_ServerHandleRequest(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
541 HDDEDATA hDdeData
= 0;
542 WDML_QUEUE_STATE ret
= WDML_QS_HANDLED
;
544 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_REQUESTS
))
547 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_REQUEST
, pXAct
->wFmt
, (HCONV
)pConv
,
548 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
554 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, FALSE
, pXAct
->hszItem
,
555 pXAct
->lParam
, WM_DDE_REQUEST
);
562 HGLOBAL hMem
= WDML_DataHandle2Global(hDdeData
, FALSE
, FALSE
, FALSE
, FALSE
);
563 if (!PostMessageA(pConv
->hwndClient
, WM_DDE_DATA
, (WPARAM
)pConv
->hwndServer
,
564 ReuseDDElParam(pXAct
->lParam
, WM_DDE_REQUEST
, WM_DDE_DATA
,
565 (UINT
)hMem
, (UINT
)pXAct
->atom
)))
567 DdeFreeDataHandle(hDdeData
);
573 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
577 /******************************************************************
578 * WDML_ServerQueueAdvise
582 static WDML_XACT
* WDML_ServerQueueAdvise(WDML_CONV
* pConv
, LPARAM lParam
)
587 /* XTYP_ADVSTART transaction:
588 establish link and save link info to InstanceInfoTable */
590 UnpackDDElParam(WM_DDE_ADVISE
, lParam
, &uiLo
, &uiHi
);
592 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_ADVISE
,
593 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
596 pXAct
->hMem
= (HGLOBAL
)uiLo
;
602 /******************************************************************
603 * WDML_ServerHandleAdvise
607 static WDML_QUEUE_STATE
WDML_ServerHandleAdvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
611 DDEADVISE
* pDdeAdvise
;
615 pDdeAdvise
= (DDEADVISE
*)GlobalLock(pXAct
->hMem
);
616 uType
= XTYP_ADVSTART
|
617 (pDdeAdvise
->fDeferUpd
? XTYPF_NODATA
: 0) |
618 (pDdeAdvise
->fAckReq
? XTYPF_ACKREQ
: 0);
620 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
622 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTART
, pDdeAdvise
->cfFormat
,
623 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
634 /* billx: first to see if the link is already created. */
635 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
636 pXAct
->hszItem
, pDdeAdvise
->cfFormat
);
640 /* we found a link, and only need to modify it in case it changes */
641 pLink
->transactionType
= uType
;
645 TRACE("Adding Link with hConv=0x%lx\n", (DWORD
)pConv
);
647 WDML_AddLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
648 uType
, pXAct
->hszItem
, pDdeAdvise
->cfFormat
);
653 TRACE("No data returned from the Callback\n");
657 GlobalUnlock(pXAct
->hMem
);
659 GlobalFree(pXAct
->hMem
);
661 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_ADVISE
);
663 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
665 return WDML_QS_HANDLED
;
668 /******************************************************************
669 * WDML_ServerQueueUnadvise
673 static WDML_XACT
* WDML_ServerQueueUnadvise(WDML_CONV
* pConv
, LPARAM lParam
)
678 UnpackDDElParam(WM_DDE_UNADVISE
, lParam
, &uiLo
, &uiHi
);
680 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_UNADVISE
,
681 uiLo
, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
682 if (pXAct
) pXAct
->atom
= uiHi
;
686 /******************************************************************
687 * WDML_ServerHandleUnadvise
691 static WDML_QUEUE_STATE
WDML_ServerHandleUnadvise(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
695 if (pXAct
->hszItem
== (HSZ
)0 || pXAct
->wFmt
== 0)
697 ERR("Unsupported yet options (null item or clipboard format)\n");
698 return WDML_QS_ERROR
;
701 pLink
= WDML_FindLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
702 pXAct
->hszItem
, pXAct
->wFmt
);
705 ERR("Couln'd find link for %08lx, dropping request\n", (DWORD
)pXAct
->hszItem
);
706 FreeDDElParam(WM_DDE_UNADVISE
, pXAct
->lParam
);
707 return WDML_QS_ERROR
;
710 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_ADVISES
))
712 WDML_InvokeCallback(pConv
->instance
, XTYP_ADVSTOP
, pXAct
->wFmt
, (HCONV
)pConv
,
713 pConv
->hszTopic
, pXAct
->hszItem
, 0, 0, 0);
716 WDML_RemoveLink(pConv
->instance
, (HCONV
)pConv
, WDML_SERVER_SIDE
,
717 pXAct
->hszItem
, pXAct
->wFmt
);
720 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, FALSE
, TRUE
, pXAct
->atom
,
721 pXAct
->lParam
, WM_DDE_UNADVISE
);
723 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
725 return WDML_QS_HANDLED
;
728 /******************************************************************
733 static WDML_XACT
* WDML_ServerQueueExecute(WDML_CONV
* pConv
, LPARAM lParam
)
737 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_EXECUTE
, 0, 0);
740 pXAct
->hMem
= (HGLOBAL
)lParam
;
745 /******************************************************************
746 * WDML_ServerHandleExecute
750 static WDML_QUEUE_STATE
WDML_ServerHandleExecute(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
752 HDDEDATA hDdeData
= DDE_FNOTPROCESSED
;
753 BOOL fAck
= FALSE
, fBusy
= FALSE
;
755 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_EXECUTES
))
757 LPVOID ptr
= GlobalLock(pXAct
->hMem
);
761 hDdeData
= DdeCreateDataHandle(0, ptr
, GlobalSize(pXAct
->hMem
),
763 GlobalUnlock(pXAct
->hMem
);
765 hDdeData
= WDML_InvokeCallback(pConv
->instance
, XTYP_EXECUTE
, 0, (HCONV
)pConv
,
766 pConv
->hszTopic
, 0, hDdeData
, 0L, 0L);
769 switch ((UINT
)hDdeData
)
778 WARN("Bad result code\n");
780 case DDE_FNOTPROCESSED
:
783 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, pXAct
->hMem
, 0, 0);
785 return WDML_QS_HANDLED
;
788 /******************************************************************
789 * WDML_ServerQueuePoke
793 static WDML_XACT
* WDML_ServerQueuePoke(WDML_CONV
* pConv
, LPARAM lParam
)
798 UnpackDDElParam(WM_DDE_POKE
, lParam
, &uiLo
, &uiHi
);
800 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_POKE
,
801 0, WDML_MakeHszFromAtom(pConv
->instance
, uiHi
));
805 pXAct
->hMem
= (HGLOBAL
)uiLo
;
810 /******************************************************************
811 * WDML_ServerHandlePoke
815 static WDML_QUEUE_STATE
WDML_ServerHandlePoke(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
819 BOOL fBusy
= FALSE
, fAck
= FALSE
;
821 pDdePoke
= (DDEPOKE
*)GlobalLock(pXAct
->hMem
);
824 return WDML_QS_ERROR
;
827 if (!(pConv
->instance
->CBFflags
& CBF_FAIL_POKES
))
829 hDdeData
= DdeCreateDataHandle(pConv
->instance
->instanceID
, pDdePoke
->Value
,
830 GlobalSize(pXAct
->hMem
) - sizeof(DDEPOKE
) + 1,
831 0, 0, pDdePoke
->cfFormat
, 0);
834 HDDEDATA hDdeDataOut
;
836 hDdeDataOut
= WDML_InvokeCallback(pConv
->instance
, XTYP_POKE
, pDdePoke
->cfFormat
,
837 (HCONV
)pConv
, pConv
->hszTopic
, pXAct
->hszItem
,
839 switch ((UINT
)hDdeDataOut
)
848 FIXME("Unsupported returned value %08lx\n", (DWORD
)hDdeDataOut
);
850 case DDE_FNOTPROCESSED
:
853 DdeFreeDataHandle(hDdeData
);
856 GlobalUnlock(pXAct
->hMem
);
859 GlobalFree(pXAct
->hMem
);
861 WDML_PostAck(pConv
, WDML_SERVER_SIDE
, 0, fBusy
, fAck
, pXAct
->atom
, pXAct
->lParam
, WM_DDE_POKE
);
863 WDML_DecHSZ(pConv
->instance
, pXAct
->hszItem
);
865 return WDML_QS_HANDLED
;
868 /******************************************************************
869 * WDML_ServerQueueTerminate
873 static WDML_XACT
* WDML_ServerQueueTerminate(WDML_CONV
* pConv
, LPARAM lParam
)
877 pXAct
= WDML_AllocTransaction(pConv
->instance
, WM_DDE_TERMINATE
, 0, 0);
881 /******************************************************************
882 * WDML_ServerHandleTerminate
886 static WDML_QUEUE_STATE
WDML_ServerHandleTerminate(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
888 /* billx: two things to remove: the conv, and associated links.
889 * Respond with another WM_DDE_TERMINATE iMsg.
891 if (!(pConv
->instance
->CBFflags
& CBF_SKIP_DISCONNECTS
))
893 WDML_InvokeCallback(pConv
->instance
, XTYP_DISCONNECT
, 0, (HCONV
)pConv
, 0, 0,
894 0, 0, (pConv
->wStatus
& ST_ISSELF
) ? 1 : 0);
897 PostMessageA(pConv
->hwndClient
, WM_DDE_TERMINATE
, (WPARAM
)pConv
->hwndServer
, 0);
898 WDML_RemoveConv(pConv
, WDML_SERVER_SIDE
);
900 return WDML_QS_HANDLED
;
903 /******************************************************************
908 static WDML_QUEUE_STATE
WDML_ServerHandle(WDML_CONV
* pConv
, WDML_XACT
* pXAct
)
910 WDML_QUEUE_STATE qs
= WDML_QS_ERROR
;
912 switch (pXAct
->ddeMsg
)
914 case WM_DDE_INITIATE
:
915 FIXME("WM_DDE_INITIATE shouldn't be there!\n");
918 qs
= WDML_ServerHandleRequest(pConv
, pXAct
);
922 qs
= WDML_ServerHandleAdvise(pConv
, pXAct
);
925 case WM_DDE_UNADVISE
:
926 qs
= WDML_ServerHandleUnadvise(pConv
, pXAct
);
930 qs
= WDML_ServerHandleExecute(pConv
, pXAct
);
934 qs
= WDML_ServerHandlePoke(pConv
, pXAct
);
937 case WM_DDE_TERMINATE
:
938 qs
= WDML_ServerHandleTerminate(pConv
, pXAct
);
942 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
946 FIXME("Unsupported message %d\n", pXAct
->ddeMsg
);
951 /******************************************************************
952 * WDML_ServerConvProc
956 static LRESULT CALLBACK
WDML_ServerConvProc(HWND hwndServer
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
958 WDML_INSTANCE
* pInstance
;
960 WDML_XACT
* pXAct
= NULL
;
962 if (iMsg
== WM_DESTROY
)
964 EnterCriticalSection(&WDML_CritSect
);
965 pConv
= WDML_GetConvFromWnd(hwndServer
);
966 if (pConv
&& !(pConv
->wStatus
& ST_TERMINATED
))
968 WDML_ServerHandleTerminate(pConv
, NULL
);
970 LeaveCriticalSection(&WDML_CritSect
);
972 if (iMsg
< WM_DDE_FIRST
|| iMsg
> WM_DDE_LAST
)
974 return DefWindowProcA(hwndServer
, iMsg
, wParam
, lParam
);
977 EnterCriticalSection(&WDML_CritSect
);
979 pInstance
= WDML_GetInstanceFromWnd(hwndServer
);
980 pConv
= WDML_GetConvFromWnd(hwndServer
);
984 ERR("Got a message (%u) on a not known conversation, dropping request\n", iMsg
);
987 if (pConv
->hwndClient
!= WIN_GetFullHandle( (HWND
)wParam
) || pConv
->hwndServer
!= hwndServer
)
989 ERR("mismatch between C/S windows and converstation\n");
992 if (pConv
->instance
!= pInstance
|| pConv
->instance
== NULL
)
994 ERR("mismatch in instances\n");
1000 case WM_DDE_INITIATE
:
1001 FIXME("WM_DDE_INITIATE message received!\n");
1004 case WM_DDE_REQUEST
:
1005 pXAct
= WDML_ServerQueueRequest(pConv
, lParam
);
1009 pXAct
= WDML_ServerQueueAdvise(pConv
, lParam
);
1012 case WM_DDE_UNADVISE
:
1013 pXAct
= WDML_ServerQueueUnadvise(pConv
, lParam
);
1016 case WM_DDE_EXECUTE
:
1017 pXAct
= WDML_ServerQueueExecute(pConv
, lParam
);
1021 pXAct
= WDML_ServerQueuePoke(pConv
, lParam
);
1024 case WM_DDE_TERMINATE
:
1025 pXAct
= WDML_ServerQueueTerminate(pConv
, lParam
);
1029 WARN("Shouldn't receive a ACK message (never requests them). Ignoring it\n");
1033 FIXME("Unsupported message %d\n", iMsg
);
1038 pXAct
->lParam
= lParam
;
1039 if (WDML_ServerHandle(pConv
, pXAct
) == WDML_QS_BLOCK
)
1041 WDML_QueueTransaction(pConv
, pXAct
);
1045 WDML_FreeTransaction(pInstance
, pXAct
, TRUE
);
1049 LeaveCriticalSection(&WDML_CritSect
);