2001-06-23 01:02:48 +02:00
|
|
|
/*
|
|
|
|
* DDEML library
|
|
|
|
*
|
|
|
|
* Copyright 1997 Alexandre Julliard
|
|
|
|
* Copyright 1997 Len White
|
|
|
|
* Copyright 1999 Keith Matthews
|
|
|
|
* Copyright 2000 Corel
|
|
|
|
* Copyright 2001 Eric Pouech
|
2005-02-14 12:53:15 +01:00
|
|
|
* Copyright 2003, 2004, 2005 Dmitry Timoshkov
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-08-10 00:07:22 +02:00
|
|
|
#include <stdio.h>
|
2001-06-23 01:02:48 +02:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2001-06-23 01:02:48 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "dde.h"
|
|
|
|
#include "ddeml.h"
|
2001-09-14 02:24:39 +02:00
|
|
|
#include "win.h"
|
2005-06-09 12:21:31 +02:00
|
|
|
#include "dde_private.h"
|
2005-02-14 12:53:15 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-10-19 02:51:00 +02:00
|
|
|
/* convert between ATOM and HSZ avoiding compiler warnings */
|
|
|
|
#define ATOM2HSZ(atom) ((HSZ) (ULONG_PTR)(atom))
|
|
|
|
#define HSZ2ATOM(hsz) ((ATOM) (ULONG_PTR)(hsz))
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
static WDML_INSTANCE* WDML_InstanceList = NULL;
|
2005-07-06 12:36:28 +02:00
|
|
|
static LONG WDML_MaxInstanceID = 0; /* OK for present, have to worry about wrap-around later */
|
2005-02-14 12:53:15 +01:00
|
|
|
const WCHAR WDML_szEventClass[] = {'W','i','n','e','D','d','e','E','v','e','n','t','C','l','a','s','s',0};
|
2003-08-13 01:50:54 +02:00
|
|
|
|
2006-11-15 14:22:35 +01:00
|
|
|
/* protection for instance list */
|
|
|
|
static CRITICAL_SECTION WDML_CritSect;
|
2003-08-13 01:50:54 +02:00
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &WDML_CritSect,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": WDML_CritSect") }
|
2003-08-13 01:50:54 +02:00
|
|
|
};
|
2006-11-15 14:22:35 +01:00
|
|
|
static CRITICAL_SECTION WDML_CritSect = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Pure DDE (non DDEML) management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
2001-06-23 01:02:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* PackDDElParam (USER32.@)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* the packed lParam
|
|
|
|
*/
|
2003-05-20 01:27:16 +02:00
|
|
|
LPARAM WINAPI PackDDElParam(UINT msg, UINT_PTR uiLo, UINT_PTR uiHi)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-03-29 18:59:20 +01:00
|
|
|
HGLOBAL hMem;
|
2003-05-20 01:27:16 +02:00
|
|
|
UINT_PTR *params;
|
2002-03-29 18:59:20 +01:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_DDE_ACK:
|
|
|
|
case WM_DDE_ADVISE:
|
|
|
|
case WM_DDE_DATA:
|
|
|
|
case WM_DDE_POKE:
|
2003-05-20 01:27:16 +02:00
|
|
|
if (!(hMem = GlobalAlloc(GMEM_DDESHARE, sizeof(UINT_PTR) * 2)))
|
2002-03-29 18:59:20 +01:00
|
|
|
{
|
|
|
|
ERR("GlobalAlloc failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(params = GlobalLock(hMem)))
|
|
|
|
{
|
2002-11-22 22:22:14 +01:00
|
|
|
ERR("GlobalLock failed (%p)\n", hMem);
|
2002-03-29 18:59:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
params[0] = uiLo;
|
|
|
|
params[1] = uiHi;
|
|
|
|
GlobalUnlock(hMem);
|
|
|
|
return (LPARAM)hMem;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
case WM_DDE_EXECUTE:
|
|
|
|
return uiHi;
|
|
|
|
|
|
|
|
default:
|
2003-05-20 01:27:16 +02:00
|
|
|
return MAKELPARAM(uiLo, uiHi);
|
2002-03-29 18:59:20 +01:00
|
|
|
}
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* UnpackDDElParam (USER32.@)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* success: nonzero
|
|
|
|
* failure: zero
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnpackDDElParam(UINT msg, LPARAM lParam,
|
2003-05-20 01:27:16 +02:00
|
|
|
PUINT_PTR uiLo, PUINT_PTR uiHi)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2003-05-20 01:27:16 +02:00
|
|
|
UINT_PTR *params;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_DDE_ACK:
|
|
|
|
case WM_DDE_ADVISE:
|
|
|
|
case WM_DDE_DATA:
|
|
|
|
case WM_DDE_POKE:
|
2007-09-17 01:27:02 +02:00
|
|
|
if (!lParam || !(params = GlobalLock((HGLOBAL)lParam)))
|
2002-03-29 18:59:20 +01:00
|
|
|
{
|
2007-09-17 01:27:02 +02:00
|
|
|
if (uiLo) *uiLo = 0;
|
|
|
|
if (uiHi) *uiHi = 0;
|
2002-03-29 18:59:20 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (uiLo) *uiLo = params[0];
|
|
|
|
if (uiHi) *uiHi = params[1];
|
|
|
|
GlobalUnlock( (HGLOBAL)lParam );
|
|
|
|
return TRUE;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
case WM_DDE_EXECUTE:
|
|
|
|
if (uiLo) *uiLo = 0;
|
|
|
|
if (uiHi) *uiHi = lParam;
|
|
|
|
return TRUE;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
default:
|
|
|
|
if (uiLo) *uiLo = LOWORD(lParam);
|
|
|
|
if (uiHi) *uiHi = HIWORD(lParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* FreeDDElParam (USER32.@)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* success: nonzero
|
|
|
|
* failure: zero
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FreeDDElParam(UINT msg, LPARAM lParam)
|
|
|
|
{
|
2002-03-29 18:59:20 +01:00
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_DDE_ACK:
|
|
|
|
case WM_DDE_ADVISE:
|
|
|
|
case WM_DDE_DATA:
|
|
|
|
case WM_DDE_POKE:
|
|
|
|
/* first check if it's a global handle */
|
|
|
|
if (!GlobalHandle( (LPVOID)lParam )) return TRUE;
|
|
|
|
return !GlobalFree( (HGLOBAL)lParam );
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
default:
|
|
|
|
return TRUE;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* ReuseDDElParam (USER32.@)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* the packed lParam
|
|
|
|
*/
|
|
|
|
LPARAM WINAPI ReuseDDElParam(LPARAM lParam, UINT msgIn, UINT msgOut,
|
2003-05-20 01:27:16 +02:00
|
|
|
UINT_PTR uiLo, UINT_PTR uiHi)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2003-05-20 01:27:16 +02:00
|
|
|
UINT_PTR *params;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
switch (msgIn)
|
|
|
|
{
|
|
|
|
case WM_DDE_ACK:
|
|
|
|
case WM_DDE_ADVISE:
|
|
|
|
case WM_DDE_DATA:
|
|
|
|
case WM_DDE_POKE:
|
|
|
|
switch(msgOut)
|
|
|
|
{
|
|
|
|
case WM_DDE_ACK:
|
|
|
|
case WM_DDE_ADVISE:
|
|
|
|
case WM_DDE_DATA:
|
|
|
|
case WM_DDE_POKE:
|
|
|
|
if (!lParam) return 0;
|
|
|
|
if (!(params = GlobalLock( (HGLOBAL)lParam )))
|
|
|
|
{
|
|
|
|
ERR("GlobalLock failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
params[0] = uiLo;
|
|
|
|
params[1] = uiHi;
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("Reusing pack %08lx %08lx\n", uiLo, uiHi);
|
2005-06-30 20:11:37 +02:00
|
|
|
GlobalUnlock( (HGLOBAL)lParam );
|
2002-03-29 18:59:20 +01:00
|
|
|
return lParam;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
case WM_DDE_EXECUTE:
|
|
|
|
FreeDDElParam( msgIn, lParam );
|
|
|
|
return uiHi;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
default:
|
|
|
|
FreeDDElParam( msgIn, lParam );
|
2003-05-20 01:27:16 +02:00
|
|
|
return MAKELPARAM(uiLo, uiHi);
|
2002-03-29 18:59:20 +01:00
|
|
|
}
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-03-29 18:59:20 +01:00
|
|
|
default:
|
|
|
|
return PackDDElParam( msgOut, uiLo, uiHi );
|
|
|
|
}
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* ImpersonateDdeClientWindow (USER32.@)
|
|
|
|
*
|
2001-08-10 00:07:22 +02:00
|
|
|
* PARAMS
|
|
|
|
* hWndClient [I] handle to DDE client window
|
|
|
|
* hWndServer [I] handle to DDE server window
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
BOOL WINAPI ImpersonateDdeClientWindow(HWND hWndClient, HWND hWndServer)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-11-22 22:22:14 +01:00
|
|
|
FIXME("(%p %p): stub\n", hWndClient, hWndServer);
|
2001-06-23 01:02:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeSetQualityOfService (USER32.@)
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL WINAPI DdeSetQualityOfService(HWND hwndClient, CONST SECURITY_QUALITY_OF_SERVICE *pqosNew,
|
|
|
|
PSECURITY_QUALITY_OF_SERVICE pqosPrev)
|
|
|
|
{
|
2002-11-22 22:22:14 +01:00
|
|
|
FIXME("(%p %p %p): stub\n", hwndClient, pqosNew, pqosPrev);
|
2001-06-23 01:02:48 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Instance management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
2001-06-23 01:02:48 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* IncrementInstanceId
|
|
|
|
*
|
|
|
|
* generic routine to increment the max instance Id and allocate a new application instance
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
static void WDML_IncrementInstanceId(WDML_INSTANCE* pInstance)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
DWORD id = InterlockedIncrement(&WDML_MaxInstanceID);
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->instanceID = id;
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("New instance id %d allocated\n", id);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_EventProc
|
|
|
|
*
|
|
|
|
*
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
|
|
|
static LRESULT CALLBACK WDML_EventProc(HWND hwndEvent, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
|
|
|
HSZ hsz1, hsz2;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_WDML_REGISTER:
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance = WDML_GetInstanceFromWnd(hwndEvent);
|
2001-06-23 01:02:48 +02:00
|
|
|
/* try calling the Callback */
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pInstance && !(pInstance->CBFflags & CBF_SKIP_REGISTRATIONS))
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
hsz1 = WDML_MakeHszFromAtom(pInstance, wParam);
|
|
|
|
hsz2 = WDML_MakeHszFromAtom(pInstance, lParam);
|
|
|
|
WDML_InvokeCallback(pInstance, XTYP_REGISTER, 0, 0, hsz1, hsz2, 0, 0, 0);
|
|
|
|
WDML_DecHSZ(pInstance, hsz1);
|
|
|
|
WDML_DecHSZ(pInstance, hsz2);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_WDML_UNREGISTER:
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance = WDML_GetInstanceFromWnd(hwndEvent);
|
|
|
|
if (pInstance && !(pInstance->CBFflags & CBF_SKIP_UNREGISTRATIONS))
|
|
|
|
{
|
|
|
|
hsz1 = WDML_MakeHszFromAtom(pInstance, wParam);
|
|
|
|
hsz2 = WDML_MakeHszFromAtom(pInstance, lParam);
|
|
|
|
WDML_InvokeCallback(pInstance, XTYP_UNREGISTER, 0, 0, hsz1, hsz2, 0, 0, 0);
|
|
|
|
WDML_DecHSZ(pInstance, hsz1);
|
|
|
|
WDML_DecHSZ(pInstance, hsz2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_WDML_CONNECT_CONFIRM:
|
|
|
|
pInstance = WDML_GetInstanceFromWnd(hwndEvent);
|
|
|
|
if (pInstance && !(pInstance->CBFflags & CBF_SKIP_CONNECT_CONFIRMS))
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_CONV* pConv;
|
|
|
|
/* confirm connection...
|
|
|
|
* lookup for this conv handle
|
|
|
|
*/
|
2001-09-14 02:24:39 +02:00
|
|
|
HWND client = WIN_GetFullHandle( (HWND)wParam );
|
|
|
|
HWND server = WIN_GetFullHandle( (HWND)lParam );
|
2001-08-10 00:07:22 +02:00
|
|
|
for (pConv = pInstance->convs[WDML_SERVER_SIDE]; pConv != NULL; pConv = pConv->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-09-14 02:24:39 +02:00
|
|
|
if (pConv->hwndClient == client && pConv->hwndServer == server)
|
2001-08-10 00:07:22 +02:00
|
|
|
break;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pConv)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pConv->wStatus |= ST_ISLOCAL;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
WDML_InvokeCallback(pInstance, XTYP_CONNECT_CONFIRM, 0, (HCONV)pConv,
|
|
|
|
pConv->hszTopic, pConv->hszService, 0, 0,
|
2001-08-10 00:07:22 +02:00
|
|
|
(pConv->wStatus & ST_ISSELF) ? 1 : 0);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
2005-02-14 12:53:15 +01:00
|
|
|
return DefWindowProcW(hwndEvent, uMsg, wParam, lParam);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
return 0;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_Initialize
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
UINT WDML_Initialize(LPDWORD pidInst, PFNCALLBACK pfnCallback,
|
2005-07-08 13:33:09 +02:00
|
|
|
DWORD afCmd, DWORD ulRes, BOOL bUnicode, BOOL b16)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
2001-06-23 01:02:48 +02:00
|
|
|
WDML_INSTANCE* reference_inst;
|
|
|
|
UINT ret;
|
2005-02-14 12:53:15 +01:00
|
|
|
WNDCLASSEXW wndclass;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2008-08-05 14:14:01 +02:00
|
|
|
TRACE("(%p,%p,0x%x,%d,0x%x)\n",
|
|
|
|
pidInst, pfnCallback, afCmd, ulRes, bUnicode);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if (ulRes)
|
|
|
|
{
|
|
|
|
ERR("Reserved value not zero? What does this mean?\n");
|
|
|
|
/* trap this and no more until we know more */
|
|
|
|
return DMLERR_NO_ERROR;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* grab enough heap for one control struct - not really necessary for re-initialise
|
|
|
|
* but allows us to use same validation routines */
|
2005-03-24 22:01:35 +01:00
|
|
|
pInstance = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_INSTANCE));
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pInstance == NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/* catastrophe !! warn user & abort */
|
|
|
|
ERR("Instance create failed - out of memory\n");
|
|
|
|
return DMLERR_SYS_ERROR;
|
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->next = NULL;
|
|
|
|
pInstance->monitor = (afCmd | APPCLASS_MONITOR);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* messy bit, spec implies that 'Client Only' can be set in 2 different ways, catch 1 here */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->clientOnly = afCmd & APPCMD_CLIENTONLY;
|
|
|
|
pInstance->instanceID = *pidInst; /* May need to add calling proc Id */
|
|
|
|
pInstance->threadID = GetCurrentThreadId();
|
|
|
|
pInstance->callback = *pfnCallback;
|
2005-07-08 13:33:09 +02:00
|
|
|
pInstance->unicode = bUnicode;
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->win16 = b16;
|
|
|
|
pInstance->nodeList = NULL; /* node will be added later */
|
|
|
|
pInstance->monitorFlags = afCmd & MF_MASK;
|
2006-11-21 07:43:48 +01:00
|
|
|
pInstance->wStatus = 0;
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->servers = NULL;
|
|
|
|
pInstance->convs[0] = NULL;
|
|
|
|
pInstance->convs[1] = NULL;
|
|
|
|
pInstance->links[0] = NULL;
|
|
|
|
pInstance->links[1] = NULL;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
|
|
|
/* isolate CBF flags in one go, expect this will go the way of all attempts to be clever !! */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->CBFflags = afCmd^((afCmd&MF_MASK)|((afCmd&APPCMD_MASK)|(afCmd&APPCLASS_MASK)));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
if (!pInstance->clientOnly)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/* Check for other way of setting Client-only !! */
|
2002-06-01 01:06:46 +02:00
|
|
|
pInstance->clientOnly =
|
2001-08-10 00:07:22 +02:00
|
|
|
(pInstance->CBFflags & CBF_FAIL_ALLSVRXACTIONS) == CBF_FAIL_ALLSVRXACTIONS;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("instance created - checking validity\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (*pidInst == 0)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/* Initialisation of new Instance Identifier */
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("new instance, callback %p flags %X\n",pfnCallback,afCmd);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&WDML_CritSect);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (WDML_InstanceList == NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/* can't be another instance in this case, assign to the base pointer */
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_InstanceList = pInstance;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* since first must force filter of XTYP_CONNECT and XTYP_WILDCONNECT for
|
2002-06-01 01:06:46 +02:00
|
|
|
* present
|
2001-06-23 01:02:48 +02:00
|
|
|
* ------------------------------- NOTE NOTE NOTE --------------------------
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2001-06-23 01:02:48 +02:00
|
|
|
* the manual is not clear if this condition
|
2002-06-01 01:06:46 +02:00
|
|
|
* applies to the first call to DdeInitialize from an application, or the
|
2001-06-23 01:02:48 +02:00
|
|
|
* first call for a given callback !!!
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->CBFflags = pInstance->CBFflags|APPCMD_FILTERINITS;
|
2001-06-23 01:02:48 +02:00
|
|
|
TRACE("First application instance detected OK\n");
|
|
|
|
/* allocate new instance ID */
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_IncrementInstanceId(pInstance);
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
|
|
|
else
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/* really need to chain the new one in to the latest here, but after checking conditions
|
|
|
|
* such as trying to start a conversation from an application trying to monitor */
|
|
|
|
reference_inst = WDML_InstanceList;
|
|
|
|
TRACE("Subsequent application instance - starting checks\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
while (reference_inst->next != NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This set of tests will work if application uses same instance Id
|
|
|
|
* at application level once allocated - which is what manual implies
|
2002-06-01 01:06:46 +02:00
|
|
|
* should happen. If someone tries to be
|
2001-06-23 01:02:48 +02:00
|
|
|
* clever (lazy ?) it will fail to pick up that later calls are for
|
|
|
|
* the same application - should we trust them ?
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
if (pInstance->instanceID == reference_inst->instanceID)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
/* Check 1 - must be same Client-only state */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pInstance->clientOnly != reference_inst->clientOnly)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
ret = DMLERR_DLL_USAGE;
|
|
|
|
goto theError;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* Check 2 - cannot use 'Monitor' with any non-monitor modes */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (pInstance->monitor != reference_inst->monitor)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
ret = DMLERR_INVALIDPARAMETER;
|
|
|
|
goto theError;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* Check 3 - must supply different callback address */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pInstance->callback == reference_inst->callback)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
ret = DMLERR_DLL_USAGE;
|
|
|
|
goto theError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reference_inst = reference_inst->next;
|
|
|
|
}
|
|
|
|
/* All cleared, add to chain */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
TRACE("Application Instance checks finished\n");
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_IncrementInstanceId(pInstance);
|
|
|
|
reference_inst->next = pInstance;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
LeaveCriticalSection(&WDML_CritSect);
|
|
|
|
|
|
|
|
*pidInst = pInstance->instanceID;
|
|
|
|
|
|
|
|
/* for deadlock issues, windows must always be created when outside the critical section */
|
|
|
|
wndclass.cbSize = sizeof(wndclass);
|
|
|
|
wndclass.style = 0;
|
|
|
|
wndclass.lpfnWndProc = WDML_EventProc;
|
|
|
|
wndclass.cbClsExtra = 0;
|
2005-02-14 12:53:15 +01:00
|
|
|
wndclass.cbWndExtra = sizeof(ULONG_PTR);
|
2001-08-10 00:07:22 +02:00
|
|
|
wndclass.hInstance = 0;
|
|
|
|
wndclass.hIcon = 0;
|
|
|
|
wndclass.hCursor = 0;
|
|
|
|
wndclass.hbrBackground = 0;
|
|
|
|
wndclass.lpszMenuName = NULL;
|
|
|
|
wndclass.lpszClassName = WDML_szEventClass;
|
|
|
|
wndclass.hIconSm = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
RegisterClassExW(&wndclass);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
pInstance->hwndEvent = CreateWindowW(WDML_szEventClass, NULL,
|
2001-08-10 00:07:22 +02:00
|
|
|
WS_POPUP, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
SetWindowLongPtrW(pInstance->hwndEvent, GWL_WDML_INSTANCE, (ULONG_PTR)pInstance);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
TRACE("New application instance processing finished OK\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
|
|
|
else
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/* Reinitialisation situation --- FIX */
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("reinitialisation of (%p,%p,0x%x,%d): stub\n", pidInst, pfnCallback, afCmd, ulRes);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
EnterCriticalSection(&WDML_CritSect);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (WDML_InstanceList == NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2004-04-23 23:32:17 +02:00
|
|
|
ret = DMLERR_INVALIDPARAMETER;
|
2001-06-23 01:02:48 +02:00
|
|
|
goto theError;
|
|
|
|
}
|
|
|
|
/* can't reinitialise if we have initialised nothing !! */
|
|
|
|
reference_inst = WDML_InstanceList;
|
|
|
|
/* must first check if we have been given a valid instance to re-initialise !! how do we do that ? */
|
|
|
|
/*
|
|
|
|
* MS allows initialisation without specifying a callback, should we allow addition of the
|
|
|
|
* callback by a later call to initialise ? - if so this lot will have to change
|
|
|
|
*/
|
|
|
|
while (reference_inst->next != NULL)
|
|
|
|
{
|
|
|
|
if (*pidInst == reference_inst->instanceID && pfnCallback == reference_inst->callback)
|
|
|
|
{
|
|
|
|
/* Check 1 - cannot change client-only mode if set via APPCMD_CLIENTONLY */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if (reference_inst->clientOnly)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((reference_inst->CBFflags & CBF_FAIL_ALLSVRXACTIONS) != CBF_FAIL_ALLSVRXACTIONS)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/* i.e. Was set to Client-only and through APPCMD_CLIENTONLY */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if (!(afCmd & APPCMD_CLIENTONLY))
|
|
|
|
{
|
2004-04-23 23:32:17 +02:00
|
|
|
ret = DMLERR_INVALIDPARAMETER;
|
2001-06-23 01:02:48 +02:00
|
|
|
goto theError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Check 2 - cannot change monitor modes */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (pInstance->monitor != reference_inst->monitor)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2004-04-23 23:32:17 +02:00
|
|
|
ret = DMLERR_INVALIDPARAMETER;
|
2001-06-23 01:02:48 +02:00
|
|
|
goto theError;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* Check 3 - trying to set Client-only via APPCMD when not set so previously */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if ((afCmd&APPCMD_CLIENTONLY) && !reference_inst->clientOnly)
|
|
|
|
{
|
2004-04-23 23:32:17 +02:00
|
|
|
ret = DMLERR_INVALIDPARAMETER;
|
2001-06-23 01:02:48 +02:00
|
|
|
goto theError;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
reference_inst = reference_inst->next;
|
|
|
|
}
|
|
|
|
if (reference_inst->next == NULL)
|
|
|
|
{
|
|
|
|
ret = DMLERR_INVALIDPARAMETER;
|
|
|
|
goto theError;
|
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
/* All checked - change relevant flags */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
reference_inst->CBFflags = pInstance->CBFflags;
|
|
|
|
reference_inst->clientOnly = pInstance->clientOnly;
|
|
|
|
reference_inst->monitorFlags = pInstance->monitorFlags;
|
2008-06-17 22:21:55 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pInstance); /* finished - release heap space used as work store */
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
LeaveCriticalSection(&WDML_CritSect);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
return DMLERR_NO_ERROR;
|
|
|
|
theError:
|
2001-08-10 00:07:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pInstance);
|
|
|
|
LeaveCriticalSection(&WDML_CritSect);
|
2001-06-23 01:02:48 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* DdeInitializeA (USER32.@)
|
2005-11-09 11:33:40 +01:00
|
|
|
*
|
|
|
|
* See DdeInitializeW.
|
2001-08-10 00:07:22 +02:00
|
|
|
*/
|
|
|
|
UINT WINAPI DdeInitializeA(LPDWORD pidInst, PFNCALLBACK pfnCallback,
|
|
|
|
DWORD afCmd, DWORD ulRes)
|
|
|
|
{
|
2005-07-08 13:33:09 +02:00
|
|
|
return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, FALSE, FALSE);
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DdeInitializeW [USER32.@]
|
|
|
|
* Registers an application with the DDEML
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pidInst [I] Pointer to instance identifier
|
|
|
|
* pfnCallback [I] Pointer to callback function
|
|
|
|
* afCmd [I] Set of command and filter flags
|
|
|
|
* ulRes [I] Reserved
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: DMLERR_NO_ERROR
|
|
|
|
* Failure: DMLERR_DLL_USAGE, DMLERR_INVALIDPARAMETER, DMLERR_SYS_ERROR
|
|
|
|
*/
|
|
|
|
UINT WINAPI DdeInitializeW(LPDWORD pidInst, PFNCALLBACK pfnCallback,
|
|
|
|
DWORD afCmd, DWORD ulRes)
|
|
|
|
{
|
2005-07-08 13:33:09 +02:00
|
|
|
return WDML_Initialize(pidInst, pfnCallback, afCmd, ulRes, TRUE, FALSE);
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/*****************************************************************
|
|
|
|
* DdeUninitialize [USER32.@] Frees DDEML resources
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* idInst [I] Instance identifier
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL WINAPI DdeUninitialize(DWORD idInst)
|
|
|
|
{
|
|
|
|
/* Stage one - check if we have a handle for this instance
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
|
|
|
WDML_CONV* pConv;
|
|
|
|
WDML_CONV* pConvNext;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d)\n", idInst);
|
2003-05-20 01:27:16 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* First check instance
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance = WDML_GetInstance(idInst);
|
|
|
|
if (pInstance == NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Needs something here to record NOT_INITIALIZED ready for DdeGetLastError
|
|
|
|
*/
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
/* first terminate all conversations client side
|
|
|
|
* this shall close existing links...
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
for (pConv = pInstance->convs[WDML_CLIENT_SIDE]; pConv != NULL; pConv = pConvNext)
|
|
|
|
{
|
|
|
|
pConvNext = pConv->next;
|
|
|
|
DdeDisconnect((HCONV)pConv);
|
|
|
|
}
|
|
|
|
if (pInstance->convs[WDML_CLIENT_SIDE])
|
|
|
|
FIXME("still pending conversations\n");
|
|
|
|
|
|
|
|
/* then unregister all known service names */
|
|
|
|
DdeNameService(idInst, 0, 0, DNS_UNREGISTER);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* Free the nodes that were not freed by this instance
|
|
|
|
* and remove the nodes from the list of HSZ nodes.
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_FreeAllHSZ(pInstance);
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
DestroyWindow(pInstance->hwndEvent);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* OK now delete the instance handle itself */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
if (WDML_InstanceList == pInstance)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-01-18 20:30:15 +01:00
|
|
|
/* special case - the first/only entry */
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_InstanceList = pInstance->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-01-18 20:30:15 +01:00
|
|
|
/* general case, remove entry */
|
|
|
|
WDML_INSTANCE* inst;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-18 20:30:15 +01:00
|
|
|
for (inst = WDML_InstanceList; inst->next != pInstance; inst = inst->next);
|
|
|
|
inst->next = pInstance->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2006-11-15 14:22:35 +01:00
|
|
|
/* release the heap entry
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pInstance);
|
2006-11-15 14:22:35 +01:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_NotifyThreadExit
|
|
|
|
*
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
void WDML_NotifyThreadDetach(void)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
|
|
|
WDML_INSTANCE* next;
|
|
|
|
DWORD tid = GetCurrentThreadId();
|
|
|
|
|
|
|
|
EnterCriticalSection(&WDML_CritSect);
|
|
|
|
for (pInstance = WDML_InstanceList; pInstance != NULL; pInstance = next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
next = pInstance->next;
|
|
|
|
if (pInstance->threadID == tid)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2006-11-15 14:22:35 +01:00
|
|
|
LeaveCriticalSection(&WDML_CritSect);
|
2001-08-10 00:07:22 +02:00
|
|
|
DdeUninitialize(pInstance->instanceID);
|
2006-11-15 14:22:35 +01:00
|
|
|
EnterCriticalSection(&WDML_CritSect);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
LeaveCriticalSection(&WDML_CritSect);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_InvokeCallback
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
HDDEDATA WDML_InvokeCallback(WDML_INSTANCE* pInstance, UINT uType, UINT uFmt, HCONV hConv,
|
2002-06-01 01:06:46 +02:00
|
|
|
HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
|
2004-04-27 01:29:44 +02:00
|
|
|
ULONG_PTR dwData1, ULONG_PTR dwData2)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
HDDEDATA ret;
|
|
|
|
|
|
|
|
if (pInstance == NULL)
|
2002-12-02 19:10:57 +01:00
|
|
|
return NULL;
|
2006-11-15 14:22:35 +01:00
|
|
|
|
2003-05-20 01:27:16 +02:00
|
|
|
TRACE("invoking CB%d[%p] (%x %x %p %p %p %p %lx %lx)\n",
|
2002-11-22 22:22:14 +01:00
|
|
|
pInstance->win16 ? 16 : 32, pInstance->callback, uType, uFmt,
|
|
|
|
hConv, hsz1, hsz2, hdata, dwData1, dwData2);
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pInstance->win16)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
ret = WDML_InvokeCallback16(pInstance->callback, uType, uFmt, hConv,
|
2001-08-10 00:07:22 +02:00
|
|
|
hsz1, hsz2, hdata, dwData1, dwData2);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
else
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
ret = pInstance->callback(uType, uFmt, hConv, hsz1, hsz2, hdata, dwData1, dwData2);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2003-05-20 01:27:16 +02:00
|
|
|
TRACE("done => %p\n", ret);
|
2001-08-10 00:07:22 +02:00
|
|
|
return ret;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2001-08-10 00:07:22 +02:00
|
|
|
* WDML_GetInstance
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
|
|
|
* generic routine to return a pointer to the relevant DDE_HANDLE_ENTRY
|
|
|
|
* for an instance Id, or NULL if the entry does not exist
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* WDML_GetInstance(DWORD instId)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-11-15 14:22:35 +01:00
|
|
|
EnterCriticalSection(&WDML_CritSect);
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
for (pInstance = WDML_InstanceList; pInstance != NULL; pInstance = pInstance->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pInstance->instanceID == instId)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (GetCurrentThreadId() != pInstance->threadID)
|
|
|
|
{
|
|
|
|
FIXME("Tried to get instance from wrong thread\n");
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-15 14:22:35 +01:00
|
|
|
break;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
2006-11-15 14:22:35 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection(&WDML_CritSect);
|
|
|
|
|
|
|
|
if (!pInstance)
|
|
|
|
WARN("Instance entry missing for id %04x\n", instId);
|
|
|
|
return pInstance;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_GetInstanceFromWnd
|
|
|
|
*
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* WDML_GetInstanceFromWnd(HWND hWnd)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2005-02-14 12:53:15 +01:00
|
|
|
return (WDML_INSTANCE*)GetWindowLongPtrW(hWnd, GWL_WDML_INSTANCE);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-08-10 00:07:22 +02:00
|
|
|
* DdeGetLastError [USER32.@] Gets most recent error code
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* idInst [I] Instance identifier
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
2001-08-10 00:07:22 +02:00
|
|
|
* RETURNS
|
|
|
|
* Last error code
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
UINT WINAPI DdeGetLastError(DWORD idInst)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
DWORD error_code;
|
|
|
|
WDML_INSTANCE* pInstance;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* First check instance
|
|
|
|
*/
|
|
|
|
pInstance = WDML_GetInstance(idInst);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (pInstance == NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2004-04-23 23:32:17 +02:00
|
|
|
error_code = DMLERR_INVALIDPARAMETER;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
else
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
error_code = pInstance->lastError;
|
|
|
|
pInstance->lastError = 0;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
return error_code;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* ================================================================
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
2001-08-10 00:07:22 +02:00
|
|
|
* String management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_FindNode
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HSZNode* WDML_FindNode(WDML_INSTANCE* pInstance, HSZ hsz)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
HSZNode* pNode;
|
|
|
|
|
|
|
|
if (pInstance == NULL) return NULL;
|
|
|
|
|
|
|
|
for (pNode = pInstance->nodeList; pNode != NULL; pNode = pNode->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pNode->hsz == hsz) break;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-11-22 22:22:14 +01:00
|
|
|
if (!pNode) WARN("HSZ %p not found\n", hsz);
|
2001-08-10 00:07:22 +02:00
|
|
|
return pNode;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_MakeAtomFromHsz
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
2001-08-10 00:07:22 +02:00
|
|
|
* Creates a global atom from an existing HSZ
|
|
|
|
* Generally used before sending an HSZ as an atom to a remote app
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
ATOM WDML_MakeAtomFromHsz(HSZ hsz)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WCHAR nameBuffer[MAX_BUFFER_LEN];
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2002-10-19 02:51:00 +02:00
|
|
|
if (GetAtomNameW(HSZ2ATOM(hsz), nameBuffer, MAX_BUFFER_LEN))
|
2001-08-10 00:07:22 +02:00
|
|
|
return GlobalAddAtomW(nameBuffer);
|
2002-11-22 22:22:14 +01:00
|
|
|
WARN("HSZ %p not found\n", hsz);
|
2001-08-10 00:07:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_MakeHszFromAtom
|
|
|
|
*
|
|
|
|
* Creates a HSZ from an existing global atom
|
|
|
|
* Generally used while receiving a global atom and transforming it
|
|
|
|
* into an HSZ
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2007-11-14 22:48:17 +01:00
|
|
|
HSZ WDML_MakeHszFromAtom(const WDML_INSTANCE* pInstance, ATOM atom)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WCHAR nameBuffer[MAX_BUFFER_LEN];
|
|
|
|
|
2002-12-02 19:10:57 +01:00
|
|
|
if (!atom) return NULL;
|
2002-01-18 20:30:15 +01:00
|
|
|
|
|
|
|
if (GlobalGetAtomNameW(atom, nameBuffer, MAX_BUFFER_LEN))
|
|
|
|
{
|
|
|
|
TRACE("%x => %s\n", atom, debugstr_w(nameBuffer));
|
|
|
|
return DdeCreateStringHandleW(pInstance->instanceID, nameBuffer, CP_WINUNICODE);
|
|
|
|
}
|
|
|
|
WARN("ATOM 0x%x not found\n", atom);
|
|
|
|
return 0;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_IncHSZ
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WDML_IncHSZ(WDML_INSTANCE* pInstance, HSZ hsz)
|
|
|
|
{
|
|
|
|
HSZNode* pNode;
|
|
|
|
|
|
|
|
pNode = WDML_FindNode(pInstance, hsz);
|
|
|
|
if (!pNode) return FALSE;
|
|
|
|
|
|
|
|
pNode->refCount++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* WDML_DecHSZ (INTERNAL)
|
|
|
|
*
|
|
|
|
* Decrease the ref count of an HSZ. If it reaches 0, the node is removed from the list
|
|
|
|
* of HSZ nodes
|
|
|
|
* Returns -1 is the HSZ isn't found, otherwise it's the current (after --) of the ref count
|
|
|
|
*/
|
|
|
|
BOOL WDML_DecHSZ(WDML_INSTANCE* pInstance, HSZ hsz)
|
|
|
|
{
|
|
|
|
HSZNode* pPrev = NULL;
|
|
|
|
HSZNode* pCurrent;
|
|
|
|
|
|
|
|
for (pCurrent = pInstance->nodeList; pCurrent != NULL; pCurrent = (pPrev = pCurrent)->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
/* If we found the node we were looking for and its ref count is one,
|
|
|
|
* we can remove it
|
|
|
|
*/
|
|
|
|
if (pCurrent->hsz == hsz)
|
|
|
|
{
|
|
|
|
if (--pCurrent->refCount == 0)
|
|
|
|
{
|
|
|
|
if (pCurrent == pInstance->nodeList)
|
|
|
|
{
|
|
|
|
pInstance->nodeList = pCurrent->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pPrev->next = pCurrent->next;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, pCurrent);
|
2002-10-19 02:51:00 +02:00
|
|
|
DeleteAtom(HSZ2ATOM(hsz));
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-11-22 22:22:14 +01:00
|
|
|
WARN("HSZ %p not found\n", hsz);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* WDML_FreeAllHSZ (INTERNAL)
|
|
|
|
*
|
|
|
|
* Frees up all the strings still allocated in the list and
|
|
|
|
* remove all the nodes from the list of HSZ nodes.
|
|
|
|
*/
|
|
|
|
void WDML_FreeAllHSZ(WDML_INSTANCE* pInstance)
|
|
|
|
{
|
|
|
|
/* Free any strings created in this instance.
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
while (pInstance->nodeList != NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
DdeFreeStringHandle(pInstance->instanceID, pInstance->nodeList->hsz);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* InsertHSZNode (INTERNAL)
|
|
|
|
*
|
|
|
|
* Insert a node to the head of the list.
|
|
|
|
*/
|
|
|
|
static void WDML_InsertHSZNode(WDML_INSTANCE* pInstance, HSZ hsz)
|
|
|
|
{
|
|
|
|
if (hsz != 0)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
HSZNode* pNew = NULL;
|
|
|
|
/* Create a new node for this HSZ.
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2005-03-24 22:01:35 +01:00
|
|
|
pNew = HeapAlloc(GetProcessHeap(), 0, sizeof(HSZNode));
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pNew != NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pNew->hsz = hsz;
|
|
|
|
pNew->next = pInstance->nodeList;
|
|
|
|
pNew->refCount = 1;
|
|
|
|
pInstance->nodeList = pNew;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Primary HSZ Node allocation failed - out of memory\n");
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_QueryString
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static int WDML_QueryString(WDML_INSTANCE* pInstance, HSZ hsz, LPVOID ptr, DWORD cchMax,
|
2001-08-10 00:07:22 +02:00
|
|
|
int codepage)
|
|
|
|
{
|
|
|
|
WCHAR pString[MAX_BUFFER_LEN];
|
|
|
|
int ret;
|
|
|
|
/* If psz is null, we have to return only the length
|
|
|
|
* of the string.
|
|
|
|
*/
|
|
|
|
if (ptr == NULL)
|
|
|
|
{
|
|
|
|
ptr = pString;
|
|
|
|
cchMax = MAX_BUFFER_LEN;
|
|
|
|
}
|
|
|
|
|
2008-08-05 14:14:01 +02:00
|
|
|
/* if there is no input windows returns a NULL string */
|
|
|
|
if (hsz == NULL)
|
|
|
|
{
|
|
|
|
CHAR *t_ptr = ptr;
|
|
|
|
*t_ptr = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
switch (codepage)
|
|
|
|
{
|
|
|
|
case CP_WINANSI:
|
2002-10-19 02:51:00 +02:00
|
|
|
ret = GetAtomNameA(HSZ2ATOM(hsz), ptr, cchMax);
|
2001-08-10 00:07:22 +02:00
|
|
|
break;
|
|
|
|
case CP_WINUNICODE:
|
2002-10-19 02:51:00 +02:00
|
|
|
ret = GetAtomNameW(HSZ2ATOM(hsz), ptr, cchMax);
|
2004-04-23 23:32:17 +02:00
|
|
|
break;
|
2001-08-10 00:07:22 +02:00
|
|
|
default:
|
|
|
|
ERR("Unknown code page %d\n", codepage);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeQueryStringA [USER32.@]
|
|
|
|
*/
|
|
|
|
DWORD WINAPI DdeQueryStringA(DWORD idInst, HSZ hsz, LPSTR psz, DWORD cchMax, INT iCodePage)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
WDML_INSTANCE* pInstance;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d, %p, %p, %d, %d)\n", idInst, hsz, psz, cchMax, iCodePage);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
/* First check instance
|
2001-08-10 00:07:22 +02:00
|
|
|
*/
|
|
|
|
pInstance = WDML_GetInstance(idInst);
|
|
|
|
if (pInstance != NULL)
|
|
|
|
{
|
|
|
|
if (iCodePage == 0) iCodePage = CP_WINANSI;
|
|
|
|
ret = WDML_QueryString(pInstance, hsz, psz, cchMax, iCodePage);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("returning %d (%s)\n", ret, debugstr_a(psz));
|
2001-06-23 01:02:48 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeQueryStringW [USER32.@]
|
|
|
|
*/
|
|
|
|
|
|
|
|
DWORD WINAPI DdeQueryStringW(DWORD idInst, HSZ hsz, LPWSTR psz, DWORD cchMax, INT iCodePage)
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
DWORD ret = 0;
|
|
|
|
WDML_INSTANCE* pInstance;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d, %p, %p, %d, %d)\n", idInst, hsz, psz, cchMax, iCodePage);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
/* First check instance
|
2001-08-10 00:07:22 +02:00
|
|
|
*/
|
|
|
|
pInstance = WDML_GetInstance(idInst);
|
|
|
|
if (pInstance != NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (iCodePage == 0) iCodePage = CP_WINUNICODE;
|
|
|
|
ret = WDML_QueryString(pInstance, hsz, psz, cchMax, iCodePage);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("returning %d (%s)\n", ret, debugstr_w(psz));
|
2001-06-23 01:02:48 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/******************************************************************
|
|
|
|
* DML_CreateString
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HSZ WDML_CreateString(WDML_INSTANCE* pInstance, LPCVOID ptr, int codepage)
|
|
|
|
{
|
|
|
|
HSZ hsz;
|
|
|
|
|
|
|
|
switch (codepage)
|
|
|
|
{
|
|
|
|
case CP_WINANSI:
|
2002-10-19 02:51:00 +02:00
|
|
|
hsz = ATOM2HSZ(AddAtomA(ptr));
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("added atom %s with HSZ %p,\n", debugstr_a(ptr), hsz);
|
2001-08-10 00:07:22 +02:00
|
|
|
break;
|
|
|
|
case CP_WINUNICODE:
|
2002-10-19 02:51:00 +02:00
|
|
|
hsz = ATOM2HSZ(AddAtomW(ptr));
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("added atom %s with HSZ %p,\n", debugstr_w(ptr), hsz);
|
2001-08-10 00:07:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unknown code page %d\n", codepage);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
WDML_InsertHSZNode(pInstance, hsz);
|
|
|
|
return hsz;
|
|
|
|
}
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/*****************************************************************
|
|
|
|
* DdeCreateStringHandleA [USER32.@]
|
|
|
|
*
|
2005-11-09 11:33:40 +01:00
|
|
|
* See DdeCreateStringHandleW.
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
|
|
|
HSZ WINAPI DdeCreateStringHandleA(DWORD idInst, LPCSTR psz, INT codepage)
|
|
|
|
{
|
|
|
|
HSZ hsz = 0;
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d,%s,%d)\n", idInst, debugstr_a(psz), codepage);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance = WDML_GetInstance(idInst);
|
|
|
|
if (pInstance)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (codepage == 0) codepage = CP_WINANSI;
|
|
|
|
hsz = WDML_CreateString(pInstance, psz, codepage);
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return hsz;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DdeCreateStringHandleW [USER32.@] Creates handle to identify string
|
|
|
|
*
|
2001-08-10 00:07:22 +02:00
|
|
|
* PARAMS
|
|
|
|
* idInst [I] Instance identifier
|
|
|
|
* psz [I] Pointer to string
|
|
|
|
* codepage [I] Code page identifier
|
2001-06-23 01:02:48 +02:00
|
|
|
* RETURNS
|
|
|
|
* Success: String handle
|
|
|
|
* Failure: 0
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
HSZ WINAPI DdeCreateStringHandleW(DWORD idInst, LPCWSTR psz, INT codepage)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
2001-06-23 01:02:48 +02:00
|
|
|
HSZ hsz = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance = WDML_GetInstance(idInst);
|
|
|
|
if (pInstance)
|
2004-04-23 23:32:17 +02:00
|
|
|
{
|
|
|
|
if (codepage == 0) codepage = CP_WINUNICODE;
|
|
|
|
hsz = WDML_CreateString(pInstance, psz, codepage);
|
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
return hsz;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeFreeStringHandle (USER32.@)
|
2005-11-09 11:33:40 +01:00
|
|
|
* RETURNS
|
|
|
|
* success: nonzero
|
|
|
|
* fail: zero
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DdeFreeStringHandle(DWORD idInst, HSZ hsz)
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d,%p):\n", idInst, hsz);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
/* First check instance
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance = WDML_GetInstance(idInst);
|
|
|
|
if (pInstance)
|
|
|
|
ret = WDML_DecHSZ(pInstance, hsz);
|
|
|
|
|
|
|
|
return ret;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeKeepStringHandle (USER32.@)
|
|
|
|
*
|
2005-11-09 11:33:40 +01:00
|
|
|
* RETURNS
|
|
|
|
* success: nonzero
|
|
|
|
* fail: zero
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DdeKeepStringHandle(DWORD idInst, HSZ hsz)
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_INSTANCE* pInstance;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d,%p):\n", idInst, hsz);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* First check instance
|
|
|
|
*/
|
|
|
|
pInstance = WDML_GetInstance(idInst);
|
|
|
|
if (pInstance)
|
|
|
|
ret = WDML_IncHSZ(pInstance, hsz);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeCmpStringHandles (USER32.@)
|
|
|
|
*
|
|
|
|
* Compares the value of two string handles. This comparison is
|
|
|
|
* not case sensitive.
|
|
|
|
*
|
2005-11-09 11:33:40 +01:00
|
|
|
* PARAMS
|
|
|
|
* hsz1 [I] Handle to the first string
|
|
|
|
* hsz2 [I] Handle to the second string
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* -1 The value of hsz1 is zero or less than hsz2
|
|
|
|
* 0 The values of hsz 1 and 2 are the same or both zero.
|
|
|
|
* 1 The value of hsz2 is zero of less than hsz1
|
2001-08-10 00:07:22 +02:00
|
|
|
*/
|
|
|
|
INT WINAPI DdeCmpStringHandles(HSZ hsz1, HSZ hsz2)
|
|
|
|
{
|
|
|
|
WCHAR psz1[MAX_BUFFER_LEN];
|
|
|
|
WCHAR psz2[MAX_BUFFER_LEN];
|
|
|
|
int ret = 0;
|
|
|
|
int ret1, ret2;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-10-19 02:51:00 +02:00
|
|
|
ret1 = GetAtomNameW(HSZ2ATOM(hsz1), psz1, MAX_BUFFER_LEN);
|
|
|
|
ret2 = GetAtomNameW(HSZ2ATOM(hsz2), psz2, MAX_BUFFER_LEN);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2002-11-22 22:22:14 +01:00
|
|
|
TRACE("(%p<%s> %p<%s>);\n", hsz1, debugstr_w(psz1), hsz2, debugstr_w(psz2));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* Make sure we found both strings. */
|
|
|
|
if (ret1 == 0 && ret2 == 0)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
/* If both are not found, return both "zero strings". */
|
|
|
|
ret = 0;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
else if (ret1 == 0)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
/* If hsz1 is a not found, return hsz1 is "zero string". */
|
|
|
|
ret = -1;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
else if (ret2 == 0)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
/* If hsz2 is a not found, return hsz2 is "zero string". */
|
|
|
|
ret = 1;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2001-08-10 00:07:22 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Compare the two strings we got (case insensitive). */
|
|
|
|
ret = lstrcmpiW(psz1, psz2);
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Since strcmp returns any number smaller than
|
2001-08-10 00:07:22 +02:00
|
|
|
* 0 when the first string is found to be less than
|
|
|
|
* the second one we must make sure we are returning
|
|
|
|
* the proper values.
|
|
|
|
*/
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else if (ret > 0)
|
|
|
|
{
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
return ret;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Data handle management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/*****************************************************************
|
|
|
|
* DdeCreateDataHandle (USER32.@)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
HDDEDATA WINAPI DdeCreateDataHandle(DWORD idInst, LPBYTE pSrc, DWORD cb, DWORD cbOff,
|
2002-01-18 20:30:15 +01:00
|
|
|
HSZ hszItem, UINT wFmt, UINT afCmd)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-01-18 20:30:15 +01:00
|
|
|
/* For now, we ignore idInst, hszItem.
|
|
|
|
* The purpose of these arguments still need to be investigated.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
HGLOBAL hMem;
|
|
|
|
LPBYTE pByte;
|
|
|
|
DDE_DATAHANDLE_HEAD* pDdh;
|
2003-05-20 01:27:16 +02:00
|
|
|
WCHAR psz[MAX_BUFFER_LEN];
|
|
|
|
|
2005-02-01 19:47:55 +01:00
|
|
|
if (!GetAtomNameW(HSZ2ATOM(hszItem), psz, MAX_BUFFER_LEN))
|
|
|
|
{
|
|
|
|
psz[0] = HSZ2ATOM(hszItem);
|
|
|
|
psz[1] = 0;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d,%p,cb %d, cbOff %d,%p <%s>,fmt %04x,%x)\n",
|
2003-05-20 01:27:16 +02:00
|
|
|
idInst, pSrc, cb, cbOff, hszItem, debugstr_w(psz), wFmt, afCmd);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-18 20:30:15 +01:00
|
|
|
if (afCmd != 0 && afCmd != HDATA_APPOWNED)
|
|
|
|
return 0;
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* we use the first 4 bytes to store the size */
|
2003-05-20 01:27:16 +02:00
|
|
|
if (!(hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, cb + cbOff + sizeof(DDE_DATAHANDLE_HEAD))))
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
ERR("GlobalAlloc failed\n");
|
|
|
|
return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 23:35:56 +01:00
|
|
|
pDdh = GlobalLock(hMem);
|
2002-01-18 20:30:15 +01:00
|
|
|
if (!pDdh)
|
|
|
|
{
|
|
|
|
GlobalFree(hMem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
pDdh->cfFormat = wFmt;
|
2002-01-18 20:30:15 +01:00
|
|
|
pDdh->bAppOwned = (afCmd == HDATA_APPOWNED);
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
pByte = (LPBYTE)(pDdh + 1);
|
|
|
|
if (pSrc)
|
|
|
|
{
|
|
|
|
memcpy(pByte, pSrc + cbOff, cb);
|
|
|
|
}
|
|
|
|
GlobalUnlock(hMem);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-02-01 19:47:55 +01:00
|
|
|
TRACE("=> %p\n", hMem);
|
2001-06-23 01:02:48 +02:00
|
|
|
return (HDDEDATA)hMem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
*
|
|
|
|
* DdeAddData (USER32.@)
|
|
|
|
*/
|
|
|
|
HDDEDATA WINAPI DdeAddData(HDDEDATA hData, LPBYTE pSrc, DWORD cb, DWORD cbOff)
|
|
|
|
{
|
|
|
|
DWORD old_sz, new_sz;
|
2002-06-01 01:06:46 +02:00
|
|
|
LPBYTE pDst;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%p,%p,cb %d, cbOff %d)\n", hData, pSrc, cb, cbOff);
|
2003-05-20 01:27:16 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
pDst = DdeAccessData(hData, &old_sz);
|
|
|
|
if (!pDst) return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
new_sz = cb + cbOff;
|
|
|
|
if (new_sz > old_sz)
|
|
|
|
{
|
|
|
|
DdeUnaccessData(hData);
|
2007-12-29 01:05:07 +01:00
|
|
|
hData = GlobalReAlloc(hData, new_sz + sizeof(DDE_DATAHANDLE_HEAD),
|
2001-06-23 01:02:48 +02:00
|
|
|
GMEM_MOVEABLE | GMEM_DDESHARE);
|
|
|
|
pDst = DdeAccessData(hData, &old_sz);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if (!pDst) return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
memcpy(pDst + cbOff, pSrc, cb);
|
|
|
|
DdeUnaccessData(hData);
|
|
|
|
return hData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DdeGetData [USER32.@] Copies data from DDE object to local buffer
|
|
|
|
*
|
2001-08-10 00:07:22 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hData [I] Handle to DDE object
|
|
|
|
* pDst [I] Pointer to destination buffer
|
|
|
|
* cbMax [I] Amount of data to copy
|
|
|
|
* cbOff [I] Offset to beginning of data
|
|
|
|
*
|
2001-06-23 01:02:48 +02:00
|
|
|
* RETURNS
|
|
|
|
* Size of memory object associated with handle
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
DWORD WINAPI DdeGetData(HDDEDATA hData, LPBYTE pDst, DWORD cbMax, DWORD cbOff)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
DWORD dwSize, dwRet;
|
|
|
|
LPBYTE pByte;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%p,%p,%d,%d)\n", hData, pDst, cbMax, cbOff);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
pByte = DdeAccessData(hData, &dwSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (pByte)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-02-26 01:37:57 +01:00
|
|
|
if (!pDst)
|
|
|
|
{
|
|
|
|
dwRet = dwSize;
|
|
|
|
}
|
|
|
|
else if (cbOff + cbMax < dwSize)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
dwRet = cbMax;
|
|
|
|
}
|
|
|
|
else if (cbOff < dwSize)
|
|
|
|
{
|
|
|
|
dwRet = dwSize - cbOff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwRet = 0;
|
|
|
|
}
|
|
|
|
if (pDst && dwRet != 0)
|
|
|
|
{
|
|
|
|
memcpy(pDst, pByte + cbOff, dwRet);
|
|
|
|
}
|
|
|
|
DdeUnaccessData(hData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwRet = 0;
|
|
|
|
}
|
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeAccessData (USER32.@)
|
|
|
|
*/
|
|
|
|
LPBYTE WINAPI DdeAccessData(HDDEDATA hData, LPDWORD pcbDataSize)
|
|
|
|
{
|
2007-12-29 01:05:07 +01:00
|
|
|
HGLOBAL hMem = hData;
|
2001-06-23 01:02:48 +02:00
|
|
|
DDE_DATAHANDLE_HEAD* pDdh;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-05-20 01:27:16 +02:00
|
|
|
TRACE("(%p,%p)\n", hData, pcbDataSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-11-04 23:35:56 +01:00
|
|
|
pDdh = GlobalLock(hMem);
|
2001-06-23 01:02:48 +02:00
|
|
|
if (pDdh == NULL)
|
|
|
|
{
|
2002-11-22 22:22:14 +01:00
|
|
|
ERR("Failed on GlobalLock(%p)\n", hMem);
|
2001-06-23 01:02:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if (pcbDataSize != NULL)
|
|
|
|
{
|
|
|
|
*pcbDataSize = GlobalSize(hMem) - sizeof(DDE_DATAHANDLE_HEAD);
|
|
|
|
}
|
2005-02-01 19:47:55 +01:00
|
|
|
TRACE("=> %p (%lu) fmt %04x\n", pDdh + 1, GlobalSize(hMem) - sizeof(DDE_DATAHANDLE_HEAD), pDdh->cfFormat);
|
2001-06-23 01:02:48 +02:00
|
|
|
return (LPBYTE)(pDdh + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeUnaccessData (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DdeUnaccessData(HDDEDATA hData)
|
|
|
|
{
|
2007-12-29 01:05:07 +01:00
|
|
|
HGLOBAL hMem = hData;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-05-20 01:27:16 +02:00
|
|
|
TRACE("(%p)\n", hData);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
GlobalUnlock(hMem);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeFreeDataHandle (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DdeFreeDataHandle(HDDEDATA hData)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2003-05-20 01:27:16 +02:00
|
|
|
TRACE("(%p)\n", hData);
|
2007-12-29 01:05:07 +01:00
|
|
|
return GlobalFree(hData) == 0;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
2002-01-18 20:30:15 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_IsAppOwned
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WDML_IsAppOwned(HDDEDATA hData)
|
|
|
|
{
|
|
|
|
DDE_DATAHANDLE_HEAD* pDdh;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2008-11-04 23:35:56 +01:00
|
|
|
pDdh = GlobalLock(hData);
|
2002-01-18 20:30:15 +01:00
|
|
|
if (pDdh != NULL)
|
|
|
|
{
|
|
|
|
ret = pDdh->bAppOwned;
|
2007-12-29 01:05:07 +01:00
|
|
|
GlobalUnlock(hData);
|
2002-01-18 20:30:15 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Global <=> Data handle management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* Note: we use a DDEDATA, but layout of DDEDATA, DDEADVISE and DDEPOKE structures is similar:
|
2002-06-01 01:06:46 +02:00
|
|
|
* offset size
|
2001-06-23 01:02:48 +02:00
|
|
|
* (bytes) (bits) comment
|
|
|
|
* 0 16 bit fields for options (release, ackreq, response...)
|
|
|
|
* 2 16 clipboard format
|
|
|
|
* 4 ? data to be used
|
2001-08-10 00:07:22 +02:00
|
|
|
*/
|
|
|
|
HDDEDATA WDML_Global2DataHandle(HGLOBAL hMem, WINE_DDEHEAD* p)
|
|
|
|
{
|
|
|
|
DDEDATA* pDd;
|
|
|
|
HDDEDATA ret = 0;
|
2002-01-18 20:30:15 +01:00
|
|
|
DWORD size;
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
if (hMem)
|
|
|
|
{
|
|
|
|
pDd = GlobalLock(hMem);
|
2002-01-18 20:30:15 +01:00
|
|
|
size = GlobalSize(hMem) - sizeof(WINE_DDEHEAD);
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pDd)
|
|
|
|
{
|
|
|
|
if (p) memcpy(p, pDd, sizeof(WINE_DDEHEAD));
|
2002-01-18 20:30:15 +01:00
|
|
|
switch (pDd->cfFormat)
|
|
|
|
{
|
|
|
|
default:
|
2005-02-01 19:47:55 +01:00
|
|
|
FIXME("Unsupported format (%04x) for data %p, passing raw information\n",
|
|
|
|
pDd->cfFormat, hMem);
|
2002-01-18 20:30:15 +01:00
|
|
|
/* fall thru */
|
|
|
|
case 0:
|
|
|
|
case CF_TEXT:
|
|
|
|
ret = DdeCreateDataHandle(0, pDd->Value, size, 0, 0, pDd->cfFormat, 0);
|
|
|
|
break;
|
|
|
|
case CF_BITMAP:
|
|
|
|
if (size >= sizeof(BITMAP))
|
|
|
|
{
|
|
|
|
BITMAP* bmp = (BITMAP*)pDd->Value;
|
|
|
|
int count = bmp->bmWidthBytes * bmp->bmHeight * bmp->bmPlanes;
|
|
|
|
if (size >= sizeof(BITMAP) + count)
|
|
|
|
{
|
|
|
|
HBITMAP hbmp;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((hbmp = CreateBitmap(bmp->bmWidth, bmp->bmHeight,
|
2002-01-18 20:30:15 +01:00
|
|
|
bmp->bmPlanes, bmp->bmBitsPixel,
|
|
|
|
pDd->Value + sizeof(BITMAP))))
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
ret = DdeCreateDataHandle(0, (LPBYTE)&hbmp, sizeof(hbmp),
|
2002-01-18 20:30:15 +01:00
|
|
|
0, 0, CF_BITMAP, 0);
|
|
|
|
}
|
|
|
|
else ERR("Can't create bmp\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-30 00:25:15 +02:00
|
|
|
ERR("Wrong count: %u / %d\n", size, count);
|
2002-01-18 20:30:15 +01:00
|
|
|
}
|
|
|
|
} else ERR("No bitmap header\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GlobalUnlock(hMem);
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/******************************************************************
|
2001-08-10 00:07:22 +02:00
|
|
|
* WDML_DataHandle2Global
|
|
|
|
*
|
2001-06-23 01:02:48 +02:00
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
HGLOBAL WDML_DataHandle2Global(HDDEDATA hDdeData, BOOL fResponse, BOOL fRelease,
|
2001-08-10 00:07:22 +02:00
|
|
|
BOOL fDeferUpd, BOOL fAckReq)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
DDE_DATAHANDLE_HEAD* pDdh;
|
|
|
|
DWORD dwSize;
|
|
|
|
HGLOBAL hMem = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-18 20:30:15 +01:00
|
|
|
dwSize = GlobalSize((HGLOBAL)hDdeData) - sizeof(DDE_DATAHANDLE_HEAD);
|
2008-11-04 23:35:56 +01:00
|
|
|
pDdh = GlobalLock((HGLOBAL)hDdeData);
|
2001-08-10 00:07:22 +02:00
|
|
|
if (dwSize && pDdh)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-01-18 20:30:15 +01:00
|
|
|
WINE_DDEHEAD* wdh = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-18 20:30:15 +01:00
|
|
|
switch (pDdh->cfFormat)
|
|
|
|
{
|
|
|
|
default:
|
2005-02-01 19:47:55 +01:00
|
|
|
FIXME("Unsupported format (%04x) for data %p, passing raw information\n",
|
|
|
|
pDdh->cfFormat, hDdeData);
|
2002-01-18 20:30:15 +01:00
|
|
|
/* fall thru */
|
|
|
|
case 0:
|
|
|
|
case CF_TEXT:
|
|
|
|
hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, sizeof(WINE_DDEHEAD) + dwSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (hMem && (wdh = GlobalLock(hMem)))
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
|
|
|
memcpy(wdh + 1, pDdh + 1, dwSize);
|
|
|
|
}
|
2002-01-18 20:30:15 +01:00
|
|
|
break;
|
|
|
|
case CF_BITMAP:
|
|
|
|
if (dwSize >= sizeof(HBITMAP))
|
|
|
|
{
|
|
|
|
BITMAP bmp;
|
|
|
|
DWORD count;
|
|
|
|
HBITMAP hbmp = *(HBITMAP*)(pDdh + 1);
|
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
if (GetObjectW(hbmp, sizeof(bmp), &bmp))
|
2002-01-18 20:30:15 +01:00
|
|
|
{
|
|
|
|
count = bmp.bmWidthBytes * bmp.bmHeight;
|
2002-06-01 01:06:46 +02:00
|
|
|
hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
|
2002-01-18 20:30:15 +01:00
|
|
|
sizeof(WINE_DDEHEAD) + sizeof(bmp) + count);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (hMem && (wdh = GlobalLock(hMem)))
|
2002-01-18 20:30:15 +01:00
|
|
|
{
|
|
|
|
memcpy(wdh + 1, &bmp, sizeof(bmp));
|
|
|
|
GetBitmapBits(hbmp, count, ((char*)(wdh + 1)) + sizeof(bmp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
2002-01-18 20:30:15 +01:00
|
|
|
if (wdh)
|
|
|
|
{
|
2003-05-20 01:27:16 +02:00
|
|
|
wdh->unused = 0;
|
2002-01-18 20:30:15 +01:00
|
|
|
wdh->fResponse = fResponse;
|
|
|
|
wdh->fRelease = fRelease;
|
|
|
|
wdh->fDeferUpd = fDeferUpd;
|
|
|
|
wdh->fAckReq = fAckReq;
|
|
|
|
wdh->cfFormat = pDdh->cfFormat;
|
|
|
|
GlobalUnlock(hMem);
|
|
|
|
}
|
|
|
|
GlobalUnlock((HGLOBAL)hDdeData);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
return hMem;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Server management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_AddServer
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_SERVER* WDML_AddServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2005-02-14 12:53:15 +01:00
|
|
|
static const WCHAR fmtW[] = {'%','s','(','0','x','%','0','8','l','x',')',0};
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_SERVER* pServer;
|
2005-02-14 12:53:15 +01:00
|
|
|
WCHAR buf1[256];
|
|
|
|
WCHAR buf2[256];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
pServer = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_SERVER));
|
2001-06-23 01:02:48 +02:00
|
|
|
if (pServer == NULL) return NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
pServer->hszService = hszService;
|
|
|
|
WDML_IncHSZ(pInstance, hszService);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
DdeQueryStringW(pInstance->instanceID, hszService, buf1, 256, CP_WINUNICODE);
|
|
|
|
snprintfW(buf2, 256, fmtW, buf1, GetCurrentProcessId());
|
|
|
|
pServer->hszServiceSpec = DdeCreateStringHandleW(pInstance->instanceID, buf2, CP_WINUNICODE);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
pServer->atomService = WDML_MakeAtomFromHsz(pServer->hszService);
|
|
|
|
pServer->atomServiceSpec = WDML_MakeAtomFromHsz(pServer->hszServiceSpec);
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
pServer->filterOn = TRUE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pServer->next = pInstance->servers;
|
|
|
|
pInstance->servers = pServer;
|
2001-06-23 01:02:48 +02:00
|
|
|
return pServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_RemoveServer
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
void WDML_RemoveServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_SERVER* pPrev = NULL;
|
|
|
|
WDML_SERVER* pServer = NULL;
|
|
|
|
WDML_CONV* pConv;
|
|
|
|
WDML_CONV* pConvNext;
|
|
|
|
|
|
|
|
pServer = pInstance->servers;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
while (pServer != NULL)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (DdeCmpStringHandles(pServer->hszService, hszService) == 0)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
WDML_BroadcastDDEWindows(WDML_szEventClass, WM_WDML_UNREGISTER,
|
2001-08-10 00:07:22 +02:00
|
|
|
pServer->atomService, pServer->atomServiceSpec);
|
|
|
|
/* terminate all conversations for given topic */
|
|
|
|
for (pConv = pInstance->convs[WDML_SERVER_SIDE]; pConv != NULL; pConv = pConvNext)
|
|
|
|
{
|
|
|
|
pConvNext = pConv->next;
|
|
|
|
if (DdeCmpStringHandles(pConv->hszService, hszService) == 0)
|
|
|
|
{
|
2008-07-21 12:15:49 +02:00
|
|
|
HWND client = pConv->hwndClient, server = pConv->hwndServer;
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_RemoveConv(pConv, WDML_SERVER_SIDE);
|
|
|
|
/* don't care about return code (whether client window is present or not) */
|
2008-07-21 12:15:49 +02:00
|
|
|
PostMessageW(client, WM_DDE_TERMINATE, (WPARAM)server, 0);
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pServer == pInstance->servers)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->servers = pServer->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pPrev->next = pServer->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
DestroyWindow(pServer->hwndServer);
|
|
|
|
WDML_DecHSZ(pInstance, pServer->hszServiceSpec);
|
|
|
|
WDML_DecHSZ(pInstance, pServer->hszService);
|
|
|
|
|
|
|
|
GlobalDeleteAtom(pServer->atomService);
|
|
|
|
GlobalDeleteAtom(pServer->atomServiceSpec);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pServer);
|
2001-06-23 01:02:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pPrev = pServer;
|
|
|
|
pServer = pServer->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WDML_FindServer
|
|
|
|
*
|
|
|
|
* generic routine to return a pointer to the relevant ServiceNode
|
|
|
|
* for a given service name, or NULL if the entry does not exist
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_SERVER* WDML_FindServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
WDML_SERVER* pServer;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
for (pServer = pInstance->servers; pServer != NULL; pServer = pServer->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
if (hszService == pServer->hszService)
|
|
|
|
{
|
|
|
|
return pServer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("Service name missing\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Conversation management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_AddConv
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_CONV* WDML_AddConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
|
2001-06-23 01:02:48 +02:00
|
|
|
HSZ hszService, HSZ hszTopic, HWND hwndClient, HWND hwndServer)
|
|
|
|
{
|
|
|
|
WDML_CONV* pConv;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-01-16 12:20:50 +01:00
|
|
|
/* no conversation yet, add it */
|
2001-06-23 01:02:48 +02:00
|
|
|
pConv = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_CONV));
|
|
|
|
if (!pConv) return NULL;
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
pConv->instance = pInstance;
|
|
|
|
WDML_IncHSZ(pInstance, pConv->hszService = hszService);
|
|
|
|
WDML_IncHSZ(pInstance, pConv->hszTopic = hszTopic);
|
2005-09-20 13:39:19 +02:00
|
|
|
pConv->magic = WDML_CONV_MAGIC;
|
2001-06-23 01:02:48 +02:00
|
|
|
pConv->hwndServer = hwndServer;
|
|
|
|
pConv->hwndClient = hwndClient;
|
|
|
|
pConv->transactions = NULL;
|
|
|
|
pConv->hUser = 0;
|
2001-08-10 00:07:22 +02:00
|
|
|
pConv->wStatus = (side == WDML_CLIENT_SIDE) ? ST_CLIENT : 0L;
|
2006-11-21 07:43:48 +01:00
|
|
|
pConv->wStatus |= pInstance->wStatus;
|
2001-08-10 00:07:22 +02:00
|
|
|
/* check if both side of the conversation are of the same instance */
|
|
|
|
if (GetWindowThreadProcessId(hwndClient, NULL) == GetWindowThreadProcessId(hwndServer, NULL) &&
|
|
|
|
WDML_GetInstanceFromWnd(hwndClient) == WDML_GetInstanceFromWnd(hwndServer))
|
|
|
|
{
|
|
|
|
pConv->wStatus |= ST_ISSELF;
|
|
|
|
}
|
|
|
|
pConv->wConvst = XST_NULL;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pConv->next = pInstance->convs[side];
|
|
|
|
pInstance->convs[side] = pConv;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-09-04 12:31:03 +02:00
|
|
|
TRACE("pConv->wStatus %04x pInstance(%p)\n", pConv->wStatus, pInstance);
|
2006-11-21 07:43:48 +01:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
return pConv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_FindConv
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
WDML_CONV* WDML_FindConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
|
2001-06-23 01:02:48 +02:00
|
|
|
HSZ hszService, HSZ hszTopic)
|
|
|
|
{
|
|
|
|
WDML_CONV* pCurrent = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
for (pCurrent = pInstance->convs[side]; pCurrent != NULL; pCurrent = pCurrent->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
if (DdeCmpStringHandles(pCurrent->hszService, hszService) == 0 &&
|
|
|
|
DdeCmpStringHandles(pCurrent->hszTopic, hszTopic) == 0)
|
|
|
|
{
|
|
|
|
return pCurrent;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_RemoveConv
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
void WDML_RemoveConv(WDML_CONV* pRef, WDML_SIDE side)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_CONV* pPrev = NULL;
|
|
|
|
WDML_CONV* pCurrent;
|
|
|
|
WDML_XACT* pXAct;
|
|
|
|
WDML_XACT* pXActNext;
|
|
|
|
HWND hWnd;
|
2001-06-23 01:02:48 +02:00
|
|
|
|
|
|
|
if (!pRef)
|
|
|
|
return;
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
/* remove any pending transaction */
|
|
|
|
for (pXAct = pRef->transactions; pXAct != NULL; pXAct = pXActNext)
|
|
|
|
{
|
|
|
|
pXActNext = pXAct->next;
|
|
|
|
WDML_FreeTransaction(pRef->instance, pXAct, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
WDML_RemoveAllLinks(pRef->instance, pRef, side);
|
|
|
|
|
|
|
|
/* FIXME: should we keep the window around ? it seems so (at least on client side
|
|
|
|
* to let QueryConvInfo work after conv termination, but also to implement
|
|
|
|
* DdeReconnect...
|
|
|
|
*/
|
|
|
|
/* destroy conversation window, but first remove pConv from hWnd.
|
|
|
|
* this would help the wndProc do appropriate handling upon a WM_DESTROY message
|
|
|
|
*/
|
|
|
|
hWnd = (side == WDML_CLIENT_SIDE) ? pRef->hwndClient : pRef->hwndServer;
|
2005-02-14 12:53:15 +01:00
|
|
|
SetWindowLongPtrW(hWnd, GWL_WDML_CONVERSATION, 0);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
|
|
|
DestroyWindow((side == WDML_CLIENT_SIDE) ? pRef->hwndClient : pRef->hwndServer);
|
|
|
|
|
|
|
|
WDML_DecHSZ(pRef->instance, pRef->hszService);
|
|
|
|
WDML_DecHSZ(pRef->instance, pRef->hszTopic);
|
|
|
|
|
|
|
|
for (pCurrent = pRef->instance->convs[side]; pCurrent != NULL; pCurrent = (pPrev = pCurrent)->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
if (pCurrent == pRef)
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pCurrent == pRef->instance->convs[side])
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pRef->instance->convs[side] = pCurrent->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pPrev->next = pCurrent->next;
|
|
|
|
}
|
2005-09-20 13:39:19 +02:00
|
|
|
pCurrent->magic = 0;
|
2001-06-23 01:02:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pCurrent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-20 01:27:16 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_EnableCallback
|
|
|
|
*/
|
|
|
|
static BOOL WDML_EnableCallback(WDML_CONV *pConv, UINT wCmd)
|
|
|
|
{
|
|
|
|
if (wCmd == EC_DISABLE)
|
|
|
|
{
|
2006-11-21 07:43:48 +01:00
|
|
|
pConv->wStatus |= ST_BLOCKED;
|
|
|
|
TRACE("EC_DISABLE: conv %p status flags %04x\n", pConv, pConv->wStatus);
|
2003-05-20 01:27:16 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wCmd == EC_QUERYWAITING)
|
|
|
|
return pConv->transactions ? TRUE : FALSE;
|
|
|
|
|
|
|
|
if (wCmd != EC_ENABLEALL && wCmd != EC_ENABLEONE)
|
|
|
|
{
|
|
|
|
FIXME("Unknown command code %04x\n", wCmd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-11-21 07:43:48 +01:00
|
|
|
if (wCmd == EC_ENABLEALL)
|
|
|
|
{
|
|
|
|
pConv->wStatus &= ~ST_BLOCKED;
|
|
|
|
TRACE("EC_ENABLEALL: conv %p status flags %04x\n", pConv, pConv->wStatus);
|
|
|
|
}
|
|
|
|
|
2003-05-20 01:27:16 +02:00
|
|
|
while (pConv->transactions)
|
|
|
|
{
|
|
|
|
WDML_XACT *pXAct = pConv->transactions;
|
|
|
|
|
|
|
|
if (pConv->wStatus & ST_CLIENT)
|
|
|
|
{
|
2006-11-21 07:43:48 +01:00
|
|
|
/* transaction should be in the queue until handled */
|
|
|
|
WDML_ClientHandle(pConv, pXAct, 0, NULL);
|
|
|
|
WDML_UnQueueTransaction(pConv, pXAct);
|
2003-05-20 01:27:16 +02:00
|
|
|
}
|
|
|
|
else
|
2006-11-21 07:43:48 +01:00
|
|
|
{
|
|
|
|
/* transaction should be removed from the queue before handling */
|
|
|
|
WDML_UnQueueTransaction(pConv, pXAct);
|
2003-05-20 01:27:16 +02:00
|
|
|
WDML_ServerHandle(pConv, pXAct);
|
2006-11-21 07:43:48 +01:00
|
|
|
}
|
2003-05-20 01:27:16 +02:00
|
|
|
|
|
|
|
WDML_FreeTransaction(pConv->instance, pXAct, TRUE);
|
|
|
|
|
|
|
|
if (wCmd == EC_ENABLEONE) break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/*****************************************************************
|
|
|
|
* DdeEnableCallback (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DdeEnableCallback(DWORD idInst, HCONV hConv, UINT wCmd)
|
|
|
|
{
|
2003-05-20 01:27:16 +02:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
WDML_CONV *pConv;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%d, %p, %04x)\n", idInst, hConv, wCmd);
|
2003-05-20 01:27:16 +02:00
|
|
|
|
2006-11-21 07:43:48 +01:00
|
|
|
if (hConv)
|
|
|
|
{
|
|
|
|
pConv = WDML_GetConv(hConv, TRUE);
|
|
|
|
|
|
|
|
if (pConv && pConv->instance->instanceID == idInst)
|
|
|
|
ret = WDML_EnableCallback(pConv, wCmd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WDML_INSTANCE *pInstance = WDML_GetInstance(idInst);
|
2003-05-20 01:27:16 +02:00
|
|
|
|
2006-11-21 07:43:48 +01:00
|
|
|
if (!pInstance)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
TRACE("adding flags %04x to instance %p\n", wCmd, pInstance);
|
|
|
|
pInstance->wStatus |= wCmd;
|
|
|
|
|
|
|
|
if (wCmd == EC_DISABLE)
|
|
|
|
{
|
|
|
|
pInstance->wStatus |= ST_BLOCKED;
|
|
|
|
TRACE("EC_DISABLE: inst %p status flags %04x\n", pInstance, pInstance->wStatus);
|
|
|
|
}
|
|
|
|
else if (wCmd == EC_ENABLEALL)
|
|
|
|
{
|
|
|
|
pInstance->wStatus &= ~ST_BLOCKED;
|
|
|
|
TRACE("EC_ENABLEALL: inst %p status flags %04x\n", pInstance, pInstance->wStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
for (pConv = pInstance->convs[WDML_CLIENT_SIDE]; pConv != NULL; pConv = pConv->next)
|
|
|
|
{
|
|
|
|
ret = WDML_EnableCallback(pConv, wCmd);
|
|
|
|
if (ret && wCmd == EC_QUERYWAITING) break;
|
|
|
|
}
|
|
|
|
}
|
2003-05-20 01:27:16 +02:00
|
|
|
|
|
|
|
return ret;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WDML_GetConv
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2001-06-23 01:02:48 +02:00
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_CONV* WDML_GetConv(HCONV hConv, BOOL checkConnected)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_CONV* pConv = (WDML_CONV*)hConv;
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* FIXME: should do better checking */
|
2005-09-20 13:39:19 +02:00
|
|
|
if (pConv == NULL || pConv->magic != WDML_CONV_MAGIC) return NULL;
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2006-11-15 14:22:35 +01:00
|
|
|
if (!pConv->instance || pConv->instance->threadID != GetCurrentThreadId())
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
2006-11-15 14:22:35 +01:00
|
|
|
WARN("wrong thread ID\n");
|
|
|
|
pConv->instance->lastError = DMLERR_INVALIDPARAMETER; /* FIXME: check */
|
2001-08-10 00:07:22 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-15 14:22:35 +01:00
|
|
|
|
|
|
|
if (checkConnected && !(pConv->wStatus & ST_CONNECTED))
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
2006-11-15 14:22:35 +01:00
|
|
|
WARN("found conv but ain't connected\n");
|
|
|
|
pConv->instance->lastError = DMLERR_NO_CONV_ESTABLISHED;
|
2001-08-10 00:07:22 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pConv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_GetConvFromWnd
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
WDML_CONV* WDML_GetConvFromWnd(HWND hWnd)
|
|
|
|
{
|
2005-02-14 12:53:15 +01:00
|
|
|
return (WDML_CONV*)GetWindowLongPtrW(hWnd, GWL_WDML_CONVERSATION);
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_PostAck
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
BOOL WDML_PostAck(WDML_CONV* pConv, WDML_SIDE side, WORD appRetCode,
|
2007-05-30 12:32:24 +02:00
|
|
|
BOOL fBusy, BOOL fAck, UINT_PTR pmt, LPARAM lParam, UINT oldMsg)
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
|
|
|
DDEACK ddeAck;
|
|
|
|
HWND from, to;
|
|
|
|
|
|
|
|
if (side == WDML_SERVER_SIDE)
|
|
|
|
{
|
|
|
|
from = pConv->hwndServer;
|
|
|
|
to = pConv->hwndClient;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
to = pConv->hwndServer;
|
|
|
|
from = pConv->hwndClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddeAck.bAppReturnCode = appRetCode;
|
|
|
|
ddeAck.reserved = 0;
|
|
|
|
ddeAck.fBusy = fBusy;
|
|
|
|
ddeAck.fAck = fAck;
|
|
|
|
|
|
|
|
TRACE("Posting a %s ack\n", ddeAck.fAck ? "positive" : "negative");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-01-18 20:30:15 +01:00
|
|
|
lParam = (lParam) ? ReuseDDElParam(lParam, oldMsg, WM_DDE_ACK, *(WORD*)&ddeAck, pmt) :
|
|
|
|
PackDDElParam(WM_DDE_ACK, *(WORD*)&ddeAck, pmt);
|
2005-02-14 12:53:15 +01:00
|
|
|
if (!PostMessageW(to, WM_DDE_ACK, (WPARAM)from, lParam))
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
2002-01-18 20:30:15 +01:00
|
|
|
pConv->wStatus &= ~ST_CONNECTED;
|
2006-11-15 14:21:44 +01:00
|
|
|
pConv->instance->lastError = DMLERR_POSTMSG_FAILED;
|
2002-01-18 20:30:15 +01:00
|
|
|
FreeDDElParam(WM_DDE_ACK, lParam);
|
|
|
|
return FALSE;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
2002-01-18 20:30:15 +01:00
|
|
|
return TRUE;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* DdeSetUserHandle (USER32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DdeSetUserHandle(HCONV hConv, DWORD id, DWORD hUser)
|
|
|
|
{
|
|
|
|
WDML_CONV* pConv;
|
|
|
|
|
|
|
|
pConv = WDML_GetConv(hConv, FALSE);
|
|
|
|
if (pConv == NULL)
|
2006-11-15 14:22:35 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (id == QID_SYNC)
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
|
|
|
pConv->hUser = hUser;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WDML_XACT* pXAct;
|
|
|
|
|
|
|
|
pXAct = WDML_FindTransaction(pConv, id);
|
|
|
|
if (pXAct)
|
|
|
|
{
|
|
|
|
pXAct->hUser = hUser;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pConv->instance->lastError = DMLERR_UNFOUND_QUEUE_ID;
|
2006-11-15 14:22:35 +01:00
|
|
|
return FALSE;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
}
|
2006-11-15 14:22:35 +01:00
|
|
|
return TRUE;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_GetLocalConvInfo
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL WDML_GetLocalConvInfo(WDML_CONV* pConv, CONVINFO* ci, DWORD id)
|
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
WDML_LINK* pLink;
|
|
|
|
WDML_SIDE side;
|
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
ci->hConvPartner = (pConv->wStatus & ST_ISLOCAL) ? (HCONV)((ULONG_PTR)pConv | 1) : 0;
|
2001-08-10 00:07:22 +02:00
|
|
|
ci->hszSvcPartner = pConv->hszService;
|
|
|
|
ci->hszServiceReq = pConv->hszService; /* FIXME: they shouldn't be the same, should they ? */
|
|
|
|
ci->hszTopic = pConv->hszTopic;
|
|
|
|
ci->wStatus = pConv->wStatus;
|
|
|
|
|
|
|
|
side = (pConv->wStatus & ST_CLIENT) ? WDML_CLIENT_SIDE : WDML_SERVER_SIDE;
|
|
|
|
|
|
|
|
for (pLink = pConv->instance->links[side]; pLink != NULL; pLink = pLink->next)
|
|
|
|
{
|
2001-09-14 02:24:39 +02:00
|
|
|
if (pLink->hConv == (HCONV)pConv)
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
|
|
|
ci->wStatus |= ST_ADVISE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: non handled status flags:
|
|
|
|
ST_BLOCKED
|
|
|
|
ST_BLOCKNEXT
|
|
|
|
ST_INLIST
|
|
|
|
*/
|
|
|
|
|
|
|
|
ci->wConvst = pConv->wConvst; /* FIXME */
|
|
|
|
|
|
|
|
ci->wLastError = 0; /* FIXME: note it's not the instance last error */
|
|
|
|
ci->hConvList = 0;
|
|
|
|
ci->ConvCtxt = pConv->convContext;
|
|
|
|
if (ci->wStatus & ST_CLIENT)
|
|
|
|
{
|
|
|
|
ci->hwnd = pConv->hwndClient;
|
|
|
|
ci->hwndPartner = pConv->hwndServer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ci->hwnd = pConv->hwndServer;
|
|
|
|
ci->hwndPartner = pConv->hwndClient;
|
|
|
|
}
|
|
|
|
if (id == QID_SYNC)
|
|
|
|
{
|
|
|
|
ci->hUser = pConv->hUser;
|
|
|
|
ci->hszItem = 0;
|
|
|
|
ci->wFmt = 0;
|
|
|
|
ci->wType = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WDML_XACT* pXAct;
|
|
|
|
|
|
|
|
pXAct = WDML_FindTransaction(pConv, id);
|
|
|
|
if (pXAct)
|
|
|
|
{
|
|
|
|
ci->hUser = pXAct->hUser;
|
|
|
|
ci->hszItem = pXAct->hszItem;
|
|
|
|
ci->wFmt = pXAct->wFmt;
|
|
|
|
ci->wType = pXAct->wType;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
pConv->instance->lastError = DMLERR_UNFOUND_QUEUE_ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DdeQueryConvInfo (USER32.@)
|
|
|
|
*
|
2005-07-08 13:33:09 +02:00
|
|
|
* FIXME: Set last DDE error on failure.
|
2001-08-10 00:07:22 +02:00
|
|
|
*/
|
2002-12-19 02:18:49 +01:00
|
|
|
UINT WINAPI DdeQueryConvInfo(HCONV hConv, DWORD id, PCONVINFO lpConvInfo)
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
|
|
|
UINT ret = lpConvInfo->cb;
|
|
|
|
CONVINFO ci;
|
|
|
|
WDML_CONV* pConv;
|
|
|
|
|
2006-09-30 00:25:15 +02:00
|
|
|
TRACE("(%p,%x,%p)\n", hConv, id, lpConvInfo);
|
2002-03-29 18:59:20 +01:00
|
|
|
|
|
|
|
if (!hConv)
|
|
|
|
{
|
|
|
|
FIXME("hConv is NULL\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pConv = WDML_GetConv(hConv, FALSE);
|
2005-07-08 13:33:09 +02:00
|
|
|
if (pConv != NULL)
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
2005-07-08 13:33:09 +02:00
|
|
|
if (!WDML_GetLocalConvInfo(pConv, &ci, id))
|
|
|
|
ret = 0;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
2005-07-08 13:33:09 +02:00
|
|
|
else
|
2001-08-10 00:07:22 +02:00
|
|
|
{
|
2005-07-08 13:33:09 +02:00
|
|
|
if ((ULONG_PTR)hConv & 1)
|
|
|
|
{
|
|
|
|
pConv = WDML_GetConv((HCONV)((ULONG_PTR)hConv & ~1), FALSE);
|
|
|
|
if (pConv != NULL)
|
|
|
|
FIXME("Request on remote conversation information is not implemented yet\n");
|
|
|
|
}
|
|
|
|
ret = 0;
|
2001-08-10 00:07:22 +02:00
|
|
|
}
|
2006-11-15 14:22:35 +01:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
if (ret != 0)
|
2002-01-18 20:30:15 +01:00
|
|
|
memcpy(lpConvInfo, &ci, min((size_t)lpConvInfo->cb, sizeof(ci)));
|
2001-08-10 00:07:22 +02:00
|
|
|
return ret;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Link (hot & warm) management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_AddLink
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
void WDML_AddLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
|
2001-06-23 01:02:48 +02:00
|
|
|
UINT wType, HSZ hszItem, UINT wFmt)
|
|
|
|
{
|
|
|
|
WDML_LINK* pLink;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
pLink = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_LINK));
|
|
|
|
if (pLink == NULL)
|
|
|
|
{
|
|
|
|
ERR("OOM\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pLink->hConv = hConv;
|
|
|
|
pLink->transactionType = wType;
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_IncHSZ(pInstance, pLink->hszItem = hszItem);
|
2001-06-23 01:02:48 +02:00
|
|
|
pLink->uFmt = wFmt;
|
2001-08-10 00:07:22 +02:00
|
|
|
pLink->next = pInstance->links[side];
|
|
|
|
pInstance->links[side] = pLink;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_RemoveLink
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
void WDML_RemoveLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
|
2001-06-23 01:02:48 +02:00
|
|
|
HSZ hszItem, UINT uFmt)
|
|
|
|
{
|
|
|
|
WDML_LINK* pPrev = NULL;
|
|
|
|
WDML_LINK* pCurrent = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pCurrent = pInstance->links[side];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
while (pCurrent != NULL)
|
|
|
|
{
|
|
|
|
if (pCurrent->hConv == hConv &&
|
|
|
|
DdeCmpStringHandles(pCurrent->hszItem, hszItem) == 0 &&
|
|
|
|
pCurrent->uFmt == uFmt)
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pCurrent == pInstance->links[side])
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->links[side] = pCurrent->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pPrev->next = pCurrent->next;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_DecHSZ(pInstance, pCurrent->hszItem);
|
2001-06-23 01:02:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pCurrent);
|
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
pPrev = pCurrent;
|
|
|
|
pCurrent = pCurrent->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called to remove all links related to the conv.
|
2002-06-01 01:06:46 +02:00
|
|
|
It should be called from both client and server when terminating
|
2001-06-23 01:02:48 +02:00
|
|
|
the conversation.
|
|
|
|
*/
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_RemoveAllLinks
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
void WDML_RemoveAllLinks(WDML_INSTANCE* pInstance, WDML_CONV* pConv, WDML_SIDE side)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
WDML_LINK* pPrev = NULL;
|
|
|
|
WDML_LINK* pCurrent = NULL;
|
|
|
|
WDML_LINK* pNext = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
pCurrent = pInstance->links[side];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
while (pCurrent != NULL)
|
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pCurrent->hConv == (HCONV)pConv)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
if (pCurrent == pInstance->links[side])
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->links[side] = pCurrent->next;
|
2001-06-23 01:02:48 +02:00
|
|
|
pNext = pCurrent->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pPrev->next = pCurrent->next;
|
|
|
|
pNext = pCurrent->next;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_DecHSZ(pInstance, pCurrent->hszItem);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pCurrent);
|
|
|
|
pCurrent = NULL;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if (pCurrent)
|
|
|
|
{
|
|
|
|
pPrev = pCurrent;
|
|
|
|
pCurrent = pCurrent->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCurrent = pNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_FindLink
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
WDML_LINK* WDML_FindLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
|
2002-01-18 20:30:15 +01:00
|
|
|
HSZ hszItem, BOOL use_fmt, UINT uFmt)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
WDML_LINK* pCurrent = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
for (pCurrent = pInstance->links[side]; pCurrent != NULL; pCurrent = pCurrent->next)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
/* we don't need to check for transaction type as it can be altered */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
if (pCurrent->hConv == hConv &&
|
|
|
|
DdeCmpStringHandles(pCurrent->hszItem, hszItem) == 0 &&
|
2002-01-18 20:30:15 +01:00
|
|
|
(!use_fmt || pCurrent->uFmt == uFmt))
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
return pCurrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Transaction management
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_AllocTransaction
|
|
|
|
*
|
|
|
|
* Alloc a transaction structure for handling the message ddeMsg
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
WDML_XACT* WDML_AllocTransaction(WDML_INSTANCE* pInstance, UINT ddeMsg,
|
|
|
|
UINT wFmt, HSZ hszItem)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
WDML_XACT* pXAct;
|
|
|
|
static WORD tid = 1; /* FIXME: wrap around */
|
|
|
|
|
|
|
|
pXAct = HeapAlloc(GetProcessHeap(), 0, sizeof(WDML_XACT));
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!pXAct)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
pInstance->lastError = DMLERR_MEMORY_ERROR;
|
2001-06-23 01:02:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pXAct->xActID = tid++;
|
|
|
|
pXAct->ddeMsg = ddeMsg;
|
|
|
|
pXAct->hDdeData = 0;
|
|
|
|
pXAct->hUser = 0;
|
|
|
|
pXAct->next = NULL;
|
2001-08-10 00:07:22 +02:00
|
|
|
pXAct->wType = 0;
|
|
|
|
pXAct->wFmt = wFmt;
|
2002-01-18 20:30:15 +01:00
|
|
|
if ((pXAct->hszItem = hszItem)) WDML_IncHSZ(pInstance, pXAct->hszItem);
|
2001-08-10 00:07:22 +02:00
|
|
|
pXAct->atom = 0;
|
|
|
|
pXAct->hMem = 0;
|
|
|
|
pXAct->lParam = 0;
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
return pXAct;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_QueueTransaction
|
|
|
|
*
|
|
|
|
* Adds a transaction to the list of transaction
|
|
|
|
*/
|
|
|
|
void WDML_QueueTransaction(WDML_CONV* pConv, WDML_XACT* pXAct)
|
|
|
|
{
|
|
|
|
WDML_XACT** pt;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
/* advance to last in queue */
|
|
|
|
for (pt = &pConv->transactions; *pt != NULL; pt = &(*pt)->next);
|
|
|
|
*pt = pXAct;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_UnQueueTransaction
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WDML_UnQueueTransaction(WDML_CONV* pConv, WDML_XACT* pXAct)
|
|
|
|
{
|
|
|
|
WDML_XACT** pt;
|
|
|
|
|
|
|
|
for (pt = &pConv->transactions; *pt; pt = &(*pt)->next)
|
|
|
|
{
|
|
|
|
if (*pt == pXAct)
|
|
|
|
{
|
|
|
|
*pt = pXAct->next;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_FreeTransaction
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-08-10 00:07:22 +02:00
|
|
|
void WDML_FreeTransaction(WDML_INSTANCE* pInstance, WDML_XACT* pXAct, BOOL doFreePmt)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2002-01-18 20:30:15 +01:00
|
|
|
/* free pmt(s) in pXAct too. check against one for not deleting TRUE return values */
|
2005-02-14 12:53:15 +01:00
|
|
|
if (doFreePmt && (ULONG_PTR)pXAct->hMem > 1)
|
2002-01-18 20:30:15 +01:00
|
|
|
{
|
2001-08-10 00:07:22 +02:00
|
|
|
GlobalFree(pXAct->hMem);
|
2002-01-18 20:30:15 +01:00
|
|
|
}
|
|
|
|
if (pXAct->hszItem) WDML_DecHSZ(pInstance, pXAct->hszItem);
|
2001-08-10 00:07:22 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pXAct);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_FindTransaction
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
WDML_XACT* WDML_FindTransaction(WDML_CONV* pConv, DWORD tid)
|
|
|
|
{
|
|
|
|
WDML_XACT* pXAct;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
tid = HIWORD(tid);
|
|
|
|
for (pXAct = pConv->transactions; pXAct; pXAct = pXAct->next)
|
|
|
|
{
|
|
|
|
if (pXAct->xActID == tid)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return pXAct;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:07:22 +02:00
|
|
|
/* ================================================================
|
|
|
|
*
|
|
|
|
* Information broadcast across DDEML implementations
|
|
|
|
*
|
|
|
|
* ================================================================ */
|
|
|
|
|
2001-06-23 01:02:48 +02:00
|
|
|
struct tagWDML_BroadcastPmt
|
|
|
|
{
|
2005-02-14 12:53:15 +01:00
|
|
|
LPCWSTR clsName;
|
2001-06-23 01:02:48 +02:00
|
|
|
UINT uMsg;
|
|
|
|
WPARAM wParam;
|
|
|
|
LPARAM lParam;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_BroadcastEnumProc
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL CALLBACK WDML_BroadcastEnumProc(HWND hWnd, LPARAM lParam)
|
|
|
|
{
|
|
|
|
struct tagWDML_BroadcastPmt* s = (struct tagWDML_BroadcastPmt*)lParam;
|
2005-02-14 12:53:15 +01:00
|
|
|
WCHAR buffer[128];
|
2001-06-23 01:02:48 +02:00
|
|
|
|
2005-02-14 12:53:15 +01:00
|
|
|
if (GetClassNameW(hWnd, buffer, 128) > 0 &&
|
|
|
|
lstrcmpiW(buffer, s->clsName) == 0)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
2005-02-14 12:53:15 +01:00
|
|
|
PostMessageW(hWnd, s->uMsg, s->wParam, s->lParam);
|
2001-06-23 01:02:48 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WDML_BroadcastDDEWindows
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2005-02-14 12:53:15 +01:00
|
|
|
void WDML_BroadcastDDEWindows(LPCWSTR clsName, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2001-06-23 01:02:48 +02:00
|
|
|
{
|
|
|
|
struct tagWDML_BroadcastPmt s;
|
|
|
|
|
|
|
|
s.clsName = clsName;
|
|
|
|
s.uMsg = uMsg;
|
|
|
|
s.wParam = wParam;
|
|
|
|
s.lParam = lParam;
|
|
|
|
EnumWindows(WDML_BroadcastEnumProc, (LPARAM)&s);
|
|
|
|
}
|