dde_private.h 11.8 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * DDEML library
 *
 * Copyright 1997 Alexandre Julliard
 * Copyright 1997 Len White
 * Copyright 1999 Keith Matthews
 * Copyright 2000 Corel
 * Copyright 2001 Eric Pouech
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * 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
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 */

#ifndef __WINE_DDEML_PRIVATE_H
#define __WINE_DDEML_PRIVATE_H

/* defined in atom.c file.
 */
#define MAX_ATOM_LEN              255

/* Maximum buffer size ( including the '\0' ).
 */
#define MAX_BUFFER_LEN            (MAX_ATOM_LEN + 1)

/* The internal structures (prefixed by WDML) are used as follows:
 * + a WDML_INSTANCE is created for each instance creation (DdeInitialize)
38
 *      - a popup window (InstanceClass) is created for each instance.
39
 *      - this window is used to receive all the DDEML events (server registration,
40
 *	  conversation confirmation...). See the WM_WDML_???? messages for details
41
 * + when registering a server (DdeNameService) a WDML_SERVER is created
42 43 44 45 46 47 48 49 50 51
 *	- a popup window (ServerNameClass) is created
 * + a conversation is represented by two WDML_CONV structures:
 *	- one on the client side, the other one on the server side
 *	- this is needed because the address spaces may be different
 *	- therefore, two lists of links are kept for each instance
 *	- two windows are created for a conversation:
 *		o a popup window on client side (ClientConvClass)
 *		o a child window (of the ServerName) on the server side
 *		  (ServerConvClass)
 *	- all the exchanges then take place between those two windows
52 53
 *	- windows for the conversation exist in two forms (Ansi & Unicode). This
 *	  is only needed when a partner in a conv is not handled by DDEML. The
54
 *	  type (A/W) of the window is used to handle the ansi <=> unicode
55 56 57 58
 *        transformations
 *	- two handles are created for a conversation (on each side). Each handle
 *	  is linked to a structure. To help differentiate those handles, the
 *	  local one has an even value, whereas the remote one has an odd value.
59 60 61
 * + a (warm or link) is represented by two WDML_LINK structures:
 *	- one on client side, the other one on server side
 *	- therefore, two lists of links are kept for each instance
62
 *
63 64 65 66
 * To help getting back to data, WDML windows store information:
 *	- offset 0: the DDE instance
 *	- offset 4: the current conversation (for ClientConv and ServerConv only)
 *
67 68 69
 * All the implementation (client & server) makes the assumption that the other side
 * is not always a DDEML partner. However, if it's the case, supplementary services
 * are available (most notably the REGISTER/UNREGISTER and CONNECT_CONFIRM messages
70
 * to the callback function). To be correct in every situation, all the basic
71
 * exchanges are made using the 'pure' DDE protocol. A (future !) enhancement would
72
 * be to provide a new protocol in the case where both partners are handled by DDEML.
73 74
 *
 * The StringHandles are in fact stored as local atoms. So an HSZ and a (local) atom
75
 * can be used interchangeably. However, in order to keep track of the allocated HSZ,
76
 * and to free them upon instance termination, all HSZ are stored in a link list.
77
 * When the HSZ need to be passed through DDE messages, we need to convert them back and
78
 * forth to global atoms.
79 80
 */

81 82 83 84 85 86 87 88 89 90
/* this struct has the same mapping as all the DDE??? structures */
typedef struct {
    unsigned short unused:12,
		   fResponse:1,
                   fRelease:1,
		   fDeferUpd:1,
                   fAckReq:1;
    short    cfFormat;
} WINE_DDEHEAD;

91 92
typedef struct tagHSZNode
{
93
    struct tagHSZNode*		next;
94
    HSZ 			hsz;
95
    unsigned			refCount;
96 97 98 99 100 101
} HSZNode;

typedef struct tagWDML_SERVER
{
    struct tagWDML_SERVER*	next;
    HSZ				hszService;
102 103 104
    HSZ				hszServiceSpec;
    ATOM			atomService;
    ATOM			atomServiceSpec;
105 106 107 108 109
    BOOL			filterOn;
    HWND			hwndServer;
} WDML_SERVER;

typedef struct tagWDML_XACT {
110
    struct tagWDML_XACT*	next;		/* list of transactions in conversation */
111 112 113 114 115
    DWORD			xActID;
    UINT			ddeMsg;
    HDDEDATA			hDdeData;
    DWORD			dwTimeout;
    DWORD			hUser;
116 117 118 119 120 121
    UINT			wType;
    UINT			wFmt;
    HSZ				hszItem;
    ATOM			atom;		/* as converted from or to hszItem */
    HGLOBAL			hMem;
    LPARAM			lParam; 	/* useful for reusing */
122 123
} WDML_XACT;

