Handle CBR_BLOCK in EXECUTE and ADVISE DDE transactions.
[wine/multimedia.git] / dlls / user / dde / misc.c
blob0013a4c6a8d1da559425ba58f8fb55c3909d7b4d
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * DDEML library
6 * Copyright 1997 Alexandre Julliard
7 * Copyright 1997 Len White
8 * Copyright 1999 Keith Matthews
9 * Copyright 2000 Corel
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
27 #include "config.h"
28 #include "wine/port.h"
30 #include <string.h>
31 #include <stdarg.h>
32 #include <stdio.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "winerror.h"
38 #include "dde.h"
39 #include "ddeml.h"
40 #include "win.h"
41 #include "wine/debug.h"
42 #include "dde/dde_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
46 /* convert between ATOM and HSZ avoiding compiler warnings */
47 #define ATOM2HSZ(atom) ((HSZ) (ULONG_PTR)(atom))
48 #define HSZ2ATOM(hsz) ((ATOM) (ULONG_PTR)(hsz))
50 static WDML_INSTANCE* WDML_InstanceList = NULL;
51 static DWORD WDML_MaxInstanceID = 0; /* OK for present, have to worry about wrap-around later */
52 const char WDML_szEventClass[] = "DdeEventClass";
54 static CRITICAL_SECTION_DEBUG critsect_debug =
56 0, 0, &WDML_CritSect,
57 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
58 0, 0, { 0, (DWORD)(__FILE__ ": WDML_CritSect") }
60 CRITICAL_SECTION WDML_CritSect = { &critsect_debug, -1, 0, 0, 0, 0 };
62 /* ================================================================
64 * Pure DDE (non DDEML) management
66 * ================================================================ */
69 /*****************************************************************
70 * PackDDElParam (USER32.@)
72 * RETURNS
73 * the packed lParam
75 LPARAM WINAPI PackDDElParam(UINT msg, UINT_PTR uiLo, UINT_PTR uiHi)
77 HGLOBAL hMem;
78 UINT_PTR *params;
80 switch (msg)
82 case WM_DDE_ACK:
83 case WM_DDE_ADVISE:
84 case WM_DDE_DATA:
85 case WM_DDE_POKE:
86 if (!(hMem = GlobalAlloc(GMEM_DDESHARE, sizeof(UINT_PTR) * 2)))
88 ERR("GlobalAlloc failed\n");
89 return 0;
91 if (!(params = GlobalLock(hMem)))
93 ERR("GlobalLock failed (%p)\n", hMem);
94 return 0;
96 params[0] = uiLo;
97 params[1] = uiHi;
98 GlobalUnlock(hMem);
99 return (LPARAM)hMem;
101 case WM_DDE_EXECUTE:
102 return uiHi;
104 default:
105 return MAKELPARAM(uiLo, uiHi);
110 /*****************************************************************
111 * UnpackDDElParam (USER32.@)
113 * RETURNS
114 * success: nonzero
115 * failure: zero
117 BOOL WINAPI UnpackDDElParam(UINT msg, LPARAM lParam,
118 PUINT_PTR uiLo, PUINT_PTR uiHi)
120 UINT_PTR *params;
122 switch (msg)
124 case WM_DDE_ACK:
125 case WM_DDE_ADVISE:
126 case WM_DDE_DATA:
127 case WM_DDE_POKE:
128 if (!lParam) return FALSE;
129 if (!(params = GlobalLock( (HGLOBAL)lParam )))
131 ERR("GlobalLock failed (%lx)\n", lParam);
132 return FALSE;
134 TRACE("unpacked: low %08x, high %08x\n", params[0], params[1]);
135 if (uiLo) *uiLo = params[0];
136 if (uiHi) *uiHi = params[1];
137 GlobalUnlock( (HGLOBAL)lParam );
138 return TRUE;
140 case WM_DDE_EXECUTE:
141 if (uiLo) *uiLo = 0;
142 if (uiHi) *uiHi = lParam;
143 return TRUE;
145 default:
146 if (uiLo) *uiLo = LOWORD(lParam);
147 if (uiHi) *uiHi = HIWORD(lParam);
148 return TRUE;
153 /*****************************************************************
154 * FreeDDElParam (USER32.@)
156 * RETURNS
157 * success: nonzero
158 * failure: zero
160 BOOL WINAPI FreeDDElParam(UINT msg, LPARAM lParam)
162 switch (msg)
164 case WM_DDE_ACK:
165 case WM_DDE_ADVISE:
166 case WM_DDE_DATA:
167 case WM_DDE_POKE:
168 /* first check if it's a global handle */
169 if (!GlobalHandle( (LPVOID)lParam )) return TRUE;
170 return !GlobalFree( (HGLOBAL)lParam );
172 default:
173 return TRUE;
178 /*****************************************************************
179 * ReuseDDElParam (USER32.@)
181 * RETURNS
182 * the packed lParam
184 LPARAM WINAPI ReuseDDElParam(LPARAM lParam, UINT msgIn, UINT msgOut,
185 UINT_PTR uiLo, UINT_PTR uiHi)
187 UINT_PTR *params;
189 switch (msgIn)
191 case WM_DDE_ACK:
192 case WM_DDE_ADVISE:
193 case WM_DDE_DATA:
194 case WM_DDE_POKE:
195 switch(msgOut)
197 case WM_DDE_ACK:
198 case WM_DDE_ADVISE:
199 case WM_DDE_DATA:
200 case WM_DDE_POKE:
201 if (!lParam) return 0;
202 if (!(params = GlobalLock( (HGLOBAL)lParam )))
204 ERR("GlobalLock failed\n");
205 return 0;
207 params[0] = uiLo;
208 params[1] = uiHi;
209 TRACE("Reusing pack %08x %08x\n", uiLo, uiHi);
210 GlobalLock( (HGLOBAL)lParam );
211 return lParam;
213 case WM_DDE_EXECUTE:
214 FreeDDElParam( msgIn, lParam );
215 return uiHi;
217 default:
218 FreeDDElParam( msgIn, lParam );
219 return MAKELPARAM(uiLo, uiHi);
222 default:
223 return PackDDElParam( msgOut, uiLo, uiHi );
227 /*****************************************************************
228 * ImpersonateDdeClientWindow (USER32.@)
230 * PARAMS
231 * hWndClient [I] handle to DDE client window
232 * hWndServer [I] handle to DDE server window
234 BOOL WINAPI ImpersonateDdeClientWindow(HWND hWndClient, HWND hWndServer)
236 FIXME("(%p %p): stub\n", hWndClient, hWndServer);
237 return FALSE;
240 /*****************************************************************
241 * DdeSetQualityOfService (USER32.@)
244 BOOL WINAPI DdeSetQualityOfService(HWND hwndClient, CONST SECURITY_QUALITY_OF_SERVICE *pqosNew,
245 PSECURITY_QUALITY_OF_SERVICE pqosPrev)
247 FIXME("(%p %p %p): stub\n", hwndClient, pqosNew, pqosPrev);
248 return TRUE;
251 /* ================================================================
253 * Instance management
255 * ================================================================ */
257 /******************************************************************************
258 * IncrementInstanceId
260 * generic routine to increment the max instance Id and allocate a new application instance
262 static void WDML_IncrementInstanceId(WDML_INSTANCE* pInstance)
264 DWORD id = InterlockedIncrement(&WDML_MaxInstanceID);
266 pInstance->instanceID = id;
267 TRACE("New instance id %ld allocated\n", id);
270 /******************************************************************
271 * WDML_EventProc
275 static LRESULT CALLBACK WDML_EventProc(HWND hwndEvent, UINT uMsg, WPARAM wParam, LPARAM lParam)
277 WDML_INSTANCE* pInstance;
278 HSZ hsz1, hsz2;
280 switch (uMsg)
282 case WM_WDML_REGISTER:
283 pInstance = WDML_GetInstanceFromWnd(hwndEvent);
284 /* try calling the Callback */
285 if (pInstance && !(pInstance->CBFflags & CBF_SKIP_REGISTRATIONS))
287 hsz1 = WDML_MakeHszFromAtom(pInstance, wParam);
288 hsz2 = WDML_MakeHszFromAtom(pInstance, lParam);
289 WDML_InvokeCallback(pInstance, XTYP_REGISTER, 0, 0, hsz1, hsz2, 0, 0, 0);
290 WDML_DecHSZ(pInstance, hsz1);
291 WDML_DecHSZ(pInstance, hsz2);
293 break;
295 case WM_WDML_UNREGISTER:
296 pInstance = WDML_GetInstanceFromWnd(hwndEvent);
297 if (pInstance && !(pInstance->CBFflags & CBF_SKIP_UNREGISTRATIONS))
299 hsz1 = WDML_MakeHszFromAtom(pInstance, wParam);
300 hsz2 = WDML_MakeHszFromAtom(pInstance, lParam);
301 WDML_InvokeCallback(pInstance, XTYP_UNREGISTER, 0, 0, hsz1, hsz2, 0, 0, 0);
302 WDML_DecHSZ(pInstance, hsz1);
303 WDML_DecHSZ(pInstance, hsz2);
305 break;
307 case WM_WDML_CONNECT_CONFIRM:
308 pInstance = WDML_GetInstanceFromWnd(hwndEvent);
309 if (pInstance && !(pInstance->CBFflags & CBF_SKIP_CONNECT_CONFIRMS))
311 WDML_CONV* pConv;
312 /* confirm connection...
313 * lookup for this conv handle
315 HWND client = WIN_GetFullHandle( (HWND)wParam );
316 HWND server = WIN_GetFullHandle( (HWND)lParam );
317 for (pConv = pInstance->convs[WDML_SERVER_SIDE]; pConv != NULL; pConv = pConv->next)
319 if (pConv->hwndClient == client && pConv->hwndServer == server)
320 break;
322 if (pConv)
324 pConv->wStatus |= ST_ISLOCAL;
326 WDML_InvokeCallback(pInstance, XTYP_CONNECT_CONFIRM, 0, (HCONV)pConv,
327 pConv->hszTopic, pConv->hszService, 0, 0,
328 (pConv->wStatus & ST_ISSELF) ? 1 : 0);
331 break;
332 default:
333 return DefWindowProcA(hwndEvent, uMsg, wParam, lParam);
335 return 0;
338 /******************************************************************
339 * WDML_Initialize
343 UINT WDML_Initialize(LPDWORD pidInst, PFNCALLBACK pfnCallback,
344 DWORD afCmd, DWORD ulRes, BOOL bUnicode, BOOL b16)
346 WDML_INSTANCE* pInstance;
347 WDML_INSTANCE* reference_inst;
348 UINT ret;
349 WNDCLASSEXA wndclass;
351 TRACE("(%p,%p,0x%lx,%ld)\n",
352 pidInst, pfnCallback, afCmd, ulRes);
354 if (ulRes)
356 ERR("Reserved value not zero? What does this mean?\n");
357 /* trap this and no more until we know more */
358 return DMLERR_NO_ERROR;
361 /* grab enough heap for one control struct - not really necessary for re-initialise
362 * but allows us to use same validation routines */
363 pInstance = (WDML_INSTANCE*)HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_INSTANCE));
364 if (pInstance == NULL)
366 /* catastrophe !! warn user & abort */
367 ERR("Instance create failed - out of memory\n");
368 return DMLERR_SYS_ERROR;
370 pInstance->next = NULL;
371 pInstance->monitor = (afCmd | APPCLASS_MONITOR);
373 /* messy bit, spec implies that 'Client Only' can be set in 2 different ways, catch 1 here */
375 pInstance->clientOnly = afCmd & APPCMD_CLIENTONLY;
376 pInstance->instanceID = *pidInst; /* May need to add calling proc Id */
377 pInstance->threadID = GetCurrentThreadId();
378 pInstance->callback = *pfnCallback;
379 pInstance->unicode = bUnicode;
380 pInstance->win16 = b16;
381 pInstance->nodeList = NULL; /* node will be added later */
382 pInstance->monitorFlags = afCmd & MF_MASK;
383 pInstance->servers = NULL;
384 pInstance->convs[0] = NULL;
385 pInstance->convs[1] = NULL;
386 pInstance->links[0] = NULL;
387 pInstance->links[1] = NULL;
389 /* isolate CBF flags in one go, expect this will go the way of all attempts to be clever !! */
391 pInstance->CBFflags = afCmd^((afCmd&MF_MASK)|((afCmd&APPCMD_MASK)|(afCmd&APPCLASS_MASK)));
393 if (!pInstance->clientOnly)
395 /* Check for other way of setting Client-only !! */
396 pInstance->clientOnly =
397 (pInstance->CBFflags & CBF_FAIL_ALLSVRXACTIONS) == CBF_FAIL_ALLSVRXACTIONS;
400 TRACE("instance created - checking validity \n");
402 if (*pidInst == 0)
404 /* Initialisation of new Instance Identifier */
405 TRACE("new instance, callback %p flags %lX\n",pfnCallback,afCmd);
407 EnterCriticalSection(&WDML_CritSect);
409 if (WDML_InstanceList == NULL)
411 /* can't be another instance in this case, assign to the base pointer */
412 WDML_InstanceList = pInstance;
414 /* since first must force filter of XTYP_CONNECT and XTYP_WILDCONNECT for
415 * present
416 * ------------------------------- NOTE NOTE NOTE --------------------------
418 * the manual is not clear if this condition
419 * applies to the first call to DdeInitialize from an application, or the
420 * first call for a given callback !!!
423 pInstance->CBFflags = pInstance->CBFflags|APPCMD_FILTERINITS;
424 TRACE("First application instance detected OK\n");
425 /* allocate new instance ID */
426 WDML_IncrementInstanceId(pInstance);
428 else
430 /* really need to chain the new one in to the latest here, but after checking conditions
431 * such as trying to start a conversation from an application trying to monitor */
432 reference_inst = WDML_InstanceList;
433 TRACE("Subsequent application instance - starting checks\n");
434 while (reference_inst->next != NULL)
437 * This set of tests will work if application uses same instance Id
438 * at application level once allocated - which is what manual implies
439 * should happen. If someone tries to be
440 * clever (lazy ?) it will fail to pick up that later calls are for
441 * the same application - should we trust them ?
443 if (pInstance->instanceID == reference_inst->instanceID)
445 /* Check 1 - must be same Client-only state */
447 if (pInstance->clientOnly != reference_inst->clientOnly)
449 ret = DMLERR_DLL_USAGE;
450 goto theError;
453 /* Check 2 - cannot use 'Monitor' with any non-monitor modes */
455 if (pInstance->monitor != reference_inst->monitor)
457 ret = DMLERR_INVALIDPARAMETER;
458 goto theError;
461 /* Check 3 - must supply different callback address */
463 if (pInstance->callback == reference_inst->callback)
465 ret = DMLERR_DLL_USAGE;
466 goto theError;
469 reference_inst = reference_inst->next;
471 /* All cleared, add to chain */
473 TRACE("Application Instance checks finished\n");
474 WDML_IncrementInstanceId(pInstance);
475 reference_inst->next = pInstance;
477 LeaveCriticalSection(&WDML_CritSect);
479 *pidInst = pInstance->instanceID;
481 /* for deadlock issues, windows must always be created when outside the critical section */
482 wndclass.cbSize = sizeof(wndclass);
483 wndclass.style = 0;
484 wndclass.lpfnWndProc = WDML_EventProc;
485 wndclass.cbClsExtra = 0;
486 wndclass.cbWndExtra = sizeof(DWORD);
487 wndclass.hInstance = 0;
488 wndclass.hIcon = 0;
489 wndclass.hCursor = 0;
490 wndclass.hbrBackground = 0;
491 wndclass.lpszMenuName = NULL;
492 wndclass.lpszClassName = WDML_szEventClass;
493 wndclass.hIconSm = 0;
495 RegisterClassExA(&wndclass);
497 pInstance->hwndEvent = CreateWindowA(WDML_szEventClass, NULL,
498 WS_POPUP, 0, 0, 0, 0,
499 0, 0, 0, 0);
501 SetWindowLongA(pInstance->hwndEvent, GWL_WDML_INSTANCE, (DWORD)pInstance);
503 TRACE("New application instance processing finished OK\n");
505 else
507 /* Reinitialisation situation --- FIX */
508 TRACE("reinitialisation of (%p,%p,0x%lx,%ld): stub\n", pidInst, pfnCallback, afCmd, ulRes);
510 EnterCriticalSection(&WDML_CritSect);
512 if (WDML_InstanceList == NULL)
514 ret = DMLERR_INVALIDPARAMETER;
515 goto theError;
517 HeapFree(GetProcessHeap(), 0, pInstance); /* finished - release heap space used as work store */
518 /* can't reinitialise if we have initialised nothing !! */
519 reference_inst = WDML_InstanceList;
520 /* must first check if we have been given a valid instance to re-initialise !! how do we do that ? */
522 * MS allows initialisation without specifying a callback, should we allow addition of the
523 * callback by a later call to initialise ? - if so this lot will have to change
525 while (reference_inst->next != NULL)
527 if (*pidInst == reference_inst->instanceID && pfnCallback == reference_inst->callback)
529 /* Check 1 - cannot change client-only mode if set via APPCMD_CLIENTONLY */
531 if (reference_inst->clientOnly)
533 if ((reference_inst->CBFflags & CBF_FAIL_ALLSVRXACTIONS) != CBF_FAIL_ALLSVRXACTIONS)
535 /* i.e. Was set to Client-only and through APPCMD_CLIENTONLY */
537 if (!(afCmd & APPCMD_CLIENTONLY))
539 ret = DMLERR_INVALIDPARAMETER;
540 goto theError;
544 /* Check 2 - cannot change monitor modes */
546 if (pInstance->monitor != reference_inst->monitor)
548 ret = DMLERR_INVALIDPARAMETER;
549 goto theError;
552 /* Check 3 - trying to set Client-only via APPCMD when not set so previously */
554 if ((afCmd&APPCMD_CLIENTONLY) && !reference_inst->clientOnly)
556 ret = DMLERR_INVALIDPARAMETER;
557 goto theError;
559 break;
561 reference_inst = reference_inst->next;
563 if (reference_inst->next == NULL)
565 ret = DMLERR_INVALIDPARAMETER;
566 goto theError;
568 /* All checked - change relevant flags */
570 reference_inst->CBFflags = pInstance->CBFflags;
571 reference_inst->clientOnly = pInstance->clientOnly;
572 reference_inst->monitorFlags = pInstance->monitorFlags;
573 LeaveCriticalSection(&WDML_CritSect);
576 return DMLERR_NO_ERROR;
577 theError:
578 HeapFree(GetProcessHeap(), 0, pInstance);
579 LeaveCriticalSection(&WDML_CritSect);
580 return ret;
583 /******************************************************************************
584 * DdeInitializeA (USER32.@)
586 UINT WINAPI DdeInitializeA(LPDWORD pidInst, PFNCALLBACK pfnCallback,
587 DWORD afCmd, DWORD ulRes)
589 return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, FALSE, FALSE);
592 /******************************************************************************
593 * DdeInitializeW [USER32.@]
594 * Registers an application with the DDEML
596 * PARAMS
597 * pidInst [I] Pointer to instance identifier
598 * pfnCallback [I] Pointer to callback function
599 * afCmd [I] Set of command and filter flags
600 * ulRes [I] Reserved
602 * RETURNS
603 * Success: DMLERR_NO_ERROR
604 * Failure: DMLERR_DLL_USAGE, DMLERR_INVALIDPARAMETER, DMLERR_SYS_ERROR
606 UINT WINAPI DdeInitializeW(LPDWORD pidInst, PFNCALLBACK pfnCallback,
607 DWORD afCmd, DWORD ulRes)
609 return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, TRUE, FALSE);
612 /*****************************************************************
613 * DdeUninitialize [USER32.@] Frees DDEML resources
615 * PARAMS
616 * idInst [I] Instance identifier
618 * RETURNS
619 * Success: TRUE
620 * Failure: FALSE
623 BOOL WINAPI DdeUninitialize(DWORD idInst)
625 /* Stage one - check if we have a handle for this instance
627 WDML_INSTANCE* pInstance;
628 WDML_CONV* pConv;
629 WDML_CONV* pConvNext;
631 TRACE("(%ld)\n", idInst);
633 EnterCriticalSection(&WDML_CritSect);
635 /* First check instance
637 pInstance = WDML_GetInstance(idInst);
638 if (pInstance == NULL)
640 LeaveCriticalSection(&WDML_CritSect);
642 * Needs something here to record NOT_INITIALIZED ready for DdeGetLastError
644 return FALSE;
647 /* first terminate all conversations client side
648 * this shall close existing links...
650 for (pConv = pInstance->convs[WDML_CLIENT_SIDE]; pConv != NULL; pConv = pConvNext)
652 pConvNext = pConv->next;
653 DdeDisconnect((HCONV)pConv);
655 if (pInstance->convs[WDML_CLIENT_SIDE])
656 FIXME("still pending conversations\n");
658 /* then unregister all known service names */
659 DdeNameService(idInst, 0, 0, DNS_UNREGISTER);
661 /* Free the nodes that were not freed by this instance
662 * and remove the nodes from the list of HSZ nodes.
664 WDML_FreeAllHSZ(pInstance);
666 DestroyWindow(pInstance->hwndEvent);
668 /* OK now delete the instance handle itself */
670 if (WDML_InstanceList == pInstance)
672 /* special case - the first/only entry */
673 WDML_InstanceList = pInstance->next;
675 else
677 /* general case, remove entry */
678 WDML_INSTANCE* inst;
680 for (inst = WDML_InstanceList; inst->next != pInstance; inst = inst->next);
681 inst->next = pInstance->next;
683 /* leave crit sect and release the heap entry
685 HeapFree(GetProcessHeap(), 0, pInstance);
686 LeaveCriticalSection(&WDML_CritSect);
687 return TRUE;
690 /******************************************************************
691 * WDML_NotifyThreadExit
695 void WDML_NotifyThreadDetach(void)
697 WDML_INSTANCE* pInstance;
698 WDML_INSTANCE* next;
699 DWORD tid = GetCurrentThreadId();
701 EnterCriticalSection(&WDML_CritSect);
702 for (pInstance = WDML_InstanceList; pInstance != NULL; pInstance = next)
704 next = pInstance->next;
705 if (pInstance->threadID == tid)
707 DdeUninitialize(pInstance->instanceID);
710 LeaveCriticalSection(&WDML_CritSect);
713 /******************************************************************
714 * WDML_InvokeCallback
718 HDDEDATA WDML_InvokeCallback(WDML_INSTANCE* pInstance, UINT uType, UINT uFmt, HCONV hConv,
719 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
720 ULONG_PTR dwData1, ULONG_PTR dwData2)
722 HDDEDATA ret;
724 if (pInstance == NULL)
725 return NULL;
726 TRACE("invoking CB%d[%p] (%x %x %p %p %p %p %lx %lx)\n",
727 pInstance->win16 ? 16 : 32, pInstance->callback, uType, uFmt,
728 hConv, hsz1, hsz2, hdata, dwData1, dwData2);
729 if (pInstance->win16)
731 ret = WDML_InvokeCallback16(pInstance->callback, uType, uFmt, hConv,
732 hsz1, hsz2, hdata, dwData1, dwData2);
734 else
736 ret = pInstance->callback(uType, uFmt, hConv, hsz1, hsz2, hdata, dwData1, dwData2);
738 TRACE("done => %p\n", ret);
739 return ret;
742 /*****************************************************************************
743 * WDML_GetInstance
745 * generic routine to return a pointer to the relevant DDE_HANDLE_ENTRY
746 * for an instance Id, or NULL if the entry does not exist
749 WDML_INSTANCE* WDML_GetInstance(DWORD instId)
751 WDML_INSTANCE* pInstance;
753 for (pInstance = WDML_InstanceList; pInstance != NULL; pInstance = pInstance->next)
755 if (pInstance->instanceID == instId)
757 if (GetCurrentThreadId() != pInstance->threadID)
759 FIXME("Tried to get instance from wrong thread\n");
760 continue;
762 return pInstance;
765 TRACE("Instance entry missing\n");
766 return NULL;
769 /******************************************************************
770 * WDML_GetInstanceFromWnd
774 WDML_INSTANCE* WDML_GetInstanceFromWnd(HWND hWnd)
776 return (WDML_INSTANCE*)GetWindowLongA(hWnd, GWL_WDML_INSTANCE);
779 /******************************************************************************
780 * DdeGetLastError [USER32.@] Gets most recent error code
782 * PARAMS
783 * idInst [I] Instance identifier
785 * RETURNS
786 * Last error code
788 UINT WINAPI DdeGetLastError(DWORD idInst)
790 DWORD error_code;
791 WDML_INSTANCE* pInstance;
793 EnterCriticalSection(&WDML_CritSect);
795 /* First check instance
797 pInstance = WDML_GetInstance(idInst);
798 if (pInstance == NULL)
800 error_code = DMLERR_INVALIDPARAMETER;
802 else
804 error_code = pInstance->lastError;
805 pInstance->lastError = 0;
808 LeaveCriticalSection(&WDML_CritSect);
809 return error_code;
812 /* ================================================================
814 * String management
816 * ================================================================ */
819 /******************************************************************
820 * WDML_FindNode
824 static HSZNode* WDML_FindNode(WDML_INSTANCE* pInstance, HSZ hsz)
826 HSZNode* pNode;
828 if (pInstance == NULL) return NULL;
830 for (pNode = pInstance->nodeList; pNode != NULL; pNode = pNode->next)
832 if (pNode->hsz == hsz) break;
834 if (!pNode) WARN("HSZ %p not found\n", hsz);
835 return pNode;
838 /******************************************************************
839 * WDML_MakeAtomFromHsz
841 * Creates a global atom from an existing HSZ
842 * Generally used before sending an HSZ as an atom to a remote app
844 ATOM WDML_MakeAtomFromHsz(HSZ hsz)
846 WCHAR nameBuffer[MAX_BUFFER_LEN];
848 if (GetAtomNameW(HSZ2ATOM(hsz), nameBuffer, MAX_BUFFER_LEN))
849 return GlobalAddAtomW(nameBuffer);
850 WARN("HSZ %p not found\n", hsz);
851 return 0;
854 /******************************************************************
855 * WDML_MakeHszFromAtom
857 * Creates a HSZ from an existing global atom
858 * Generally used while receiving a global atom and transforming it
859 * into an HSZ
861 HSZ WDML_MakeHszFromAtom(WDML_INSTANCE* pInstance, ATOM atom)
863 WCHAR nameBuffer[MAX_BUFFER_LEN];
865 if (!atom) return NULL;
867 if (GlobalGetAtomNameW(atom, nameBuffer, MAX_BUFFER_LEN))
869 TRACE("%x => %s\n", atom, debugstr_w(nameBuffer));
870 return DdeCreateStringHandleW(pInstance->instanceID, nameBuffer, CP_WINUNICODE);
872 WARN("ATOM 0x%x not found\n", atom);
873 return 0;
876 /******************************************************************
877 * WDML_IncHSZ
881 BOOL WDML_IncHSZ(WDML_INSTANCE* pInstance, HSZ hsz)
883 HSZNode* pNode;
885 pNode = WDML_FindNode(pInstance, hsz);
886 if (!pNode) return FALSE;
888 pNode->refCount++;
889 return TRUE;
892 /******************************************************************************
893 * WDML_DecHSZ (INTERNAL)
895 * Decrease the ref count of an HSZ. If it reaches 0, the node is removed from the list
896 * of HSZ nodes
897 * Returns -1 is the HSZ isn't found, otherwise it's the current (after --) of the ref count
899 BOOL WDML_DecHSZ(WDML_INSTANCE* pInstance, HSZ hsz)
901 HSZNode* pPrev = NULL;
902 HSZNode* pCurrent;
904 for (pCurrent = pInstance->nodeList; pCurrent != NULL; pCurrent = (pPrev = pCurrent)->next)
906 /* If we found the node we were looking for and its ref count is one,
907 * we can remove it
909 if (pCurrent->hsz == hsz)
911 if (--pCurrent->refCount == 0)
913 if (pCurrent == pInstance->nodeList)
915 pInstance->nodeList = pCurrent->next;
917 else
919 pPrev->next = pCurrent->next;
921 HeapFree(GetProcessHeap(), 0, pCurrent);
922 DeleteAtom(HSZ2ATOM(hsz));
924 return TRUE;
927 WARN("HSZ %p not found\n", hsz);
929 return FALSE;
932 /******************************************************************************
933 * WDML_FreeAllHSZ (INTERNAL)
935 * Frees up all the strings still allocated in the list and
936 * remove all the nodes from the list of HSZ nodes.
938 void WDML_FreeAllHSZ(WDML_INSTANCE* pInstance)
940 /* Free any strings created in this instance.
942 while (pInstance->nodeList != NULL)
944 DdeFreeStringHandle(pInstance->instanceID, pInstance->nodeList->hsz);
948 /******************************************************************************
949 * InsertHSZNode (INTERNAL)
951 * Insert a node to the head of the list.
953 static void WDML_InsertHSZNode(WDML_INSTANCE* pInstance, HSZ hsz)
955 if (hsz != 0)
957 HSZNode* pNew = NULL;
958 /* Create a new node for this HSZ.
960 pNew = (HSZNode*)HeapAlloc(GetProcessHeap(), 0, sizeof(HSZNode));
961 if (pNew != NULL)
963 pNew->hsz = hsz;
964 pNew->next = pInstance->nodeList;
965 pNew->refCount = 1;
966 pInstance->nodeList = pNew;
968 else
970 ERR("Primary HSZ Node allocation failed - out of memory\n");
975 /******************************************************************
976 * WDML_QueryString
980 static int WDML_QueryString(WDML_INSTANCE* pInstance, HSZ hsz, LPVOID ptr, DWORD cchMax,
981 int codepage)
983 WCHAR pString[MAX_BUFFER_LEN];
984 int ret;
985 /* If psz is null, we have to return only the length
986 * of the string.
988 if (ptr == NULL)
990 ptr = pString;
991 cchMax = MAX_BUFFER_LEN;
994 switch (codepage)
996 case CP_WINANSI:
997 ret = GetAtomNameA(HSZ2ATOM(hsz), ptr, cchMax);
998 break;
999 case CP_WINUNICODE:
1000 ret = GetAtomNameW(HSZ2ATOM(hsz), ptr, cchMax);
1001 break;
1002 default:
1003 ERR("Unknown code page %d\n", codepage);
1004 ret = 0;
1006 return ret;
1009 /*****************************************************************
1010 * DdeQueryStringA [USER32.@]
1012 DWORD WINAPI DdeQueryStringA(DWORD idInst, HSZ hsz, LPSTR psz, DWORD cchMax, INT iCodePage)
1014 DWORD ret = 0;
1015 WDML_INSTANCE* pInstance;
1017 TRACE("(%ld, %p, %p, %ld, %d)\n", idInst, hsz, psz, cchMax, iCodePage);
1019 EnterCriticalSection(&WDML_CritSect);
1021 /* First check instance
1023 pInstance = WDML_GetInstance(idInst);
1024 if (pInstance != NULL)
1026 if (iCodePage == 0) iCodePage = CP_WINANSI;
1027 ret = WDML_QueryString(pInstance, hsz, psz, cchMax, iCodePage);
1029 LeaveCriticalSection(&WDML_CritSect);
1031 TRACE("returning %ld (%s)\n", ret, debugstr_a(psz));
1032 return ret;
1035 /*****************************************************************
1036 * DdeQueryStringW [USER32.@]
1039 DWORD WINAPI DdeQueryStringW(DWORD idInst, HSZ hsz, LPWSTR psz, DWORD cchMax, INT iCodePage)
1041 DWORD ret = 0;
1042 WDML_INSTANCE* pInstance;
1044 TRACE("(%ld, %p, %p, %ld, %d)\n", idInst, hsz, psz, cchMax, iCodePage);
1046 EnterCriticalSection(&WDML_CritSect);
1048 /* First check instance
1050 pInstance = WDML_GetInstance(idInst);
1051 if (pInstance != NULL)
1053 if (iCodePage == 0) iCodePage = CP_WINUNICODE;
1054 ret = WDML_QueryString(pInstance, hsz, psz, cchMax, iCodePage);
1056 LeaveCriticalSection(&WDML_CritSect);
1058 TRACE("returning %ld (%s)\n", ret, debugstr_w(psz));
1059 return ret;
1062 /******************************************************************
1063 * DML_CreateString
1067 static HSZ WDML_CreateString(WDML_INSTANCE* pInstance, LPCVOID ptr, int codepage)
1069 HSZ hsz;
1071 switch (codepage)
1073 case CP_WINANSI:
1074 hsz = ATOM2HSZ(AddAtomA(ptr));
1075 TRACE("added atom %s with HSZ %p, \n", debugstr_a(ptr), hsz);
1076 break;
1077 case CP_WINUNICODE:
1078 hsz = ATOM2HSZ(AddAtomW(ptr));
1079 TRACE("added atom %s with HSZ %p, \n", debugstr_w(ptr), hsz);
1080 break;
1081 default:
1082 ERR("Unknown code page %d\n", codepage);
1083 return 0;
1085 WDML_InsertHSZNode(pInstance, hsz);
1086 return hsz;
1089 /*****************************************************************
1090 * DdeCreateStringHandleA [USER32.@]
1092 * RETURNS
1093 * Success: String handle
1094 * Failure: 0
1096 HSZ WINAPI DdeCreateStringHandleA(DWORD idInst, LPCSTR psz, INT codepage)
1098 HSZ hsz = 0;
1099 WDML_INSTANCE* pInstance;
1101 TRACE("(%ld,%s,%d)\n", idInst, debugstr_a(psz), codepage);
1103 EnterCriticalSection(&WDML_CritSect);
1105 pInstance = WDML_GetInstance(idInst);
1106 if (pInstance)
1108 if (codepage == 0) codepage = CP_WINANSI;
1109 hsz = WDML_CreateString(pInstance, psz, codepage);
1112 LeaveCriticalSection(&WDML_CritSect);
1113 return hsz;
1117 /******************************************************************************
1118 * DdeCreateStringHandleW [USER32.@] Creates handle to identify string
1120 * PARAMS
1121 * idInst [I] Instance identifier
1122 * psz [I] Pointer to string
1123 * codepage [I] Code page identifier
1124 * RETURNS
1125 * Success: String handle
1126 * Failure: 0
1128 HSZ WINAPI DdeCreateStringHandleW(DWORD idInst, LPCWSTR psz, INT codepage)
1130 WDML_INSTANCE* pInstance;
1131 HSZ hsz = 0;
1133 TRACE("(%ld,%s,%d)\n", idInst, debugstr_w(psz), codepage);
1135 EnterCriticalSection(&WDML_CritSect);
1137 pInstance = WDML_GetInstance(idInst);
1138 if (pInstance)
1140 if (codepage == 0) codepage = CP_WINUNICODE;
1141 hsz = WDML_CreateString(pInstance, psz, codepage);
1143 LeaveCriticalSection(&WDML_CritSect);
1145 return hsz;
1148 /*****************************************************************
1149 * DdeFreeStringHandle (USER32.@)
1150 * RETURNS: success: nonzero
1151 * fail: zero
1153 BOOL WINAPI DdeFreeStringHandle(DWORD idInst, HSZ hsz)
1155 WDML_INSTANCE* pInstance;
1156 BOOL ret = FALSE;
1158 TRACE("(%ld,%p): \n", idInst, hsz);
1160 EnterCriticalSection(&WDML_CritSect);
1162 /* First check instance
1164 pInstance = WDML_GetInstance(idInst);
1165 if (pInstance)
1166 ret = WDML_DecHSZ(pInstance, hsz);
1168 LeaveCriticalSection(&WDML_CritSect);
1170 return ret;
1173 /*****************************************************************
1174 * DdeKeepStringHandle (USER32.@)
1176 * RETURNS: success: nonzero
1177 * fail: zero
1179 BOOL WINAPI DdeKeepStringHandle(DWORD idInst, HSZ hsz)
1181 WDML_INSTANCE* pInstance;
1182 BOOL ret = FALSE;
1184 TRACE("(%ld,%p): \n", idInst, hsz);
1186 EnterCriticalSection(&WDML_CritSect);
1188 /* First check instance
1190 pInstance = WDML_GetInstance(idInst);
1191 if (pInstance)
1192 ret = WDML_IncHSZ(pInstance, hsz);
1194 LeaveCriticalSection(&WDML_CritSect);
1195 return ret;
1198 /*****************************************************************
1199 * DdeCmpStringHandles (USER32.@)
1201 * Compares the value of two string handles. This comparison is
1202 * not case sensitive.
1204 * Returns:
1205 * -1 The value of hsz1 is zero or less than hsz2
1206 * 0 The values of hsz 1 and 2 are the same or both zero.
1207 * 1 The value of hsz2 is zero of less than hsz1
1209 INT WINAPI DdeCmpStringHandles(HSZ hsz1, HSZ hsz2)
1211 WCHAR psz1[MAX_BUFFER_LEN];
1212 WCHAR psz2[MAX_BUFFER_LEN];
1213 int ret = 0;
1214 int ret1, ret2;
1216 ret1 = GetAtomNameW(HSZ2ATOM(hsz1), psz1, MAX_BUFFER_LEN);
1217 ret2 = GetAtomNameW(HSZ2ATOM(hsz2), psz2, MAX_BUFFER_LEN);
1219 TRACE("(%p<%s> %p<%s>);\n", hsz1, debugstr_w(psz1), hsz2, debugstr_w(psz2));
1221 /* Make sure we found both strings. */
1222 if (ret1 == 0 && ret2 == 0)
1224 /* If both are not found, return both "zero strings". */
1225 ret = 0;
1227 else if (ret1 == 0)
1229 /* If hsz1 is a not found, return hsz1 is "zero string". */
1230 ret = -1;
1232 else if (ret2 == 0)
1234 /* If hsz2 is a not found, return hsz2 is "zero string". */
1235 ret = 1;
1237 else
1239 /* Compare the two strings we got (case insensitive). */
1240 ret = lstrcmpiW(psz1, psz2);
1241 /* Since strcmp returns any number smaller than
1242 * 0 when the first string is found to be less than
1243 * the second one we must make sure we are returning
1244 * the proper values.
1246 if (ret < 0)
1248 ret = -1;
1250 else if (ret > 0)
1252 ret = 1;
1256 return ret;
1259 /* ================================================================
1261 * Data handle management
1263 * ================================================================ */
1265 /*****************************************************************
1266 * DdeCreateDataHandle (USER32.@)
1268 HDDEDATA WINAPI DdeCreateDataHandle(DWORD idInst, LPBYTE pSrc, DWORD cb, DWORD cbOff,
1269 HSZ hszItem, UINT wFmt, UINT afCmd)
1271 /* For now, we ignore idInst, hszItem.
1272 * The purpose of these arguments still need to be investigated.
1275 HGLOBAL hMem;
1276 LPBYTE pByte;
1277 DDE_DATAHANDLE_HEAD* pDdh;
1278 WCHAR psz[MAX_BUFFER_LEN];
1280 if (!GetAtomNameW(HSZ2ATOM(hszItem), psz, MAX_BUFFER_LEN))
1282 psz[0] = HSZ2ATOM(hszItem);
1283 psz[1] = 0;
1286 TRACE("(%ld,%p,cb %ld, cbOff %ld,%p <%s>,fmt %04x,%x)\n",
1287 idInst, pSrc, cb, cbOff, hszItem, debugstr_w(psz), wFmt, afCmd);
1289 if (afCmd != 0 && afCmd != HDATA_APPOWNED)
1290 return 0;
1292 /* we use the first 4 bytes to store the size */
1293 if (!(hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cb + cbOff + sizeof(DDE_DATAHANDLE_HEAD))))
1295 ERR("GlobalAlloc failed\n");
1296 return 0;
1299 pDdh = (DDE_DATAHANDLE_HEAD*)GlobalLock(hMem);
1300 if (!pDdh)
1302 GlobalFree(hMem);
1303 return 0;
1306 pDdh->cfFormat = wFmt;
1307 pDdh->bAppOwned = (afCmd == HDATA_APPOWNED);
1309 pByte = (LPBYTE)(pDdh + 1);
1310 if (pSrc)
1312 memcpy(pByte, pSrc + cbOff, cb);
1314 GlobalUnlock(hMem);
1316 TRACE("=> %p\n", hMem);
1317 return (HDDEDATA)hMem;
1320 /*****************************************************************
1322 * DdeAddData (USER32.@)
1324 HDDEDATA WINAPI DdeAddData(HDDEDATA hData, LPBYTE pSrc, DWORD cb, DWORD cbOff)
1326 DWORD old_sz, new_sz;
1327 LPBYTE pDst;
1329 TRACE("(%p,%p,cb %ld, cbOff %ld)\n", hData, pSrc, cb, cbOff);
1331 pDst = DdeAccessData(hData, &old_sz);
1332 if (!pDst) return 0;
1334 new_sz = cb + cbOff;
1335 if (new_sz > old_sz)
1337 DdeUnaccessData(hData);
1338 hData = GlobalReAlloc((HGLOBAL)hData, new_sz + sizeof(DDE_DATAHANDLE_HEAD),
1339 GMEM_MOVEABLE | GMEM_DDESHARE);
1340 pDst = DdeAccessData(hData, &old_sz);
1343 if (!pDst) return 0;
1345 memcpy(pDst + cbOff, pSrc, cb);
1346 DdeUnaccessData(hData);
1347 return hData;
1350 /******************************************************************************
1351 * DdeGetData [USER32.@] Copies data from DDE object to local buffer
1354 * PARAMS
1355 * hData [I] Handle to DDE object
1356 * pDst [I] Pointer to destination buffer
1357 * cbMax [I] Amount of data to copy
1358 * cbOff [I] Offset to beginning of data
1360 * RETURNS
1361 * Size of memory object associated with handle
1363 DWORD WINAPI DdeGetData(HDDEDATA hData, LPBYTE pDst, DWORD cbMax, DWORD cbOff)
1365 DWORD dwSize, dwRet;
1366 LPBYTE pByte;
1368 TRACE("(%p,%p,%ld,%ld)\n", hData, pDst, cbMax, cbOff);
1370 pByte = DdeAccessData(hData, &dwSize);
1372 if (pByte)
1374 if (!pDst)
1376 dwRet = dwSize;
1378 else if (cbOff + cbMax < dwSize)
1380 dwRet = cbMax;
1382 else if (cbOff < dwSize)
1384 dwRet = dwSize - cbOff;
1386 else
1388 dwRet = 0;
1390 if (pDst && dwRet != 0)
1392 memcpy(pDst, pByte + cbOff, dwRet);
1394 DdeUnaccessData(hData);
1396 else
1398 dwRet = 0;
1400 return dwRet;
1403 /*****************************************************************
1404 * DdeAccessData (USER32.@)
1406 LPBYTE WINAPI DdeAccessData(HDDEDATA hData, LPDWORD pcbDataSize)
1408 HGLOBAL hMem = (HGLOBAL)hData;
1409 DDE_DATAHANDLE_HEAD* pDdh;
1411 TRACE("(%p,%p)\n", hData, pcbDataSize);
1413 pDdh = (DDE_DATAHANDLE_HEAD*)GlobalLock(hMem);
1414 if (pDdh == NULL)
1416 ERR("Failed on GlobalLock(%p)\n", hMem);
1417 return 0;
1420 if (pcbDataSize != NULL)
1422 *pcbDataSize = GlobalSize(hMem) - sizeof(DDE_DATAHANDLE_HEAD);
1424 TRACE("=> %p (%lu) fmt %04x\n", pDdh + 1, GlobalSize(hMem) - sizeof(DDE_DATAHANDLE_HEAD), pDdh->cfFormat);
1425 return (LPBYTE)(pDdh + 1);
1428 /*****************************************************************
1429 * DdeUnaccessData (USER32.@)
1431 BOOL WINAPI DdeUnaccessData(HDDEDATA hData)
1433 HGLOBAL hMem = (HGLOBAL)hData;
1435 TRACE("(%p)\n", hData);
1437 GlobalUnlock(hMem);
1439 return TRUE;
1442 /*****************************************************************
1443 * DdeFreeDataHandle (USER32.@)
1445 BOOL WINAPI DdeFreeDataHandle(HDDEDATA hData)
1447 TRACE("(%p)\n", hData);
1448 return GlobalFree((HGLOBAL)hData) == 0;
1451 /******************************************************************
1452 * WDML_IsAppOwned
1456 BOOL WDML_IsAppOwned(HDDEDATA hData)
1458 DDE_DATAHANDLE_HEAD* pDdh;
1459 BOOL ret = FALSE;
1461 pDdh = (DDE_DATAHANDLE_HEAD*)GlobalLock((HGLOBAL)hData);
1462 if (pDdh != NULL)
1464 ret = pDdh->bAppOwned;
1465 GlobalUnlock((HGLOBAL)hData);
1467 return ret;
1470 /* ================================================================
1472 * Global <=> Data handle management
1474 * ================================================================ */
1476 /* Note: we use a DDEDATA, but layout of DDEDATA, DDEADVISE and DDEPOKE structures is similar:
1477 * offset size
1478 * (bytes) (bits) comment
1479 * 0 16 bit fields for options (release, ackreq, response...)
1480 * 2 16 clipboard format
1481 * 4 ? data to be used
1483 HDDEDATA WDML_Global2DataHandle(HGLOBAL hMem, WINE_DDEHEAD* p)
1485 DDEDATA* pDd;
1486 HDDEDATA ret = 0;
1487 DWORD size;
1489 if (hMem)
1491 pDd = GlobalLock(hMem);
1492 size = GlobalSize(hMem) - sizeof(WINE_DDEHEAD);
1493 if (pDd)
1495 if (p) memcpy(p, pDd, sizeof(WINE_DDEHEAD));
1496 switch (pDd->cfFormat)
1498 default:
1499 FIXME("Unsupported format (%04x) for data %p, passing raw information\n",
1500 pDd->cfFormat, hMem);
1501 /* fall thru */
1502 case 0:
1503 case CF_TEXT:
1504 ret = DdeCreateDataHandle(0, pDd->Value, size, 0, 0, pDd->cfFormat, 0);
1505 break;
1506 case CF_BITMAP:
1507 if (size >= sizeof(BITMAP))
1509 BITMAP* bmp = (BITMAP*)pDd->Value;
1510 int count = bmp->bmWidthBytes * bmp->bmHeight * bmp->bmPlanes;
1511 if (size >= sizeof(BITMAP) + count)
1513 HBITMAP hbmp;
1515 if ((hbmp = CreateBitmap(bmp->bmWidth, bmp->bmHeight,
1516 bmp->bmPlanes, bmp->bmBitsPixel,
1517 pDd->Value + sizeof(BITMAP))))
1519 ret = DdeCreateDataHandle(0, (LPBYTE)&hbmp, sizeof(hbmp),
1520 0, 0, CF_BITMAP, 0);
1522 else ERR("Can't create bmp\n");
1524 else
1526 ERR("Wrong count: %lu / %d\n", size, sizeof(BITMAP) + count);
1528 } else ERR("No bitmap header\n");
1529 break;
1531 GlobalUnlock(hMem);
1534 return ret;
1537 /******************************************************************
1538 * WDML_DataHandle2Global
1542 HGLOBAL WDML_DataHandle2Global(HDDEDATA hDdeData, BOOL fResponse, BOOL fRelease,
1543 BOOL fDeferUpd, BOOL fAckReq)
1545 DDE_DATAHANDLE_HEAD* pDdh;
1546 DWORD dwSize;
1547 HGLOBAL hMem = 0;
1549 dwSize = GlobalSize((HGLOBAL)hDdeData) - sizeof(DDE_DATAHANDLE_HEAD);
1550 pDdh = (DDE_DATAHANDLE_HEAD*)GlobalLock((HGLOBAL)hDdeData);
1551 if (dwSize && pDdh)
1553 WINE_DDEHEAD* wdh = NULL;
1555 switch (pDdh->cfFormat)
1557 default:
1558 FIXME("Unsupported format (%04x) for data %p, passing raw information\n",
1559 pDdh->cfFormat, hDdeData);
1560 /* fall thru */
1561 case 0:
1562 case CF_TEXT:
1563 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, sizeof(WINE_DDEHEAD) + dwSize);
1564 if (hMem && (wdh = GlobalLock(hMem)))
1566 memcpy(wdh + 1, pDdh + 1, dwSize);
1568 break;
1569 case CF_BITMAP:
1570 if (dwSize >= sizeof(HBITMAP))
1572 BITMAP bmp;
1573 DWORD count;
1574 HBITMAP hbmp = *(HBITMAP*)(pDdh + 1);
1576 if (GetObjectA(hbmp, sizeof(bmp), &bmp))
1578 count = bmp.bmWidthBytes * bmp.bmHeight;
1579 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
1580 sizeof(WINE_DDEHEAD) + sizeof(bmp) + count);
1581 if (hMem && (wdh = GlobalLock(hMem)))
1583 memcpy(wdh + 1, &bmp, sizeof(bmp));
1584 GetBitmapBits(hbmp, count, ((char*)(wdh + 1)) + sizeof(bmp));
1588 break;
1590 if (wdh)
1592 wdh->unused = 0;
1593 wdh->fResponse = fResponse;
1594 wdh->fRelease = fRelease;
1595 wdh->fDeferUpd = fDeferUpd;
1596 wdh->fAckReq = fAckReq;
1597 wdh->cfFormat = pDdh->cfFormat;
1598 GlobalUnlock(hMem);
1600 GlobalUnlock((HGLOBAL)hDdeData);
1603 return hMem;
1606 /* ================================================================
1608 * Server management
1610 * ================================================================ */
1612 /******************************************************************
1613 * WDML_AddServer
1617 WDML_SERVER* WDML_AddServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic)
1619 WDML_SERVER* pServer;
1620 char buf1[256];
1621 char buf2[256];
1623 pServer = (WDML_SERVER*)HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_SERVER));
1624 if (pServer == NULL) return NULL;
1626 WDML_IncHSZ(pInstance, pServer->hszService = hszService);
1628 DdeQueryStringA(pInstance->instanceID, hszService, buf1, sizeof(buf1), CP_WINANSI);
1629 snprintf(buf2, sizeof(buf2), "%s(0x%08lx)", buf1, GetCurrentProcessId());
1630 pServer->hszServiceSpec = DdeCreateStringHandleA(pInstance->instanceID, buf2, CP_WINANSI);
1632 pServer->atomService = WDML_MakeAtomFromHsz(pServer->hszService);
1633 pServer->atomServiceSpec = WDML_MakeAtomFromHsz(pServer->hszServiceSpec);
1635 pServer->filterOn = TRUE;
1637 pServer->next = pInstance->servers;
1638 pInstance->servers = pServer;
1639 return pServer;
1642 /******************************************************************
1643 * WDML_RemoveServer
1647 void WDML_RemoveServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic)
1649 WDML_SERVER* pPrev = NULL;
1650 WDML_SERVER* pServer = NULL;
1651 WDML_CONV* pConv;
1652 WDML_CONV* pConvNext;
1654 pServer = pInstance->servers;
1656 while (pServer != NULL)
1658 if (DdeCmpStringHandles(pServer->hszService, hszService) == 0)
1660 WDML_BroadcastDDEWindows(WDML_szEventClass, WM_WDML_UNREGISTER,
1661 pServer->atomService, pServer->atomServiceSpec);
1662 /* terminate all conversations for given topic */
1663 for (pConv = pInstance->convs[WDML_SERVER_SIDE]; pConv != NULL; pConv = pConvNext)
1665 pConvNext = pConv->next;
1666 if (DdeCmpStringHandles(pConv->hszService, hszService) == 0)
1668 WDML_RemoveConv(pConv, WDML_SERVER_SIDE);
1669 /* don't care about return code (whether client window is present or not) */
1670 PostMessageA(pConv->hwndClient, WM_DDE_TERMINATE, (WPARAM)pConv->hwndServer, 0L);
1673 if (pServer == pInstance->servers)
1675 pInstance->servers = pServer->next;
1677 else
1679 pPrev->next = pServer->next;
1682 DestroyWindow(pServer->hwndServer);
1683 WDML_DecHSZ(pInstance, pServer->hszServiceSpec);
1684 WDML_DecHSZ(pInstance, pServer->hszService);
1686 GlobalDeleteAtom(pServer->atomService);
1687 GlobalDeleteAtom(pServer->atomServiceSpec);
1689 HeapFree(GetProcessHeap(), 0, pServer);
1690 break;
1693 pPrev = pServer;
1694 pServer = pServer->next;
1698 /*****************************************************************************
1699 * WDML_FindServer
1701 * generic routine to return a pointer to the relevant ServiceNode
1702 * for a given service name, or NULL if the entry does not exist
1705 WDML_SERVER* WDML_FindServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic)
1707 WDML_SERVER* pServer;
1709 for (pServer = pInstance->servers; pServer != NULL; pServer = pServer->next)
1711 if (hszService == pServer->hszService)
1713 return pServer;
1716 TRACE("Service name missing\n");
1717 return NULL;
1720 /* ================================================================
1722 * Conversation management
1724 * ================================================================ */
1726 /******************************************************************
1727 * WDML_AddConv
1731 WDML_CONV* WDML_AddConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
1732 HSZ hszService, HSZ hszTopic, HWND hwndClient, HWND hwndServer)
1734 WDML_CONV* pConv;
1736 /* no converstation yet, add it */
1737 pConv = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_CONV));
1738 if (!pConv) return NULL;
1740 pConv->instance = pInstance;
1741 WDML_IncHSZ(pInstance, pConv->hszService = hszService);
1742 WDML_IncHSZ(pInstance, pConv->hszTopic = hszTopic);
1743 pConv->hwndServer = hwndServer;
1744 pConv->hwndClient = hwndClient;
1745 pConv->transactions = NULL;
1746 pConv->hUser = 0;
1747 pConv->wStatus = (side == WDML_CLIENT_SIDE) ? ST_CLIENT : 0L;
1748 /* check if both side of the conversation are of the same instance */
1749 if (GetWindowThreadProcessId(hwndClient, NULL) == GetWindowThreadProcessId(hwndServer, NULL) &&
1750 WDML_GetInstanceFromWnd(hwndClient) == WDML_GetInstanceFromWnd(hwndServer))
1752 pConv->wStatus |= ST_ISSELF;
1754 pConv->wConvst = XST_NULL;
1756 pConv->next = pInstance->convs[side];
1757 pInstance->convs[side] = pConv;
1759 return pConv;
1762 /******************************************************************
1763 * WDML_FindConv
1767 WDML_CONV* WDML_FindConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
1768 HSZ hszService, HSZ hszTopic)
1770 WDML_CONV* pCurrent = NULL;
1772 for (pCurrent = pInstance->convs[side]; pCurrent != NULL; pCurrent = pCurrent->next)
1774 if (DdeCmpStringHandles(pCurrent->hszService, hszService) == 0 &&
1775 DdeCmpStringHandles(pCurrent->hszTopic, hszTopic) == 0)
1777 return pCurrent;
1781 return NULL;
1784 /******************************************************************
1785 * WDML_RemoveConv
1789 void WDML_RemoveConv(WDML_CONV* pRef, WDML_SIDE side)
1791 WDML_CONV* pPrev = NULL;
1792 WDML_CONV* pCurrent;
1793 WDML_XACT* pXAct;
1794 WDML_XACT* pXActNext;
1795 HWND hWnd;
1797 if (!pRef)
1798 return;
1800 /* remove any pending transaction */
1801 for (pXAct = pRef->transactions; pXAct != NULL; pXAct = pXActNext)
1803 pXActNext = pXAct->next;
1804 WDML_FreeTransaction(pRef->instance, pXAct, TRUE);
1807 WDML_RemoveAllLinks(pRef->instance, pRef, side);
1809 /* FIXME: should we keep the window around ? it seems so (at least on client side
1810 * to let QueryConvInfo work after conv termination, but also to implement
1811 * DdeReconnect...
1813 /* destroy conversation window, but first remove pConv from hWnd.
1814 * this would help the wndProc do appropriate handling upon a WM_DESTROY message
1816 hWnd = (side == WDML_CLIENT_SIDE) ? pRef->hwndClient : pRef->hwndServer;
1817 SetWindowLongA(hWnd, GWL_WDML_CONVERSATION, 0);
1819 DestroyWindow((side == WDML_CLIENT_SIDE) ? pRef->hwndClient : pRef->hwndServer);
1821 WDML_DecHSZ(pRef->instance, pRef->hszService);
1822 WDML_DecHSZ(pRef->instance, pRef->hszTopic);
1824 for (pCurrent = pRef->instance->convs[side]; pCurrent != NULL; pCurrent = (pPrev = pCurrent)->next)
1826 if (pCurrent == pRef)
1828 if (pCurrent == pRef->instance->convs[side])
1830 pRef->instance->convs[side] = pCurrent->next;
1832 else
1834 pPrev->next = pCurrent->next;
1837 HeapFree(GetProcessHeap(), 0, pCurrent);
1838 break;
1843 /******************************************************************
1844 * WDML_EnableCallback
1846 static BOOL WDML_EnableCallback(WDML_CONV *pConv, UINT wCmd)
1848 if (wCmd == EC_DISABLE)
1850 FIXME("EC_DISABLE is not implemented\n");
1851 return TRUE;
1854 if (wCmd == EC_QUERYWAITING)
1855 return pConv->transactions ? TRUE : FALSE;
1857 if (wCmd != EC_ENABLEALL && wCmd != EC_ENABLEONE)
1859 FIXME("Unknown command code %04x\n", wCmd);
1860 return FALSE;
1863 while (pConv->transactions)
1865 WDML_XACT *pXAct = pConv->transactions;
1866 WDML_UnQueueTransaction(pConv, pXAct);
1868 if (pConv->wStatus & ST_CLIENT)
1870 /*WDML_ClientHandle(pConv, pXAct);*/
1871 FIXME("Client delayed transaction queue handling is not supported\n");
1873 else
1874 WDML_ServerHandle(pConv, pXAct);
1876 WDML_FreeTransaction(pConv->instance, pXAct, TRUE);
1878 if (wCmd == EC_ENABLEONE) break;
1880 return TRUE;
1883 /*****************************************************************
1884 * DdeEnableCallback (USER32.@)
1886 BOOL WINAPI DdeEnableCallback(DWORD idInst, HCONV hConv, UINT wCmd)
1888 BOOL ret = FALSE;
1889 WDML_CONV *pConv;
1891 TRACE("(%ld, %p, %04x)\n", idInst, hConv, wCmd);
1893 EnterCriticalSection(&WDML_CritSect);
1895 pConv = WDML_GetConv(hConv, TRUE);
1897 if (pConv && pConv->instance->instanceID == idInst)
1898 ret = WDML_EnableCallback(pConv, wCmd);
1900 LeaveCriticalSection(&WDML_CritSect);
1901 return ret;
1904 /******************************************************************
1905 * WDML_GetConv
1909 WDML_CONV* WDML_GetConv(HCONV hConv, BOOL checkConnected)
1911 WDML_CONV* pConv = (WDML_CONV*)hConv;
1913 /* FIXME: should do better checking */
1914 if (pConv == NULL) return NULL;
1916 if (checkConnected && !(pConv->wStatus & ST_CONNECTED))
1918 FIXME("found conv but ain't connected\n");
1919 return NULL;
1921 if (GetCurrentThreadId() != pConv->instance->threadID)
1923 FIXME("wrong thread ID\n");
1924 return NULL;
1927 return pConv;
1930 /******************************************************************
1931 * WDML_GetConvFromWnd
1935 WDML_CONV* WDML_GetConvFromWnd(HWND hWnd)
1937 return (WDML_CONV*)GetWindowLongA(hWnd, GWL_WDML_CONVERSATION);
1940 /******************************************************************
1941 * WDML_PostAck
1945 BOOL WDML_PostAck(WDML_CONV* pConv, WDML_SIDE side, WORD appRetCode,
1946 BOOL fBusy, BOOL fAck, UINT pmt, LPARAM lParam, UINT oldMsg)
1948 DDEACK ddeAck;
1949 HWND from, to;
1951 if (side == WDML_SERVER_SIDE)
1953 from = pConv->hwndServer;
1954 to = pConv->hwndClient;
1956 else
1958 to = pConv->hwndServer;
1959 from = pConv->hwndClient;
1962 ddeAck.bAppReturnCode = appRetCode;
1963 ddeAck.reserved = 0;
1964 ddeAck.fBusy = fBusy;
1965 ddeAck.fAck = fAck;
1967 TRACE("Posting a %s ack\n", ddeAck.fAck ? "positive" : "negative");
1969 lParam = (lParam) ? ReuseDDElParam(lParam, oldMsg, WM_DDE_ACK, *(WORD*)&ddeAck, pmt) :
1970 PackDDElParam(WM_DDE_ACK, *(WORD*)&ddeAck, pmt);
1971 if (!PostMessageA(to, WM_DDE_ACK, (WPARAM)from, lParam))
1973 pConv->wStatus &= ~ST_CONNECTED;
1974 FreeDDElParam(WM_DDE_ACK, lParam);
1975 return FALSE;
1977 return TRUE;
1980 /*****************************************************************
1981 * DdeSetUserHandle (USER32.@)
1983 BOOL WINAPI DdeSetUserHandle(HCONV hConv, DWORD id, DWORD hUser)
1985 WDML_CONV* pConv;
1986 BOOL ret = TRUE;
1988 TRACE("(%p,%lx,%lx)\n", hConv, id, hUser);
1990 EnterCriticalSection(&WDML_CritSect);
1992 pConv = WDML_GetConv(hConv, FALSE);
1993 if (pConv == NULL)
1995 ret = FALSE;
1996 goto theError;
1998 if (id == QID_SYNC)
2000 pConv->hUser = hUser;
2002 else
2004 WDML_XACT* pXAct;
2006 pXAct = WDML_FindTransaction(pConv, id);
2007 if (pXAct)
2009 pXAct->hUser = hUser;
2011 else
2013 pConv->instance->lastError = DMLERR_UNFOUND_QUEUE_ID;
2014 ret = FALSE;
2017 theError:
2018 LeaveCriticalSection(&WDML_CritSect);
2019 return ret;
2022 /******************************************************************
2023 * WDML_GetLocalConvInfo
2027 static BOOL WDML_GetLocalConvInfo(WDML_CONV* pConv, CONVINFO* ci, DWORD id)
2029 BOOL ret = TRUE;
2030 WDML_LINK* pLink;
2031 WDML_SIDE side;
2033 ci->hConvPartner = (pConv->wStatus & ST_ISLOCAL) ? (HCONV)((DWORD)pConv | 1) : 0;
2034 ci->hszSvcPartner = pConv->hszService;
2035 ci->hszServiceReq = pConv->hszService; /* FIXME: they shouldn't be the same, should they ? */
2036 ci->hszTopic = pConv->hszTopic;
2037 ci->wStatus = pConv->wStatus;
2039 side = (pConv->wStatus & ST_CLIENT) ? WDML_CLIENT_SIDE : WDML_SERVER_SIDE;
2041 for (pLink = pConv->instance->links[side]; pLink != NULL; pLink = pLink->next)
2043 if (pLink->hConv == (HCONV)pConv)
2045 ci->wStatus |= ST_ADVISE;
2046 break;
2050 /* FIXME: non handled status flags:
2051 ST_BLOCKED
2052 ST_BLOCKNEXT
2053 ST_INLIST
2056 ci->wConvst = pConv->wConvst; /* FIXME */
2058 ci->wLastError = 0; /* FIXME: note it's not the instance last error */
2059 ci->hConvList = 0;
2060 ci->ConvCtxt = pConv->convContext;
2061 if (ci->wStatus & ST_CLIENT)
2063 ci->hwnd = pConv->hwndClient;
2064 ci->hwndPartner = pConv->hwndServer;
2066 else
2068 ci->hwnd = pConv->hwndServer;
2069 ci->hwndPartner = pConv->hwndClient;
2071 if (id == QID_SYNC)
2073 ci->hUser = pConv->hUser;
2074 ci->hszItem = 0;
2075 ci->wFmt = 0;
2076 ci->wType = 0;
2078 else
2080 WDML_XACT* pXAct;
2082 pXAct = WDML_FindTransaction(pConv, id);
2083 if (pXAct)
2085 ci->hUser = pXAct->hUser;
2086 ci->hszItem = pXAct->hszItem;
2087 ci->wFmt = pXAct->wFmt;
2088 ci->wType = pXAct->wType;
2090 else
2092 ret = 0;
2093 pConv->instance->lastError = DMLERR_UNFOUND_QUEUE_ID;
2096 return ret;
2099 /******************************************************************
2100 * DdeQueryConvInfo (USER32.@)
2103 UINT WINAPI DdeQueryConvInfo(HCONV hConv, DWORD id, PCONVINFO lpConvInfo)
2105 UINT ret = lpConvInfo->cb;
2106 CONVINFO ci;
2107 WDML_CONV* pConv;
2109 TRACE("(%p,%lx,%p)\n", hConv, id, lpConvInfo);
2111 if (!hConv)
2113 FIXME("hConv is NULL\n");
2114 return 0;
2117 EnterCriticalSection(&WDML_CritSect);
2119 pConv = WDML_GetConv(hConv, FALSE);
2120 if (pConv != NULL && !WDML_GetLocalConvInfo(pConv, &ci, id))
2122 ret = 0;
2124 else if ((DWORD)hConv & 1)
2126 pConv = WDML_GetConv((HCONV)((DWORD)hConv & ~1), FALSE);
2127 if (pConv != NULL)
2129 FIXME("Request on remote conversation information is not implemented yet\n");
2130 ret = 0;
2133 LeaveCriticalSection(&WDML_CritSect);
2134 if (ret != 0)
2135 memcpy(lpConvInfo, &ci, min((size_t)lpConvInfo->cb, sizeof(ci)));
2136 return ret;
2139 /* ================================================================
2141 * Link (hot & warm) management
2143 * ================================================================ */
2145 /******************************************************************
2146 * WDML_AddLink
2150 void WDML_AddLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
2151 UINT wType, HSZ hszItem, UINT wFmt)
2153 WDML_LINK* pLink;
2155 pLink = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_LINK));
2156 if (pLink == NULL)
2158 ERR("OOM\n");
2159 return;
2162 pLink->hConv = hConv;
2163 pLink->transactionType = wType;
2164 WDML_IncHSZ(pInstance, pLink->hszItem = hszItem);
2165 pLink->uFmt = wFmt;
2166 pLink->next = pInstance->links[side];
2167 pInstance->links[side] = pLink;
2170 /******************************************************************
2171 * WDML_RemoveLink
2175 void WDML_RemoveLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
2176 HSZ hszItem, UINT uFmt)
2178 WDML_LINK* pPrev = NULL;
2179 WDML_LINK* pCurrent = NULL;
2181 pCurrent = pInstance->links[side];
2183 while (pCurrent != NULL)
2185 if (pCurrent->hConv == hConv &&
2186 DdeCmpStringHandles(pCurrent->hszItem, hszItem) == 0 &&
2187 pCurrent->uFmt == uFmt)
2189 if (pCurrent == pInstance->links[side])
2191 pInstance->links[side] = pCurrent->next;
2193 else
2195 pPrev->next = pCurrent->next;
2198 WDML_DecHSZ(pInstance, pCurrent->hszItem);
2199 HeapFree(GetProcessHeap(), 0, pCurrent);
2200 break;
2203 pPrev = pCurrent;
2204 pCurrent = pCurrent->next;
2208 /* this function is called to remove all links related to the conv.
2209 It should be called from both client and server when terminating
2210 the conversation.
2212 /******************************************************************
2213 * WDML_RemoveAllLinks
2217 void WDML_RemoveAllLinks(WDML_INSTANCE* pInstance, WDML_CONV* pConv, WDML_SIDE side)
2219 WDML_LINK* pPrev = NULL;
2220 WDML_LINK* pCurrent = NULL;
2221 WDML_LINK* pNext = NULL;
2223 pCurrent = pInstance->links[side];
2225 while (pCurrent != NULL)
2227 if (pCurrent->hConv == (HCONV)pConv)
2229 if (pCurrent == pInstance->links[side])
2231 pInstance->links[side] = pCurrent->next;
2232 pNext = pCurrent->next;
2234 else
2236 pPrev->next = pCurrent->next;
2237 pNext = pCurrent->next;
2240 WDML_DecHSZ(pInstance, pCurrent->hszItem);
2242 HeapFree(GetProcessHeap(), 0, pCurrent);
2243 pCurrent = NULL;
2246 if (pCurrent)
2248 pPrev = pCurrent;
2249 pCurrent = pCurrent->next;
2251 else
2253 pCurrent = pNext;
2258 /******************************************************************
2259 * WDML_FindLink
2263 WDML_LINK* WDML_FindLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
2264 HSZ hszItem, BOOL use_fmt, UINT uFmt)
2266 WDML_LINK* pCurrent = NULL;
2268 for (pCurrent = pInstance->links[side]; pCurrent != NULL; pCurrent = pCurrent->next)
2270 /* we don't need to check for transaction type as it can be altered */
2272 if (pCurrent->hConv == hConv &&
2273 DdeCmpStringHandles(pCurrent->hszItem, hszItem) == 0 &&
2274 (!use_fmt || pCurrent->uFmt == uFmt))
2276 break;
2281 return pCurrent;
2284 /* ================================================================
2286 * Transaction management
2288 * ================================================================ */
2290 /******************************************************************
2291 * WDML_AllocTransaction
2293 * Alloc a transaction structure for handling the message ddeMsg
2295 WDML_XACT* WDML_AllocTransaction(WDML_INSTANCE* pInstance, UINT ddeMsg,
2296 UINT wFmt, HSZ hszItem)
2298 WDML_XACT* pXAct;
2299 static WORD tid = 1; /* FIXME: wrap around */
2301 pXAct = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_XACT));
2302 if (!pXAct)
2304 pInstance->lastError = DMLERR_MEMORY_ERROR;
2305 return NULL;
2308 pXAct->xActID = tid++;
2309 pXAct->ddeMsg = ddeMsg;
2310 pXAct->hDdeData = 0;
2311 pXAct->hUser = 0;
2312 pXAct->next = NULL;
2313 pXAct->wType = 0;
2314 pXAct->wFmt = wFmt;
2315 if ((pXAct->hszItem = hszItem)) WDML_IncHSZ(pInstance, pXAct->hszItem);
2316 pXAct->atom = 0;
2317 pXAct->hMem = 0;
2318 pXAct->lParam = 0;
2320 return pXAct;
2323 /******************************************************************
2324 * WDML_QueueTransaction
2326 * Adds a transaction to the list of transaction
2328 void WDML_QueueTransaction(WDML_CONV* pConv, WDML_XACT* pXAct)
2330 WDML_XACT** pt;
2332 /* advance to last in queue */
2333 for (pt = &pConv->transactions; *pt != NULL; pt = &(*pt)->next);
2334 *pt = pXAct;
2337 /******************************************************************
2338 * WDML_UnQueueTransaction
2342 BOOL WDML_UnQueueTransaction(WDML_CONV* pConv, WDML_XACT* pXAct)
2344 WDML_XACT** pt;
2346 for (pt = &pConv->transactions; *pt; pt = &(*pt)->next)
2348 if (*pt == pXAct)
2350 *pt = pXAct->next;
2351 return TRUE;
2354 return FALSE;
2357 /******************************************************************
2358 * WDML_FreeTransaction
2362 void WDML_FreeTransaction(WDML_INSTANCE* pInstance, WDML_XACT* pXAct, BOOL doFreePmt)
2364 /* free pmt(s) in pXAct too. check against one for not deleting TRUE return values */
2365 if (doFreePmt && (DWORD)pXAct->hMem > 1)
2367 GlobalFree(pXAct->hMem);
2369 if (pXAct->hszItem) WDML_DecHSZ(pInstance, pXAct->hszItem);
2371 HeapFree(GetProcessHeap(), 0, pXAct);
2374 /******************************************************************
2375 * WDML_FindTransaction
2379 WDML_XACT* WDML_FindTransaction(WDML_CONV* pConv, DWORD tid)
2381 WDML_XACT* pXAct;
2383 tid = HIWORD(tid);
2384 for (pXAct = pConv->transactions; pXAct; pXAct = pXAct->next)
2386 if (pXAct->xActID == tid)
2387 break;
2389 return pXAct;
2392 /* ================================================================
2394 * Information broadcast across DDEML implementations
2396 * ================================================================ */
2398 struct tagWDML_BroadcastPmt
2400 LPCSTR clsName;
2401 UINT uMsg;
2402 WPARAM wParam;
2403 LPARAM lParam;
2406 /******************************************************************
2407 * WDML_BroadcastEnumProc
2411 static BOOL CALLBACK WDML_BroadcastEnumProc(HWND hWnd, LPARAM lParam)
2413 struct tagWDML_BroadcastPmt* s = (struct tagWDML_BroadcastPmt*)lParam;
2414 char buffer[128];
2416 if (GetClassNameA(hWnd, buffer, sizeof(buffer)) > 0 &&
2417 strcmp(buffer, s->clsName) == 0)
2419 PostMessageA(hWnd, s->uMsg, s->wParam, s->lParam);
2421 return TRUE;
2424 /******************************************************************
2425 * WDML_BroadcastDDEWindows
2429 void WDML_BroadcastDDEWindows(const char* clsName, UINT uMsg, WPARAM wParam, LPARAM lParam)
2431 struct tagWDML_BroadcastPmt s;
2433 s.clsName = clsName;
2434 s.uMsg = uMsg;
2435 s.wParam = wParam;
2436 s.lParam = lParam;
2437 EnumWindows(WDML_BroadcastEnumProc, (LPARAM)&s);