ReactOS 0.4.15-dev-7924-g5949c20
dde.c File Reference
#include <user32.h>
Include dependency graph for dde.c:

Go to the source code of this file.

Classes

struct  packed_message
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (ddeml)
 
BOOL FASTCALL DdeAddPair (HGLOBAL ClientMem, HGLOBAL ServerMem)
 
HGLOBAL FASTCALL DdeGetPair (HGLOBAL ServerMem)
 
static void push_data (struct packed_message *data, const void *ptr, int size)
 
static ULONGLONG pack_ptr (const void *ptr)
 
static voidunpack_ptr (ULONGLONG ptr64)
 
BOOL post_dde_message (struct packed_message *data, UINT message, LPARAM lParam, LPARAM *lp)
 
BOOL unpack_dde_message (HWND hwnd, UINT message, LPARAM *lparam, PVOID buffer, int size)
 
NTSTATUS WINAPI User32CallDDEPostFromKernel (PVOID Arguments, ULONG ArgumentLength)
 
NTSTATUS WINAPI User32CallDDEGetFromKernel (PVOID Arguments, ULONG ArgumentLength)
 
BOOL WINAPI DdeGetQualityOfService (HWND hWnd, DWORD Reserved, PSECURITY_QUALITY_OF_SERVICE pqosPrev)
 

Function Documentation

◆ DdeAddPair()

BOOL FASTCALL DdeAddPair ( HGLOBAL  ClientMem,
HGLOBAL  ServerMem 
)

Definition at line 181 of file message.c.

182{
183 unsigned i;
184
186
187 /* now remember the pair of hMem on both sides */
188 if (DdeNumUsed == DdeNumAlloc)
189 {
190#define GROWBY 4
192 if (NULL != DdePairs)
193 {
195 (DdeNumAlloc + GROWBY) * sizeof(DDEPAIR));
196 }
197 else
198 {
200 (DdeNumAlloc + GROWBY) * sizeof(DDEPAIR));
201 }
202
203 if (NULL == New)
204 {
206 return FALSE;
207 }
208 DdePairs = New;
209 /* zero out newly allocated part */
210 memset(&DdePairs[DdeNumAlloc], 0, GROWBY * sizeof(DDEPAIR));
212#undef GROWBY
213 }
214
215 for (i = 0; i < DdeNumAlloc; i++)
216 {
217 if (NULL == DdePairs[i].ServerMem)
218 {
219 DdePairs[i].ClientMem = ClientMem;
220 DdePairs[i].ServerMem = ServerMem;
221 DdeNumUsed++;
222 break;
223 }
224 }
226
227 return TRUE;
228}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define New(t)
Definition: rtf.h:1086
#define memset(x, y, z)
Definition: compat.h:39
HGLOBAL ServerMem
Definition: message.c:172
HGLOBAL ClientMem
Definition: message.c:171
static unsigned DdeNumAlloc
Definition: message.c:176
static PDDEPAIR DdePairs
Definition: message.c:175
#define GROWBY
static unsigned DdeNumUsed
Definition: message.c:177
static CRITICAL_SECTION DdeCrst
Definition: message.c:178
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by unpack_dde_message().

◆ DdeGetPair()

HGLOBAL FASTCALL DdeGetPair ( HGLOBAL  ServerMem)

Definition at line 231 of file message.c.

232{
233 unsigned i;
234 HGLOBAL Ret = NULL;
235
237 for (i = 0; i < DdeNumAlloc; i++)
238 {
239 if (DdePairs[i].ServerMem == ServerMem)
240 {
241 /* free this pair */
242 DdePairs[i].ServerMem = 0;
243 DdeNumUsed--;
244 Ret = DdePairs[i].ClientMem;
245 break;
246 }
247 }
249
250 return Ret;
251}

Referenced by post_dde_message().

◆ DdeGetQualityOfService()

