1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * DDEML library
3*c2c66affSColin Finck *
4*c2c66affSColin Finck * Copyright 1997 Alexandre Julliard
5*c2c66affSColin Finck * Copyright 1997 Len White
6*c2c66affSColin Finck * Copyright 1999 Keith Matthews
7*c2c66affSColin Finck * Copyright 2000 Corel
8*c2c66affSColin Finck * Copyright 2001 Eric Pouech
9*c2c66affSColin Finck *
10*c2c66affSColin Finck * This library is free software; you can redistribute it and/or
11*c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
12*c2c66affSColin Finck * License as published by the Free Software Foundation; either
13*c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
14*c2c66affSColin Finck *
15*c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
16*c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18*c2c66affSColin Finck * Lesser General Public License for more details.
19*c2c66affSColin Finck *
20*c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
21*c2c66affSColin Finck * License along with this library; if not, write to the Free Software
22*c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23*c2c66affSColin Finck */
24*c2c66affSColin Finck
25*c2c66affSColin Finck #ifndef __WINE_DDEML_PRIVATE_H
26*c2c66affSColin Finck #define __WINE_DDEML_PRIVATE_H
27*c2c66affSColin Finck
28*c2c66affSColin Finck /* defined in atom.c file.
29*c2c66affSColin Finck */
30*c2c66affSColin Finck #define MAX_ATOM_LEN 255
31*c2c66affSColin Finck
32*c2c66affSColin Finck /* Maximum buffer size ( including the '\0' ).
33*c2c66affSColin Finck */
34*c2c66affSColin Finck #define MAX_BUFFER_LEN (MAX_ATOM_LEN + 1)
35*c2c66affSColin Finck
36*c2c66affSColin Finck /* The internal structures (prefixed by WDML) are used as follows:
37*c2c66affSColin Finck * + a WDML_INSTANCE is created for each instance creation (DdeInitialize)
38*c2c66affSColin Finck * - a popup window (InstanceClass) is created for each instance.
39*c2c66affSColin Finck * - this window is used to receive all the DDEML events (server registration,
40*c2c66affSColin Finck * conversation confirmation...). See the WM_WDML_???? messages for details
41*c2c66affSColin Finck * + when registering a server (DdeNameService) a WDML_SERVER is created
42*c2c66affSColin Finck * - a popup window (ServerNameClass) is created
43*c2c66affSColin Finck * + a conversation is represented by two WDML_CONV structures:
44*c2c66affSColin Finck * - one on the client side, the other one on the server side
45*c2c66affSColin Finck * - this is needed because the address spaces may be different
46*c2c66affSColin Finck * - therefore, two lists of links are kept for each instance
47*c2c66affSColin Finck * - two windows are created for a conversation:
48*c2c66affSColin Finck * o a popup window on client side (ClientConvClass)
49*c2c66affSColin Finck * o a child window (of the ServerName) on the server side
50*c2c66affSColin Finck * (ServerConvClass)
51*c2c66affSColin Finck * - all the exchanges then take place between those two windows
52*c2c66affSColin Finck * - windows for the conversation exist in two forms (Ansi & Unicode). This
53*c2c66affSColin Finck * is only needed when a partner in a conv is not handled by DDEML. The
54*c2c66affSColin Finck * type (A/W) of the window is used to handle the ansi <=> unicode
55*c2c66affSColin Finck * transformations
56*c2c66affSColin Finck * - two handles are created for a conversation (on each side). Each handle
57*c2c66affSColin Finck * is linked to a structure. To help differentiate those handles, the
58*c2c66affSColin Finck * local one has an even value, whereas the remote one has an odd value.
59*c2c66affSColin Finck * + a (warm or link) is represented by two WDML_LINK structures:
60*c2c66affSColin Finck * - one on client side, the other one on server side
61*c2c66affSColin Finck * - therefore, two lists of links are kept for each instance
62*c2c66affSColin Finck *
63*c2c66affSColin Finck * To help getting back to data, WDML windows store information:
64*c2c66affSColin Finck * - offset 0: the DDE instance
65*c2c66affSColin Finck * - offset 4: the current conversation (for ClientConv and ServerConv only)
66*c2c66affSColin Finck *
67*c2c66affSColin Finck * All the implementation (client & server) makes the assumption that the other side
68*c2c66affSColin Finck * is not always a DDEML partner. However, if it's the case, supplementary services
69*c2c66affSColin Finck * are available (most notably the REGISTER/UNREGISTER and CONNECT_CONFIRM messages
70*c2c66affSColin Finck * to the callback function). To be correct in every situation, all the basic
71*c2c66affSColin Finck * exchanges are made using the 'pure' DDE protocol. A (future !) enhancement would
72*c2c66affSColin Finck * be to provide a new protocol in the case were both partners are handled by DDEML.
73*c2c66affSColin Finck *
74*c2c66affSColin Finck * The StringHandles are in fact stored as local atoms. So an HSZ and a (local) atom
75*c2c66affSColin Finck * can be used interchangeably. However, in order to keep track of the allocated HSZ,
76*c2c66affSColin Finck * and to free them upon instance termination, all HSZ are stored in a link list.
77*c2c66affSColin Finck * When the HSZ need to be passed through DDE messages, we need to convert them back and
78*c2c66affSColin Finck * forth to global atoms.
79*c2c66affSColin Finck */
80*c2c66affSColin Finck
81*c2c66affSColin Finck /* this struct has the same mapping as all the DDE??? structures */
82*c2c66affSColin Finck typedef struct {
83*c2c66affSColin Finck unsigned short unused:12,
84*c2c66affSColin Finck fResponse:1,
85*c2c66affSColin Finck fRelease:1,
86*c2c66affSColin Finck fDeferUpd:1,
87*c2c66affSColin Finck fAckReq:1;
88*c2c66affSColin Finck short cfFormat;
89*c2c66affSColin Finck } WINE_DDEHEAD;
90*c2c66affSColin Finck
91*c2c66affSColin Finck typedef struct tagHSZNode
92*c2c66affSColin Finck {
93*c2c66affSColin Finck struct tagHSZNode* next;
94*c2c66affSColin Finck HSZ hsz;
95*c2c66affSColin Finck unsigned refCount;
96*c2c66affSColin Finck } HSZNode;
97*c2c66affSColin Finck
98*c2c66affSColin Finck typedef struct tagWDML_SERVER
99*c2c66affSColin Finck {
100*c2c66affSColin Finck struct tagWDML_SERVER* next;
101*c2c66affSColin Finck HSZ hszService;
102*c2c66affSColin Finck HSZ hszServiceSpec;
103*c2c66affSColin Finck ATOM atomService;
104*c2c66affSColin Finck ATOM atomServiceSpec;
105*c2c66affSColin Finck BOOL filterOn;
106*c2c66affSColin Finck HWND hwndServer;
107*c2c66affSColin Finck } WDML_SERVER;
108*c2c66affSColin Finck
109*c2c66affSColin Finck typedef struct tagWDML_XACT {
110*c2c66affSColin Finck struct tagWDML_XACT* next; /* list of transactions in conversation */
111*c2c66affSColin Finck DWORD xActID;
112*c2c66affSColin Finck UINT ddeMsg;
113*c2c66affSColin Finck HDDEDATA hDdeData;
114*c2c66affSColin Finck DWORD dwTimeout;
115*c2c66affSColin Finck DWORD hUser;
116*c2c66affSColin Finck UINT wType;
117*c2c66affSColin Finck UINT wFmt;
118*c2c66affSColin Finck HSZ hszItem;
119*c2c66affSColin Finck ATOM atom; /* as converted from or to hszItem */
120*c2c66affSColin Finck HGLOBAL hMem;
121*c2c66affSColin Finck LPARAM lParam; /* useful for reusing */
122*c2c66affSColin Finck } WDML_XACT;
123*c2c66affSColin Finck
124*c2c66affSColin Finck typedef struct tagWDML_CONV
125*c2c66affSColin Finck {
126*c2c66affSColin Finck struct tagWDML_CONV* next; /* to link all the conversations */
127*c2c66affSColin Finck struct tagWDML_INSTANCE* instance;
128*c2c66affSColin Finck HSZ hszService; /* pmt used for connection */
129*c2c66affSColin Finck HSZ hszTopic; /* pmt used for connection */
130*c2c66affSColin Finck UINT magic; /* magic number to check validity */
131*c2c66affSColin Finck UINT afCmd; /* service name flag */
132*c2c66affSColin Finck CONVCONTEXT convContext;
133*c2c66affSColin Finck HWND hwndClient; /* source of conversation (ClientConvClass) */
134*c2c66affSColin Finck HWND hwndServer; /* destination of conversation (ServerConvClass) */
135*c2c66affSColin Finck WDML_XACT* transactions; /* pending transactions */
136*c2c66affSColin Finck DWORD hUser; /* user defined value */
137*c2c66affSColin Finck DWORD wStatus; /* same bits as convinfo.wStatus */
138*c2c66affSColin Finck DWORD wConvst; /* same values as convinfo.wConvst */
139*c2c66affSColin Finck } WDML_CONV;
140*c2c66affSColin Finck
141*c2c66affSColin Finck #define WDML_CONV_MAGIC 0xbabe1234
142*c2c66affSColin Finck
143*c2c66affSColin Finck /* DDE_LINK struct defines hot, warm, and cold links */
144*c2c66affSColin Finck typedef struct tagWDML_LINK {
145*c2c66affSColin Finck struct tagWDML_LINK* next; /* to link all the active links */
146*c2c66affSColin Finck HCONV hConv; /* to get back to the conversation */
147*c2c66affSColin Finck UINT transactionType;/* 0 for no link */
148*c2c66affSColin Finck HSZ hszItem; /* item targeted for (hot/warm) link */
149*c2c66affSColin Finck UINT uFmt; /* format for data */
150*c2c66affSColin Finck } WDML_LINK;
151*c2c66affSColin Finck
152*c2c66affSColin Finck typedef struct tagWDML_INSTANCE
153*c2c66affSColin Finck {
154*c2c66affSColin Finck struct tagWDML_INSTANCE* next;
155*c2c66affSColin Finck DWORD instanceID; /* needed to track monitor usage */
156*c2c66affSColin Finck DWORD threadID; /* needed to keep instance linked to a unique thread */
157*c2c66affSColin Finck BOOL monitor; /* have these two as full Booleans cos they'll be tested frequently */
158*c2c66affSColin Finck BOOL clientOnly; /* bit wasteful of space but it will be faster */
159*c2c66affSColin Finck BOOL unicode; /* Flag to indicate Win32 API used to initialise */
160*c2c66affSColin Finck HSZNode* nodeList; /* for cleaning upon exit */
161*c2c66affSColin Finck PFNCALLBACK callback;
162*c2c66affSColin Finck DWORD CBFflags;
163*c2c66affSColin Finck DWORD monitorFlags;
164*c2c66affSColin Finck DWORD lastError;
165*c2c66affSColin Finck HWND hwndEvent;
166*c2c66affSColin Finck DWORD wStatus; /* global instance status */
167*c2c66affSColin Finck WDML_SERVER* servers; /* list of registered servers */
168*c2c66affSColin Finck WDML_CONV* convs[2]; /* active conversations for this instance (client and server) */
169*c2c66affSColin Finck WDML_LINK* links[2]; /* active links for this instance (client and server) */
170*c2c66affSColin Finck } WDML_INSTANCE;
171*c2c66affSColin Finck
172*c2c66affSColin Finck /* header for the DDE Data objects */
173*c2c66affSColin Finck typedef struct tagDDE_DATAHANDLE_HEAD
174*c2c66affSColin Finck {
175*c2c66affSColin Finck WORD cfFormat;
176*c2c66affSColin Finck WORD bAppOwned;
177*c2c66affSColin Finck } DDE_DATAHANDLE_HEAD;
178*c2c66affSColin Finck
179*c2c66affSColin Finck typedef enum tagWDML_SIDE
180*c2c66affSColin Finck {
181*c2c66affSColin Finck WDML_CLIENT_SIDE = 0, WDML_SERVER_SIDE = 1
182*c2c66affSColin Finck } WDML_SIDE;
183*c2c66affSColin Finck
184*c2c66affSColin Finck typedef enum {
185*c2c66affSColin Finck WDML_QS_ERROR, WDML_QS_HANDLED, WDML_QS_PASS, WDML_QS_SWALLOWED, WDML_QS_BLOCK,
186*c2c66affSColin Finck } WDML_QUEUE_STATE;
187*c2c66affSColin Finck
188*c2c66affSColin Finck extern HDDEDATA WDML_InvokeCallback(WDML_INSTANCE* pInst, UINT uType, UINT uFmt, HCONV hConv,
189*c2c66affSColin Finck HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
190*c2c66affSColin Finck ULONG_PTR dwData1, ULONG_PTR dwData2) DECLSPEC_HIDDEN;
191*c2c66affSColin Finck extern WDML_SERVER* WDML_AddServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
192*c2c66affSColin Finck extern void WDML_RemoveServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
193*c2c66affSColin Finck extern WDML_SERVER* WDML_FindServer(WDML_INSTANCE* pInstance, HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
194*c2c66affSColin Finck /* transaction handler on the server side */
195*c2c66affSColin Finck extern WDML_QUEUE_STATE WDML_ServerHandle(WDML_CONV* pConv, WDML_XACT* pXAct) DECLSPEC_HIDDEN;
196*c2c66affSColin Finck /* transaction handler on the client side */
197*c2c66affSColin Finck HDDEDATA WDML_ClientHandle(WDML_CONV *pConv, WDML_XACT *pXAct, DWORD dwTimeout, LPDWORD pdwResult) DECLSPEC_HIDDEN;
198*c2c66affSColin Finck /* called both in DdeClientTransaction and server side. */
199*c2c66affSColin Finck extern WDML_CONV* WDML_AddConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
200*c2c66affSColin Finck HSZ hszService, HSZ hszTopic, HWND hwndClient, HWND hwndServer) DECLSPEC_HIDDEN;
201*c2c66affSColin Finck extern void WDML_RemoveConv(WDML_CONV* pConv, WDML_SIDE side) DECLSPEC_HIDDEN;
202*c2c66affSColin Finck extern WDML_CONV* WDML_GetConv(HCONV hConv, BOOL checkConnected) DECLSPEC_HIDDEN;
203*c2c66affSColin Finck extern WDML_CONV* WDML_GetConvFromWnd(HWND hWnd) DECLSPEC_HIDDEN;
204*c2c66affSColin Finck extern WDML_CONV* WDML_FindConv(WDML_INSTANCE* pInstance, WDML_SIDE side,
205*c2c66affSColin Finck HSZ hszService, HSZ hszTopic) DECLSPEC_HIDDEN;
206*c2c66affSColin Finck extern BOOL WDML_PostAck(WDML_CONV* pConv, WDML_SIDE side, WORD appRetCode,
207*c2c66affSColin Finck BOOL fBusy, BOOL fAck, UINT_PTR pmt, LPARAM lParam, UINT oldMsg) DECLSPEC_HIDDEN;
208*c2c66affSColin Finck extern void WDML_AddLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
209*c2c66affSColin Finck UINT wType, HSZ hszItem, UINT wFmt) DECLSPEC_HIDDEN;
210*c2c66affSColin Finck extern WDML_LINK* WDML_FindLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
211*c2c66affSColin Finck HSZ hszItem, BOOL use_fmt, UINT uFmt) DECLSPEC_HIDDEN;
212*c2c66affSColin Finck extern void WDML_RemoveLink(WDML_INSTANCE* pInstance, HCONV hConv, WDML_SIDE side,
213*c2c66affSColin Finck HSZ hszItem, UINT wFmt) DECLSPEC_HIDDEN;
214*c2c66affSColin Finck /* string internals */
215*c2c66affSColin Finck extern BOOL WDML_DecHSZ(WDML_INSTANCE* pInstance, HSZ hsz) DECLSPEC_HIDDEN;
216*c2c66affSColin Finck extern BOOL WDML_IncHSZ(WDML_INSTANCE* pInstance, HSZ hsz) DECLSPEC_HIDDEN;
217*c2c66affSColin Finck extern ATOM WDML_MakeAtomFromHsz(HSZ hsz) DECLSPEC_HIDDEN;
218*c2c66affSColin Finck extern HSZ WDML_MakeHszFromAtom(const WDML_INSTANCE* pInstance, ATOM atom) DECLSPEC_HIDDEN;
219*c2c66affSColin Finck /* client calls these */
220*c2c66affSColin Finck extern WDML_XACT* WDML_AllocTransaction(WDML_INSTANCE* pInstance, UINT ddeMsg, UINT wFmt, HSZ hszItem) DECLSPEC_HIDDEN;
221*c2c66affSColin Finck extern void WDML_QueueTransaction(WDML_CONV* pConv, WDML_XACT* pXAct) DECLSPEC_HIDDEN;
222*c2c66affSColin Finck extern BOOL WDML_UnQueueTransaction(WDML_CONV* pConv, WDML_XACT* pXAct) DECLSPEC_HIDDEN;
223*c2c66affSColin Finck extern void WDML_FreeTransaction(WDML_INSTANCE* pInstance, WDML_XACT* pXAct, BOOL doFreePmt) DECLSPEC_HIDDEN;
224*c2c66affSColin Finck extern HGLOBAL WDML_DataHandle2Global(HDDEDATA hDdeData, BOOL fResponse, BOOL fRelease,
225*c2c66affSColin Finck BOOL fDeferUpd, BOOL dAckReq) DECLSPEC_HIDDEN;
226*c2c66affSColin Finck extern HDDEDATA WDML_Global2DataHandle(WDML_CONV* pConv, HGLOBAL hMem, WINE_DDEHEAD* da) DECLSPEC_HIDDEN;
227*c2c66affSColin Finck extern BOOL WDML_IsAppOwned(HDDEDATA hDdeData) DECLSPEC_HIDDEN;
228*c2c66affSColin Finck extern WDML_INSTANCE* WDML_GetInstance(DWORD InstId) DECLSPEC_HIDDEN;
229*c2c66affSColin Finck extern WDML_INSTANCE* WDML_GetInstanceFromWnd(HWND hWnd) DECLSPEC_HIDDEN;
230*c2c66affSColin Finck /* broadcasting to DDE windows */
231*c2c66affSColin Finck extern void WDML_BroadcastDDEWindows(LPCWSTR clsName, UINT uMsg,
232*c2c66affSColin Finck WPARAM wParam, LPARAM lParam) DECLSPEC_HIDDEN;
233*c2c66affSColin Finck extern void WDML_NotifyThreadExit(DWORD tid) DECLSPEC_HIDDEN;
234*c2c66affSColin Finck extern void WDML_NotifyThreadDetach(void) DECLSPEC_HIDDEN;
235*c2c66affSColin Finck
236*c2c66affSColin Finck
WDML_ExtractAck(WORD status,DDEACK * da)237*c2c66affSColin Finck static __inline void WDML_ExtractAck(WORD status, DDEACK* da)
238*c2c66affSColin Finck {
239*c2c66affSColin Finck *da = *((DDEACK*)&status);
240*c2c66affSColin Finck }
241*c2c66affSColin Finck
242*c2c66affSColin Finck extern const WCHAR WDML_szEventClass[] DECLSPEC_HIDDEN; /* class of window for events (aka instance) */
243*c2c66affSColin Finck extern const char WDML_szServerConvClassA[] DECLSPEC_HIDDEN; /* ANSI class of window for server side conv */
244*c2c66affSColin Finck extern const WCHAR WDML_szServerConvClassW[] DECLSPEC_HIDDEN; /* unicode class of window for server side conv */
245*c2c66affSColin Finck extern const char WDML_szClientConvClassA[] DECLSPEC_HIDDEN; /* ANSI class of window for client side conv */
246*c2c66affSColin Finck extern const WCHAR WDML_szClientConvClassW[] DECLSPEC_HIDDEN; /* unicode class of window for client side conv */
247*c2c66affSColin Finck
248*c2c66affSColin Finck #define WM_WDML_REGISTER (WM_USER + 0x200)
249*c2c66affSColin Finck #define WM_WDML_UNREGISTER (WM_USER + 0x201)
250*c2c66affSColin Finck #define WM_WDML_CONNECT_CONFIRM (WM_USER + 0x202)
251*c2c66affSColin Finck
252*c2c66affSColin Finck /* parameters for messages:
253*c2c66affSColin Finck * wParam lParam
254*c2c66affSColin Finck * Register atom for service name atom for service spec
255*c2c66affSColin Finck * Unregister atom for service name atom for service spec
256*c2c66affSColin Finck * ConnectConfirm client window handle server window handle
257*c2c66affSColin Finck */
258*c2c66affSColin Finck
259*c2c66affSColin Finck #define GWL_WDML_INSTANCE (0)
260*c2c66affSColin Finck #define GWL_WDML_CONVERSATION (sizeof(ULONG_PTR))
261*c2c66affSColin Finck #define GWL_WDML_SERVER (sizeof(ULONG_PTR))
262*c2c66affSColin Finck
263*c2c66affSColin Finck #endif /* __WINE_DDEML_PRIVATE_H */
264