124
typedef struct tagWDML_CONV
125 126
{
    struct tagWDML_CONV*	next;		/* to link all the conversations */
127
    struct tagWDML_INSTANCE*	instance;
128 129
    HSZ				hszService;	/* pmt used for connection */
    HSZ				hszTopic;	/* pmt used for connection */
130
    UINT			magic;		/* magic number to check validity */
131 132 133 134
    UINT			afCmd;		/* service name flag */
    CONVCONTEXT			convContext;
    HWND			hwndClient;	/* source of conversation (ClientConvClass) */
    HWND			hwndServer;	/* destination of conversation (ServerConvClass) */
135
    WDML_XACT*			transactions;	/* pending transactions */
136
    DWORD			hUser;		/* user defined value */
137 138
    DWORD			wStatus;	/* same bits as convinfo.wStatus */
    DWORD			wConvst;	/* same values as convinfo.wConvst */
139 140
} WDML_CONV;

141 142
#define WDML_CONV_MAGIC  0xbabe1234

143 144 145
/* DDE_LINK struct defines hot, warm, and cold links */
typedef struct tagWDML_LINK {
    struct tagWDML_LINK*	next;		/* to link all the active links */
Austin English's avatar
Austin English committed
146
    HCONV			hConv;		/* to get back to the conversation */
147
    UINT			transactionType;/* 0 for no link */
148
    HSZ				hszItem;	/* item targeted for (hot/warm) link */
149 150 151 152 153 154 155
    UINT			uFmt;		/* format for data */
} WDML_LINK;

typedef struct tagWDML_INSTANCE
{
    struct tagWDML_INSTANCE*	next;
    DWORD           		instanceID;	/* needed to track monitor usage */
156
    DWORD			threadID;	/* needed to keep instance linked to a unique thread */
157 158
    BOOL			monitor;        /* have these two as full Booleans cos they'll be tested frequently */
    BOOL			clientOnly;	/* bit wasteful of space but it will be faster */
159
    BOOL			unicode;	/* Flag to indicate Win32 API used to initialise */
160 161 162 163
    HSZNode*			nodeList;	/* for cleaning upon exit */
    PFNCALLBACK     		callback;
    DWORD           		CBFflags;
    DWORD           		monitorFlags;
164
    DWORD			lastError;
165
    HWND			hwndEvent;
166
    DWORD			wStatus;	/* global instance status */
167 168 169 170 171 172 173 174
    WDML_SERVER*		servers;	/* list of registered servers */
    WDML_CONV*			convs[2];	/* active conversations for this instance (client and server) */
    WDML_LINK*			links[2];	/* active links for this instance (client and server) */
} WDML_INSTANCE;

/* header for the DDE Data objects */
typedef struct tagDDE_DATAHANDLE_HEAD
{
175
    WORD	cfFormat;
176
    WORD        bAppOwned;
177 178 179 180 181 182 183
} DDE_DATAHANDLE_HEAD;

typedef enum tagWDML_SIDE
{
    WDML_CLIENT_SIDE = 0, WDML_SERVER_SIDE = 1
} WDML_SIDE;

184 185 186 187 188
typedef enum {
    WDML_QS_ERROR, WDML_QS_HANDLED, WDML_QS_PASS, WDML_QS_SWALLOWED, WDML_QS_BLOCK,
} WDML_QUEUE_STATE;

extern	HDDEDATA 	WDML_InvokeCallback(WDML_INSTANCE* pInst, UINT uType, UINT uFmt, HCONV hConv,
189
					    HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
190 191 192 193
					    ULONG_PTR dwData1, ULONG_PTR dwData2) DECLSPEC_HIDDEN;
extern	WDML_SERVER*	WDML_AddServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
extern	void		WDML_RemoveServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
extern	WDML_SERVER*	WDML_FindServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
194
/* transaction handler on the server side */
195
extern WDML_QUEUE_STATE WDML_ServerHandle(WDML_CONV* pConv, WDML_XACT* pXAct) DECLSPEC_HIDDEN;
196
/* transaction handler on the client side */
197
HDDEDATA WDML_ClientHandle(WDML_CONV *pConv, WDML_XACT *pXAct, DWORD dwTimeout, LPDWORD pdwResult) DECLSPEC_HIDDEN;
198 199
/* called both in DdeClientTransaction and server side. */
extern	WDML_CONV* 	WDML_AddConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
200 201 202 203
				     HSZ hszService, HSZ hszTopic, HWND hwndClient, HWND hwndServer) DECLSPEC_HIDDEN;
extern	void		WDML_RemoveConv(WDML_CONV* pConv, WDML_SIDE side) DECLSPEC_HIDDEN;
extern	WDML_CONV*	WDML_GetConv(HCONV hConv, BOOL checkConnected) DECLSPEC_HIDDEN;
extern	WDML_CONV*	WDML_GetConvFromWnd(HWND hWnd) DECLSPEC_HIDDEN;
204
extern	WDML_CONV*	WDML_FindConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
205
				      HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