BOOL WINAPI DdeGetQualityOfService ( HWND  hWnd,
DWORD  Reserved,
PSECURITY_QUALITY_OF_SERVICE  pqosPrev 
)

Definition at line 310 of file dde.c.

311{
313 return FALSE;
314}
#define UNIMPLEMENTED
Definition: debug.h:115

◆ pack_ptr()

static ULONGLONG pack_ptr ( const void ptr)
inlinestatic

Definition at line 35 of file dde.c.

36{
37 return (ULONG_PTR)ptr;
38}
static PVOID ptr
Definition: dispmode.c:27
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by post_dde_message().

◆ post_dde_message()

BOOL post_dde_message ( struct packed_message data,
UINT  message,
LPARAM  lParam,
LPARAM lp 
)

Definition at line 53 of file dde.c.

54{
55 void* ptr = NULL;
56 int size = 0;
57 UINT_PTR uiLo, uiHi;
58 HGLOBAL hunlock = 0;
59 ULONGLONG hpack;
60
61 if (!UnpackDDElParam( message, lParam, &uiLo, &uiHi ))
62 {
63 ERR("Unpack failed %x\n",message);
64 return FALSE;
65 }
66
67 *lp = lParam;
68 switch (message)
69 {
70 /* DDE messages which don't require packing are:
71 * WM_DDE_INITIATE
72 * WM_DDE_TERMINATE
73 * WM_DDE_REQUEST
74 * WM_DDE_UNADVISE
75 */
76 case WM_DDE_ACK:
77 if (HIWORD(uiHi))
78 {
79 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
80 HGLOBAL h = DdeGetPair( (HANDLE)uiHi );
81 if (h)
82 {
83 hpack = pack_ptr( h );
84 /* send back the value of h on the other side */
85 push_data( data, &hpack, sizeof(hpack) );
86 *lp = uiLo;
87 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
88 }
89 }
90 else
91 {
92 /* uiHi should contain either an atom or 0 */
93 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
94 *lp = MAKELONG( uiLo, uiHi );
95 }
96 break;
97 case WM_DDE_ADVISE:
98 case WM_DDE_DATA:
99 case WM_DDE_POKE:
100 size = 0;
101 if (uiLo)
102 {
103 size = GlobalSize( (HGLOBAL)uiLo ) ;
104 TRACE("WM_DDE_A D P size %d\n",size);
105 if ( (message == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
108 return FALSE;
109 }
110 else if (message != WM_DDE_DATA)
111 {
112 TRACE("WM_DDE uiLo 0\n");
113 return FALSE;
114 }
115
116 *lp = uiHi;
117 if (uiLo)
118 {
119 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
120 {
121 DDEDATA *dde_data = ptr;
122 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
123 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
124 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
125 push_data( data, ptr, size );
126 hunlock = (HGLOBAL)uiLo;
127 }
128 }
129 TRACE( "send ddepack %u %lx\n", size, uiHi );
130 break;
131 case WM_DDE_EXECUTE:
132 if (lParam)
133 {
134 if ((ptr = GlobalLock( (HGLOBAL)lParam) ))
135 {
138 /* so that the other side can send it back on ACK */
139 *lp = lParam;
140 hunlock = (HGLOBAL)lParam;
141 TRACE("WM_DDE_EXECUTE text size %d\n",GlobalSize( (HGLOBAL)lParam ));
142 }
143 }
144 break;
145 }
146
148
149 if (hunlock) GlobalUnlock(hunlock);
150
151 return TRUE;
152}
#define ERR(fmt,...)
Definition: debug.h:110
LPARAM lParam
Definition: combotst.c:139
BOOL WINAPI UnpackDDElParam(UINT, LPARAM, PUINT_PTR, PUINT_PTR)
Definition: ddemisc.c:105
#define WM_DDE_DATA
Definition: dde.h:42
#define WM_DDE_POKE
Definition: dde.h:44
#define WM_DDE_ADVISE
Definition: dde.h:39
BOOL WINAPI FreeDDElParam(UINT, LPARAM)
Definition: ddemisc.c:147
#define WM_DDE_ACK
Definition: dde.h:41
#define WM_DDE_EXECUTE
Definition: dde.h:45
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define HGLOBAL
Definition: ole.h:15
#define TRACE(s)
Definition: solgame.cpp:4
Definition: dde.h:65
Definition: dde.h:57
unsigned short fAckReq
Definition: dde.h:58
unsigned short unused
Definition: dde.h:58
unsigned short reserved
Definition: dde.h:58
short cfFormat
Definition: dde.h:59
unsigned short fResponse
Definition: dde.h:58
unsigned short fRelease
Definition: dde.h:58
Definition: dde.h:72
Definition: tftpd.h:60
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define MAKELONG(a, b)
Definition: typedefs.h:249
uint64_t ULONGLONG
Definition: typedefs.h:67
#define HIWORD(l)
Definition: typedefs.h:247
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
static void push_data(struct packed_message *data, const void *ptr, int size)
Definition: dde.c:27
static ULONGLONG pack_ptr(const void *ptr)
Definition: dde.c:35
HGLOBAL FASTCALL DdeGetPair(HGLOBAL ServerMem)
Definition: message.c:231

Referenced by User32CallDDEPostFromKernel().

◆ push_data()

static void push_data ( struct packed_message data,
const void ptr,
int  size 
)
inlinestatic

Definition at line 27 of file dde.c.

28{
29 data->data = ptr;
30 data->size = size;
31 data->count++;
32}

Referenced by post_dde_message().

◆ unpack_dde_message()

BOOL unpack_dde_message ( HWND  hwnd,
UINT  message,
LPARAM lparam,
PVOID  buffer,
int  size 
)

Definition at line 159 of file dde.c.

160{
161 UINT_PTR uiLo, uiHi;
162 HGLOBAL hMem = 0;
163 void* ptr;
164
165 TRACE("udm : Size %d\n",size);
166
167 switch (message)
168 {
169 case WM_DDE_ACK:
170 if (size)
171 {
172 ULONGLONG hpack;
173 /* hMem is being passed */
174 if (size != sizeof(hpack)) return FALSE;
175 if (!buffer) return FALSE;
176 uiLo = *lparam;
177 memcpy( &hpack, buffer, size );
178 hMem = unpack_ptr( hpack );
179 uiHi = (UINT_PTR)hMem;
180 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
181 }
182 else
183 {
184 uiLo = LOWORD( *lparam );
185 uiHi = HIWORD( *lparam );
186 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
187 }
188 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
189 break;
190 case WM_DDE_ADVISE:
191 case WM_DDE_DATA:
192 case WM_DDE_POKE:
193 if ((!buffer) && message != WM_DDE_DATA) return FALSE;
194 uiHi = *lparam;
195 if (size)
196 {
198 return FALSE;
199 if ((ptr = GlobalLock( hMem )))
200 {
201 memcpy( ptr, buffer, size );
202 GlobalUnlock( hMem );
203 }
204 else
205 {
206 GlobalFree( hMem );
207 return FALSE;
208 }
209 }
210 uiLo = (UINT_PTR)hMem;
211
212 *lparam = PackDDElParam( message, uiLo, uiHi );
213 break;
214 case WM_DDE_EXECUTE:
215 if (size)
216 {
217 if (!buffer) return FALSE;
218 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
219 if ((ptr = GlobalLock( hMem )))
220 {
221 memcpy( ptr, buffer, size );
222 GlobalUnlock( hMem );
223 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
224 if (!DdeAddPair( (HGLOBAL)*lparam, hMem ))
225 {
226 GlobalFree( hMem );
227 TRACE("udm exec: GF 1\n");
228 return FALSE;
229 }
230 }
231 else
232 {
233 GlobalFree( hMem );
234 TRACE("udm exec: GF 2\n");
235 return FALSE;
236 }
237 }
238 else
239 {
240 TRACE("udm exec: No Size\n");
241 return FALSE;
242 }
243
244 TRACE( "exec: exit c=%08lx s=%p\n", *lparam, hMem );
245 *lparam = (LPARAM)hMem;
246 break;
247 }
248 return TRUE;
249}
@ lparam
Definition: SystemMenu.c:31
LPARAM WINAPI PackDDElParam(UINT, UINT_PTR, UINT_PTR)
Definition: ddemisc.c:63
GLuint buffer
Definition: glext.h:5915
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define LOWORD(l)
Definition: pedump.c:82
static void * unpack_ptr(ULONGLONG ptr64)
Definition: dde.c:41
BOOL FASTCALL DdeAddPair(HGLOBAL ClientMem, HGLOBAL ServerMem)
Definition: message.c:181
#define GMEM_MOVEABLE
Definition: winbase.h:294
#define GMEM_DDESHARE
Definition: winbase.h:298
LONG_PTR LPARAM
Definition: windef.h:208

Referenced by User32CallDDEGetFromKernel().

◆ unpack_ptr()

static void * unpack_ptr ( ULONGLONG  ptr64)
inlinestatic

Definition at line 41 of file dde.c.

42{
43 if ((ULONG_PTR)ptr64 != ptr64) return 0;
44 return (void *)(ULONG_PTR)ptr64;
45}
#define ULONG_PTR
Definition: config.h:101

Referenced by unpack_dde_message().

◆ User32CallDDEGetFromKernel()

NTSTATUS WINAPI User32CallDDEGetFromKernel ( PVOID  Arguments,
ULONG  ArgumentLength 
)

Definition at line 288 of file dde.c.

289{
290 BOOL Ret;
292 PDDEPOSTGET_CALLBACK_ARGUMENTS Common = Arguments;
293
294 TRACE("DDE Get CB size %d\n",Common->size);
295
296 Ret = unpack_dde_message( Common->hwnd, Common->message, &Common->lParam, Common->buffer, Common->size );
297
298 if (!Ret)
299 {
300 ERR("DDE Get CB Return bad msg 0x%x\n",Common->message);
302 }
303 return ZwCallbackReturn(Arguments, ArgumentLength, Status);
304}
LONG NTSTATUS
Definition: precomp.h:26
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS NTAPI ZwCallbackReturn(_In_ PVOID Result, _In_ ULONG ResultLength, _In_ NTSTATUS Status)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
BOOL unpack_dde_message(HWND hwnd, UINT message, LPARAM *lparam, PVOID buffer, int size)
Definition: dde.c:159

◆ User32CallDDEPostFromKernel()

NTSTATUS WINAPI User32CallDDEPostFromKernel ( PVOID  Arguments,
ULONG  ArgumentLength 
)

Definition at line 256 of file dde.c.

257{
258 struct packed_message data;
259 BOOL Ret;
261 PDDEPOSTGET_CALLBACK_ARGUMENTS Common = Arguments;
262
263 data.data = 0;
264 data.size = 0;
265 TRACE("DDE Post CB\n");
266 Ret = post_dde_message( &data, Common->message, Common->lParam, &Common->lParam);
267
268 if (Ret)
269 {
270 Common->pvData = (PVOID)data.data;
271 Common->size = data.size;
272 TRACE("DDE Post CB size %d\n",data.size);
273 }
274 else
275 {
276 ERR("DDE Post CB Return bad msg 0x%x Size %d\n",Common->message,Common->size);
278 }
279
280 return ZwCallbackReturn(Arguments, ArgumentLength, Status);
281}
void * PVOID
Definition: typedefs.h:50
BOOL post_dde_message(struct packed_message *data, UINT message, LPARAM lParam, LPARAM *lp)
Definition: dde.c:53

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( ddeml  )