rpcrt4/tests: Replace || by |.
[wine/multimedia.git] / dlls / ole32 / usrmarshal.c
bloba92dfa0122757d0ce708e3072a429b7e1cf81865
1 /*
2 * Miscellaneous Marshaling Routines
4 * Copyright 2005 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
34 #include "ole2.h"
35 #include "oleauto.h"
36 #include "rpcproxy.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
42 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
43 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
44 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
46 static void dump_user_flags(ULONG *pFlags)
48 if (HIWORD(*pFlags) == NDR_LOCAL_DATA_REPRESENTATION)
49 TRACE("MAKELONG(NDR_LOCAL_REPRESENTATION, ");
50 else
51 TRACE("MAKELONG(0x%04x, ", HIWORD(*pFlags));
52 switch (LOWORD(*pFlags))
54 case MSHCTX_LOCAL: TRACE("MSHCTX_LOCAL)"); break;
55 case MSHCTX_NOSHAREDMEM: TRACE("MSHCTX_NOSHAREDMEM)"); break;
56 case MSHCTX_DIFFERENTMACHINE: TRACE("MSHCTX_DIFFERENTMACHINE)"); break;
57 case MSHCTX_INPROC: TRACE("MSHCTX_INPROC)"); break;
58 default: TRACE("%d)", LOWORD(*pFlags));
62 /******************************************************************************
63 * CLIPFORMAT_UserSize [OLE32.@]
65 * Calculates the buffer size required to marshal a clip format.
67 * PARAMS
68 * pFlags [I] Flags. See notes.
69 * StartingSize [I] Starting size of the buffer. This value is added on to
70 * the buffer size required for the clip format.
71 * pCF [I] Clip format to size.
73 * RETURNS
74 * The buffer size required to marshal a clip format plus the starting size.
76 * NOTES
77 * Even though the function is documented to take a pointer to an unsigned
78 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
79 * the first parameter is an unsigned long.
80 * This function is only intended to be called by the RPC runtime.
82 ULONG __RPC_USER CLIPFORMAT_UserSize(ULONG *pFlags, ULONG StartingSize, CLIPFORMAT *pCF)
84 ULONG size = StartingSize;
86 TRACE("("); dump_user_flags(pFlags); TRACE(", %d, %p\n", StartingSize, pCF);
88 size += sizeof(userCLIPFORMAT);
90 /* only need to marshal the name if it is not a pre-defined type and
91 * we are going remote */
92 if ((*pCF >= 0xc000) && (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE))
94 WCHAR format[255];
95 INT ret;
96 size += 3 * sizeof(INT);
97 /* urg! this function is badly designed because it won't tell us how
98 * much space is needed without doing a dummy run of storing the
99 * name into a buffer */
100 ret = GetClipboardFormatNameW(*pCF, format, sizeof(format)/sizeof(format[0])-1);
101 if (!ret)
102 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
103 size += (ret + 1) * sizeof(WCHAR);
105 return size;
108 /******************************************************************************
109 * CLIPFORMAT_UserMarshal [OLE32.@]
111 * Marshals a clip format into a buffer.
113 * PARAMS
114 * pFlags [I] Flags. See notes.
115 * pBuffer [I] Buffer to marshal the clip format into.
116 * pCF [I] Clip format to marshal.
118 * RETURNS
119 * The end of the marshaled data in the buffer.
121 * NOTES
122 * Even though the function is documented to take a pointer to an unsigned
123 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
124 * the first parameter is an unsigned long.
125 * This function is only intended to be called by the RPC runtime.
127 unsigned char * __RPC_USER CLIPFORMAT_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF)
129 wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer;
131 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &0x%04x\n", pBuffer, *pCF);
133 wirecf->u.dwValue = *pCF;
134 pBuffer += sizeof(*wirecf);
136 /* only need to marshal the name if it is not a pre-defined type and
137 * we are going remote */
138 if ((*pCF >= 0xc000) && (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE))
140 WCHAR format[255];
141 INT len;
142 wirecf->fContext = WDT_REMOTE_CALL;
143 len = GetClipboardFormatNameW(*pCF, format, sizeof(format)/sizeof(format[0])-1);
144 if (!len)
145 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
146 len += 1;
147 *(INT *)pBuffer = len;
148 pBuffer += sizeof(INT);
149 *(INT *)pBuffer = 0;
150 pBuffer += sizeof(INT);
151 *(INT *)pBuffer = len;
152 pBuffer += sizeof(INT);
153 TRACE("marshaling format name %s\n", debugstr_wn(format, len-1));
154 lstrcpynW((LPWSTR)pBuffer, format, len);
155 pBuffer += len * sizeof(WCHAR);
156 *(WCHAR *)pBuffer = '\0';
157 pBuffer += sizeof(WCHAR);
159 else
160 wirecf->fContext = WDT_INPROC_CALL;
162 return pBuffer;
165 /******************************************************************************
166 * CLIPFORMAT_UserUnmarshal [OLE32.@]
168 * Unmarshals a clip format from a buffer.
170 * PARAMS
171 * pFlags [I] Flags. See notes.
172 * pBuffer [I] Buffer to marshal the clip format from.
173 * pCF [O] Address that receive the unmarshaled clip format.
175 * RETURNS
176 * The end of the marshaled data in the buffer.
178 * NOTES
179 * Even though the function is documented to take a pointer to an unsigned
180 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
181 * the first parameter is an unsigned long.
182 * This function is only intended to be called by the RPC runtime.
184 unsigned char * __RPC_USER CLIPFORMAT_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF)
186 wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer;
188 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", pBuffer, pCF);
190 pBuffer += sizeof(*wirecf);
191 if (wirecf->fContext == WDT_INPROC_CALL)
192 *pCF = (CLIPFORMAT)wirecf->u.dwValue;
193 else if (wirecf->fContext == WDT_REMOTE_CALL)
195 CLIPFORMAT cf;
196 INT len = *(INT *)pBuffer;
197 pBuffer += sizeof(INT);
198 if (*(INT *)pBuffer != 0)
199 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
200 pBuffer += sizeof(INT);
201 if (*(INT *)pBuffer != len)
202 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
203 pBuffer += sizeof(INT);
204 if (((WCHAR *)pBuffer)[len] != '\0')
205 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
206 TRACE("unmarshaling clip format %s\n", debugstr_w((LPCWSTR)pBuffer));
207 cf = RegisterClipboardFormatW((LPCWSTR)pBuffer);
208 pBuffer += (len + 1) * sizeof(WCHAR);
209 if (!cf)
210 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
211 *pCF = cf;
213 else
214 /* code not really appropriate, but nearest I can find */
215 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
216 return pBuffer;
219 /******************************************************************************
220 * CLIPFORMAT_UserFree [OLE32.@]
222 * Frees an unmarshaled clip format.
224 * PARAMS
225 * pFlags [I] Flags. See notes.
226 * pCF [I] Clip format to free.
228 * RETURNS
229 * The end of the marshaled data in the buffer.
231 * NOTES
232 * Even though the function is documented to take a pointer to an unsigned
233 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB
234 * structure, of which the first parameter is an unsigned long.
235 * This function is only intended to be called by the RPC runtime.
237 void __RPC_USER CLIPFORMAT_UserFree(ULONG *pFlags, CLIPFORMAT *pCF)
239 /* there is no inverse of the RegisterClipboardFormat function,
240 * so nothing to do */
243 static ULONG __RPC_USER handle_UserSize(ULONG *pFlags, ULONG StartingSize, HANDLE *handle)
245 if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)
247 ERR("can't remote a local handle\n");
248 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
249 return StartingSize;
251 return StartingSize + sizeof(RemotableHandle);
254 static unsigned char * __RPC_USER handle_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
256 RemotableHandle *remhandle = (RemotableHandle *)pBuffer;
257 if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)
259 ERR("can't remote a local handle\n");
260 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
261 return pBuffer;
263 remhandle->fContext = WDT_INPROC_CALL;
264 remhandle->u.hInproc = (LONG_PTR)*handle;
265 return pBuffer + sizeof(RemotableHandle);
268 static unsigned char * __RPC_USER handle_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
270 RemotableHandle *remhandle = (RemotableHandle *)pBuffer;
271 if (remhandle->fContext != WDT_INPROC_CALL)
272 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
273 *handle = (HANDLE)remhandle->u.hInproc;
274 return pBuffer + sizeof(RemotableHandle);
277 static void __RPC_USER handle_UserFree(ULONG *pFlags, HANDLE *phMenu)
279 /* nothing to do */
282 #define IMPL_WIREM_HANDLE(type) \
283 ULONG __RPC_USER type##_UserSize(ULONG *pFlags, ULONG StartingSize, type *handle) \
285 TRACE("("); dump_user_flags(pFlags); TRACE(", %d, %p\n", StartingSize, handle); \
286 return handle_UserSize(pFlags, StartingSize, (HANDLE *)handle); \
289 unsigned char * __RPC_USER type##_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, type *handle) \
291 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", pBuffer, *handle); \
292 return handle_UserMarshal(pFlags, pBuffer, (HANDLE *)handle); \
295 unsigned char * __RPC_USER type##_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, type *handle) \
297 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", pBuffer, handle); \
298 return handle_UserUnmarshal(pFlags, pBuffer, (HANDLE *)handle); \
301 void __RPC_USER type##_UserFree(ULONG *pFlags, type *handle) \
303 TRACE("("); dump_user_flags(pFlags); TRACE(", &%p\n", *handle); \
304 return handle_UserFree(pFlags, (HANDLE *)handle); \
307 IMPL_WIREM_HANDLE(HACCEL)
308 IMPL_WIREM_HANDLE(HMENU)
309 IMPL_WIREM_HANDLE(HWND)
311 /******************************************************************************
312 * HGLOBAL_UserSize [OLE32.@]
314 ULONG __RPC_USER HGLOBAL_UserSize(ULONG *pFlags, ULONG StartingSize, HGLOBAL *phGlobal)
316 ULONG size = StartingSize;
318 TRACE("("); dump_user_flags(pFlags); TRACE(", %d, %p\n", StartingSize, phGlobal);
320 ALIGN_LENGTH(size, 3);
322 size += sizeof(ULONG);
324 if (LOWORD(*pFlags == MSHCTX_INPROC))
325 size += sizeof(HGLOBAL);
326 else
328 size += sizeof(ULONG);
329 if (*phGlobal)
331 SIZE_T ret;
332 size += 3 * sizeof(ULONG);
333 ret = GlobalSize(*phGlobal);
334 size += (ULONG)ret;
338 return size;
341 unsigned char * __RPC_USER HGLOBAL_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HGLOBAL *phGlobal)
343 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", pBuffer, *phGlobal);
345 ALIGN_POINTER(pBuffer, 3);
347 if (LOWORD(*pFlags == MSHCTX_INPROC))
349 if (sizeof(*phGlobal) == 8)
350 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
351 else
352 *(ULONG *)pBuffer = WDT_INPROC_CALL;
353 pBuffer += sizeof(ULONG);
354 *(HGLOBAL *)pBuffer = *phGlobal;
355 pBuffer += sizeof(HGLOBAL);
357 else
359 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
360 pBuffer += sizeof(ULONG);
361 *(ULONG *)pBuffer = (ULONG)*phGlobal;
362 pBuffer += sizeof(ULONG);
363 if (*phGlobal)
365 const unsigned char *memory;
366 SIZE_T size = GlobalSize(*phGlobal);
367 *(ULONG *)pBuffer = (ULONG)size;
368 pBuffer += sizeof(ULONG);
369 *(ULONG *)pBuffer = (ULONG)*phGlobal;
370 pBuffer += sizeof(ULONG);
371 *(ULONG *)pBuffer = (ULONG)size;
372 pBuffer += sizeof(ULONG);
374 memory = GlobalLock(*phGlobal);
375 memcpy(pBuffer, memory, size);
376 pBuffer += size;
377 GlobalUnlock(*phGlobal);
381 return pBuffer;
384 unsigned char * __RPC_USER HGLOBAL_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HGLOBAL *phGlobal)
386 ULONG fContext;
388 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", pBuffer, *phGlobal);
390 ALIGN_POINTER(pBuffer, 3);
392 fContext = *(ULONG *)pBuffer;
393 pBuffer += sizeof(ULONG);
395 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phGlobal) < 8)) ||
396 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phGlobal) == 8)))
398 *phGlobal = *(HGLOBAL *)pBuffer;
399 pBuffer += sizeof(*phGlobal);
401 else if (fContext == WDT_REMOTE_CALL)
403 ULONG handle;
405 handle = *(ULONG *)pBuffer;
406 pBuffer += sizeof(ULONG);
408 if (handle)
410 ULONG size;
411 void *memory;
413 size = *(ULONG *)pBuffer;
414 pBuffer += sizeof(ULONG);
415 /* redundancy is bad - it means you have to check consistency like
416 * this: */
417 if (*(ULONG *)pBuffer != handle)
419 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
420 return pBuffer;
422 pBuffer += sizeof(ULONG);
423 /* redundancy is bad - it means you have to check consistency like
424 * this: */
425 if (*(ULONG *)pBuffer != size)
427 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
428 return pBuffer;
430 pBuffer += sizeof(ULONG);
432 /* FIXME: check size is not too big */
434 *phGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
435 memory = GlobalLock(*phGlobal);
436 memcpy(memory, pBuffer, size);
437 pBuffer += size;
438 GlobalUnlock(*phGlobal);
440 else
441 *phGlobal = NULL;
443 else
444 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
446 return pBuffer;
449 /******************************************************************************
450 * HGLOBAL_UserFree [OLE32.@]
452 void __RPC_USER HGLOBAL_UserFree(ULONG *pFlags, HGLOBAL *phGlobal)
454 TRACE("("); dump_user_flags(pFlags); TRACE(", &%p\n", *phGlobal);
456 if (LOWORD(*pFlags != MSHCTX_INPROC) && *phGlobal)
457 GlobalFree(*phGlobal);
460 ULONG __RPC_USER HBITMAP_UserSize(ULONG *pFlags, ULONG StartingSize, HBITMAP *phBmp)
462 FIXME(":stub\n");
463 return StartingSize;
466 unsigned char * __RPC_USER HBITMAP_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HBITMAP *phBmp)
468 FIXME(":stub\n");
469 return pBuffer;
472 unsigned char * __RPC_USER HBITMAP_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HBITMAP *phBmp)
474 FIXME(":stub\n");
475 return pBuffer;
478 void __RPC_USER HBITMAP_UserFree(ULONG *pFlags, HBITMAP *phBmp)
480 FIXME(":stub\n");
483 ULONG __RPC_USER HDC_UserSize(ULONG *pFlags, ULONG StartingSize, HDC *phdc)
485 FIXME(":stub\n");
486 return StartingSize;
489 unsigned char * __RPC_USER HDC_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HDC *phdc)
491 FIXME(":stub\n");
492 return pBuffer;
495 unsigned char * __RPC_USER HDC_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HDC *phdc)
497 FIXME(":stub\n");
498 return pBuffer;
501 void __RPC_USER HDC_UserFree(ULONG *pFlags, HDC *phdc)
503 FIXME(":stub\n");
506 ULONG __RPC_USER HPALETTE_UserSize(ULONG *pFlags, ULONG StartingSize, HPALETTE *phPal)
508 FIXME(":stub\n");
509 return StartingSize;
512 unsigned char * __RPC_USER HPALETTE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HPALETTE *phPal)
514 FIXME(":stub\n");
515 return pBuffer;
518 unsigned char * __RPC_USER HPALETTE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HPALETTE *phPal)
520 FIXME(":stub\n");
521 return pBuffer;
524 void __RPC_USER HPALETTE_UserFree(ULONG *pFlags, HPALETTE *phPal)
526 FIXME(":stub\n");
530 ULONG __RPC_USER HENHMETAFILE_UserSize(ULONG *pFlags, ULONG StartingSize, HENHMETAFILE *phEmf)
532 ULONG size = StartingSize;
534 TRACE("("); dump_user_flags(pFlags); TRACE(", %d, %p\n", StartingSize, *phEmf);
536 size += sizeof(ULONG);
537 if (LOWORD(*pFlags) == MSHCTX_INPROC)
538 size += sizeof(ULONG_PTR);
539 else
541 size += sizeof(ULONG);
543 if (*phEmf)
545 UINT emfsize;
547 size += 2 * sizeof(ULONG);
548 emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
549 size += emfsize;
553 return size;
556 unsigned char * __RPC_USER HENHMETAFILE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
558 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", pBuffer, *phEmf);
560 if (LOWORD(*pFlags) == MSHCTX_INPROC)
562 if (sizeof(*phEmf) == 8)
563 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
564 else
565 *(ULONG *)pBuffer = WDT_INPROC_CALL;
566 pBuffer += sizeof(ULONG);
567 *(HENHMETAFILE *)pBuffer = *phEmf;
568 pBuffer += sizeof(HENHMETAFILE);
570 else
572 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
573 pBuffer += sizeof(ULONG);
574 *(ULONG *)pBuffer = (ULONG)(ULONG_PTR)*phEmf;
575 pBuffer += sizeof(ULONG);
577 if (*phEmf)
579 UINT emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
581 *(ULONG *)pBuffer = emfsize;
582 pBuffer += sizeof(ULONG);
583 *(ULONG *)pBuffer = emfsize;
584 pBuffer += sizeof(ULONG);
585 GetEnhMetaFileBits(*phEmf, emfsize, pBuffer);
586 pBuffer += emfsize;
590 return pBuffer;
593 unsigned char * __RPC_USER HENHMETAFILE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
595 ULONG fContext;
597 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", pBuffer, phEmf);
599 fContext = *(ULONG *)pBuffer;
600 pBuffer += sizeof(ULONG);
602 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phEmf) < 8)) ||
603 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phEmf) == 8)))
605 *phEmf = *(HENHMETAFILE *)pBuffer;
606 pBuffer += sizeof(*phEmf);
608 else if (fContext == WDT_REMOTE_CALL)
610 ULONG handle;
612 handle = *(ULONG *)pBuffer;
613 pBuffer += sizeof(ULONG);
615 if (handle)
617 ULONG size;
618 size = *(ULONG *)pBuffer;
619 pBuffer += sizeof(ULONG);
620 if (size != *(ULONG *)pBuffer)
622 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
623 return pBuffer;
625 pBuffer += sizeof(ULONG);
626 *phEmf = SetEnhMetaFileBits(size, pBuffer);
627 pBuffer += size;
629 else
630 *phEmf = NULL;
632 else
633 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
635 return pBuffer;
638 void __RPC_USER HENHMETAFILE_UserFree(ULONG *pFlags, HENHMETAFILE *phEmf)
640 TRACE("("); dump_user_flags(pFlags); TRACE(", &%p\n", *phEmf);
642 if (LOWORD(*pFlags) != MSHCTX_INPROC)
643 DeleteEnhMetaFile(*phEmf);
646 ULONG __RPC_USER STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, STGMEDIUM *pStgMedium)
648 ULONG size = StartingSize;
650 TRACE("("); dump_user_flags(pFlags); TRACE(", %d, %p\n", StartingSize, pStgMedium);
652 ALIGN_LENGTH(size, 3);
654 size += 2 * sizeof(DWORD);
655 if (pStgMedium->tymed != TYMED_NULL)
656 size += sizeof(DWORD);
658 switch (pStgMedium->tymed)
660 case TYMED_NULL:
661 TRACE("TYMED_NULL\n");
662 break;
663 case TYMED_HGLOBAL:
664 TRACE("TYMED_HGLOBAL\n");
665 size = HGLOBAL_UserSize(pFlags, size, &pStgMedium->u.hGlobal);
666 break;
667 case TYMED_FILE:
668 FIXME("TYMED_FILE\n");
669 break;
670 case TYMED_ISTREAM:
671 FIXME("TYMED_ISTREAM\n");
672 break;
673 case TYMED_ISTORAGE:
674 FIXME("TYMED_ISTORAGE\n");
675 break;
676 case TYMED_GDI:
677 FIXME("TYMED_GDI\n");
678 break;
679 case TYMED_MFPICT:
680 FIXME("TYMED_MFPICT\n");
681 break;
682 case TYMED_ENHMF:
683 TRACE("TYMED_ENHMF\n");
684 size = HENHMETAFILE_UserSize(pFlags, size, &pStgMedium->u.hEnhMetaFile);
685 break;
686 default:
687 RaiseException(DV_E_TYMED, 0, 0, NULL);
690 if (pStgMedium->pUnkForRelease)
691 FIXME("buffer size pUnkForRelease\n");
693 return size;
696 unsigned char * __RPC_USER STGMEDIUM_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, STGMEDIUM *pStgMedium)
698 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", pBuffer, pStgMedium);
700 ALIGN_POINTER(pBuffer, 3);
702 *(DWORD *)pBuffer = pStgMedium->tymed;
703 pBuffer += sizeof(DWORD);
704 if (pStgMedium->tymed != TYMED_NULL)
706 *(DWORD *)pBuffer = (DWORD)(DWORD_PTR)pStgMedium->u.pstg;
707 pBuffer += sizeof(DWORD);
709 *(DWORD *)pBuffer = (DWORD)(DWORD_PTR)pStgMedium->pUnkForRelease;
710 pBuffer += sizeof(DWORD);
712 switch (pStgMedium->tymed)
714 case TYMED_NULL:
715 TRACE("TYMED_NULL\n");
716 break;
717 case TYMED_HGLOBAL:
718 TRACE("TYMED_HGLOBAL\n");
719 pBuffer = HGLOBAL_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hGlobal);
720 break;
721 case TYMED_FILE:
722 FIXME("TYMED_FILE\n");
723 break;
724 case TYMED_ISTREAM:
725 FIXME("TYMED_ISTREAM\n");
726 break;
727 case TYMED_ISTORAGE:
728 FIXME("TYMED_ISTORAGE\n");
729 break;
730 case TYMED_GDI:
731 FIXME("TYMED_GDI\n");
732 break;
733 case TYMED_MFPICT:
734 FIXME("TYMED_MFPICT\n");
735 break;
736 case TYMED_ENHMF:
737 TRACE("TYMED_ENHMF\n");
738 pBuffer = HENHMETAFILE_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hEnhMetaFile);
739 break;
740 default:
741 RaiseException(DV_E_TYMED, 0, 0, NULL);
744 if (pStgMedium->pUnkForRelease)
745 FIXME("marshal pUnkForRelease\n");
747 return pBuffer;
750 unsigned char * __RPC_USER STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, STGMEDIUM *pStgMedium)
752 DWORD content;
753 DWORD releaseunk;
755 ALIGN_POINTER(pBuffer, 3);
757 TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", pBuffer, pStgMedium);
759 pStgMedium->tymed = *(DWORD *)pBuffer;
760 pBuffer += sizeof(DWORD);
761 if (pStgMedium->tymed != TYMED_NULL)
763 content = *(DWORD *)pBuffer;
764 pBuffer += sizeof(DWORD);
766 releaseunk = *(DWORD *)pBuffer;
767 pBuffer += sizeof(DWORD);
769 switch (pStgMedium->tymed)
771 case TYMED_NULL:
772 TRACE("TYMED_NULL\n");
773 break;
774 case TYMED_HGLOBAL:
775 TRACE("TYMED_HGLOBAL\n");
776 pBuffer = HGLOBAL_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hGlobal);
777 break;
778 case TYMED_FILE:
779 FIXME("TYMED_FILE\n");
780 break;
781 case TYMED_ISTREAM:
782 FIXME("TYMED_ISTREAM\n");
783 break;
784 case TYMED_ISTORAGE:
785 FIXME("TYMED_ISTORAGE\n");
786 break;
787 case TYMED_GDI:
788 FIXME("TYMED_GDI\n");
789 break;
790 case TYMED_MFPICT:
791 FIXME("TYMED_MFPICT\n");
792 break;
793 case TYMED_ENHMF:
794 TRACE("TYMED_ENHMF\n");
795 pBuffer = HENHMETAFILE_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hEnhMetaFile);
796 break;
797 default:
798 RaiseException(DV_E_TYMED, 0, 0, NULL);
801 pStgMedium->pUnkForRelease = NULL;
802 if (releaseunk)
803 FIXME("unmarshal pUnkForRelease\n");
805 return pBuffer;
808 void __RPC_USER STGMEDIUM_UserFree(ULONG *pFlags, STGMEDIUM *pStgMedium)
810 TRACE("("); dump_user_flags(pFlags); TRACE(", %p\n", pStgMedium);
812 ReleaseStgMedium(pStgMedium);
815 ULONG __RPC_USER ASYNC_STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, ASYNC_STGMEDIUM *pStgMedium)
817 FIXME(":stub\n");
818 return StartingSize;
821 unsigned char * __RPC_USER ASYNC_STGMEDIUM_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, ASYNC_STGMEDIUM *pStgMedium)
823 FIXME(":stub\n");
824 return pBuffer;
827 unsigned char * __RPC_USER ASYNC_STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, ASYNC_STGMEDIUM *pStgMedium)
829 FIXME(":stub\n");
830 return pBuffer;
833 void __RPC_USER ASYNC_STGMEDIUM_UserFree(ULONG *pFlags, ASYNC_STGMEDIUM *pStgMedium)
835 FIXME(":stub\n");
838 ULONG __RPC_USER FLAG_STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, FLAG_STGMEDIUM *pStgMedium)
840 FIXME(":stub\n");
841 return StartingSize;
844 unsigned char * __RPC_USER FLAG_STGMEDIUM_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, FLAG_STGMEDIUM *pStgMedium)
846 FIXME(":stub\n");
847 return pBuffer;
850 unsigned char * __RPC_USER FLAG_STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, FLAG_STGMEDIUM *pStgMedium)
852 FIXME(":stub\n");
853 return pBuffer;
856 void __RPC_USER FLAG_STGMEDIUM_UserFree(ULONG *pFlags, FLAG_STGMEDIUM *pStgMedium)
858 FIXME(":stub\n");
861 ULONG __RPC_USER SNB_UserSize(ULONG *pFlags, ULONG StartingSize, SNB *pSnb)
863 FIXME(":stub\n");
864 return StartingSize;
867 unsigned char * __RPC_USER SNB_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, SNB *pSnb)
869 FIXME(":stub\n");
870 return pBuffer;
873 unsigned char * __RPC_USER SNB_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, SNB *pSnb)
875 FIXME(":stub\n");
876 return pBuffer;
879 void __RPC_USER SNB_UserFree(ULONG *pFlags, SNB *pSnb)
881 FIXME(":stub\n");