206
extern  BOOL		WDML_PostAck(WDML_CONV* pConv, WDML_SIDE side, WORD appRetCode,
207
				     BOOL fBusy, BOOL fAck, UINT_PTR pmt, LPARAM lParam, UINT oldMsg) DECLSPEC_HIDDEN;
208
extern	void		WDML_AddLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
209
				     UINT wType, HSZ hszItem, UINT wFmt) DECLSPEC_HIDDEN;
210
extern	WDML_LINK*	WDML_FindLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
211
				      HSZ hszItem, BOOL use_fmt, UINT uFmt) DECLSPEC_HIDDEN;
212
extern	void 		WDML_RemoveLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
213
					HSZ hszItem, UINT wFmt) DECLSPEC_HIDDEN;
214
/* string internals */
215 216 217
extern	BOOL		WDML_DecHSZ(WDML_INSTANCE* pInstance, HSZ hsz) DECLSPEC_HIDDEN;
extern	BOOL		WDML_IncHSZ(WDML_INSTANCE* pInstance, HSZ hsz) DECLSPEC_HIDDEN;
extern	ATOM		WDML_MakeAtomFromHsz(HSZ hsz) DECLSPEC_HIDDEN;
218
extern	HSZ		WDML_MakeHszFromAtom(const WDML_INSTANCE* pInstance, ATOM atom) DECLSPEC_HIDDEN;
219
/* client calls these */
220 221 222 223
extern	WDML_XACT*	WDML_AllocTransaction(WDML_INSTANCE* pInstance, UINT ddeMsg, UINT wFmt, HSZ hszItem) DECLSPEC_HIDDEN;
extern	void		WDML_QueueTransaction(WDML_CONV* pConv, WDML_XACT* pXAct) DECLSPEC_HIDDEN;
extern	BOOL		WDML_UnQueueTransaction(WDML_CONV* pConv, WDML_XACT*  pXAct) DECLSPEC_HIDDEN;
extern	void		WDML_FreeTransaction(WDML_INSTANCE* pInstance, WDML_XACT* pXAct, BOOL doFreePmt) DECLSPEC_HIDDEN;
224
extern	HGLOBAL		WDML_DataHandle2Global(HDDEDATA hDdeData, BOOL fResponse, BOOL fRelease,
225
					       BOOL fDeferUpd, BOOL dAckReq) DECLSPEC_HIDDEN;
226
extern	HDDEDATA	WDML_Global2DataHandle(WDML_CONV* pConv, HGLOBAL hMem, WINE_DDEHEAD* da) DECLSPEC_HIDDEN;
227 228 229
extern  BOOL            WDML_IsAppOwned(HDDEDATA hDdeData) DECLSPEC_HIDDEN;
extern	WDML_INSTANCE*	WDML_GetInstance(DWORD InstId) DECLSPEC_HIDDEN;
extern	WDML_INSTANCE*	WDML_GetInstanceFromWnd(HWND hWnd) DECLSPEC_HIDDEN;
230
/* broadcasting to DDE windows */
231
extern	void		WDML_BroadcastDDEWindows(LPCWSTR clsName, UINT uMsg,
232 233
						 WPARAM wParam, LPARAM lParam) DECLSPEC_HIDDEN;
extern	void		WDML_NotifyThreadExit(DWORD tid) DECLSPEC_HIDDEN;
234 235
extern	void 		WDML_NotifyThreadDetach(void) DECLSPEC_HIDDEN;

236

237 238 239 240 241
static inline void WDML_ExtractAck(WORD status, DDEACK* da)
{
    *da = *((DDEACK*)&status);
}

242 243 244 245 246
extern const WCHAR WDML_szEventClass[] DECLSPEC_HIDDEN; /* class of window for events (aka instance) */
extern const char WDML_szServerConvClassA[] DECLSPEC_HIDDEN; /* ANSI class of window for server side conv */
extern const WCHAR WDML_szServerConvClassW[] DECLSPEC_HIDDEN; /* unicode class of window for server side conv */
extern const char WDML_szClientConvClassA[] DECLSPEC_HIDDEN; /* ANSI class of window for client side conv */
extern const WCHAR WDML_szClientConvClassW[] DECLSPEC_HIDDEN; /* unicode class of window for client side conv */
247 248 249

#define WM_WDML_REGISTER	(WM_USER + 0x200)
#define WM_WDML_UNREGISTER	(WM_USER + 0x201)
250 251
#define WM_WDML_CONNECT_CONFIRM	(WM_USER + 0x202)

252
/* parameters for messages:
253 254 255 256 257 258 259
 *			wParam				lParam
 * Register		atom for service name		atom for service spec
 * Unregister		atom for service name		atom for service spec
 * ConnectConfirm	client window handle		server window handle
 */

#define	GWL_WDML_INSTANCE	(0)
260 261
#define	GWL_WDML_CONVERSATION	(sizeof(ULONG_PTR))
#define	GWL_WDML_SERVER		(sizeof(ULONG_PTR))
262 263

#endif  /* __WINE_DDEML_PRIVATE_H */