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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
42 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
43 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
44 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
45 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
47 #define USER_MARSHAL_PTR_PREFIX \
48 ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
49 ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
51 static const char* debugstr_user_flags(ULONG *pFlags)
55 switch (LOWORD(*pFlags))
58 loword="MSHCTX_LOCAL";
60 case MSHCTX_NOSHAREDMEM:
61 loword="MSHCTX_NOSHAREDMEM";
63 case MSHCTX_DIFFERENTMACHINE:
64 loword="MSHCTX_DIFFERENTMACHINE";
67 loword="MSHCTX_INPROC";
70 sprintf(buf, "%d", LOWORD(*pFlags));
74 if (HIWORD(*pFlags) == NDR_LOCAL_DATA_REPRESENTATION)
75 return wine_dbg_sprintf("MAKELONG(NDR_LOCAL_REPRESENTATION, %s)", loword);
77 return wine_dbg_sprintf("MAKELONG(0x%04x, %s)", HIWORD(*pFlags), loword);
80 /******************************************************************************
81 * CLIPFORMAT_UserSize [OLE32.@]
83 * Calculates the buffer size required to marshal a clip format.
86 * pFlags [I] Flags. See notes.
87 * StartingSize [I] Starting size of the buffer. This value is added on to
88 * the buffer size required for the clip format.
89 * pCF [I] Clip format to size.
92 * The buffer size required to marshal a clip format plus the starting size.
95 * Even though the function is documented to take a pointer to an unsigned
96 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
97 * the first parameter is an unsigned long.
98 * This function is only intended to be called by the RPC runtime.
100 ULONG __RPC_USER CLIPFORMAT_UserSize(ULONG *pFlags, ULONG StartingSize, CLIPFORMAT *pCF)
102 ULONG size = StartingSize;
104 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, pCF);
106 size += sizeof(userCLIPFORMAT);
108 /* only need to marshal the name if it is not a pre-defined type and
109 * we are going remote */
110 if ((*pCF >= 0xc000) && (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE))
114 size += 3 * sizeof(INT);
115 /* urg! this function is badly designed because it won't tell us how
116 * much space is needed without doing a dummy run of storing the
117 * name into a buffer */
118 ret = GetClipboardFormatNameW(*pCF, format, sizeof(format)/sizeof(format[0])-1);
120 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
121 size += (ret + 1) * sizeof(WCHAR);
126 /******************************************************************************
127 * CLIPFORMAT_UserMarshal [OLE32.@]
129 * Marshals a clip format into a buffer.
132 * pFlags [I] Flags. See notes.
133 * pBuffer [I] Buffer to marshal the clip format into.
134 * pCF [I] Clip format to marshal.
137 * The end of the marshaled data in the buffer.
140 * Even though the function is documented to take a pointer to an unsigned
141 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
142 * the first parameter is an unsigned long.
143 * This function is only intended to be called by the RPC runtime.
145 unsigned char * __RPC_USER CLIPFORMAT_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF)
147 wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer;
149 TRACE("(%s, %p, &0x%04x\n", debugstr_user_flags(pFlags), pBuffer, *pCF);
151 wirecf->u.dwValue = *pCF;
152 pBuffer += sizeof(*wirecf);
154 /* only need to marshal the name if it is not a pre-defined type and
155 * we are going remote */
156 if ((*pCF >= 0xc000) && (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE))
160 wirecf->fContext = WDT_REMOTE_CALL;
161 len = GetClipboardFormatNameW(*pCF, format, sizeof(format)/sizeof(format[0])-1);
163 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
165 *(INT *)pBuffer = len;
166 pBuffer += sizeof(INT);
168 pBuffer += sizeof(INT);
169 *(INT *)pBuffer = len;
170 pBuffer += sizeof(INT);
171 TRACE("marshaling format name %s\n", debugstr_wn(format, len-1));
172 lstrcpynW((LPWSTR)pBuffer, format, len);
173 pBuffer += len * sizeof(WCHAR);
174 *(WCHAR *)pBuffer = '\0';
175 pBuffer += sizeof(WCHAR);
178 wirecf->fContext = WDT_INPROC_CALL;
183 /******************************************************************************
184 * CLIPFORMAT_UserUnmarshal [OLE32.@]
186 * Unmarshals a clip format from a buffer.
189 * pFlags [I] Flags. See notes.
190 * pBuffer [I] Buffer to marshal the clip format from.
191 * pCF [O] Address that receive the unmarshaled clip format.
194 * The end of the marshaled data in the buffer.
197 * Even though the function is documented to take a pointer to an unsigned
198 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
199 * the first parameter is an unsigned long.
200 * This function is only intended to be called by the RPC runtime.
202 unsigned char * __RPC_USER CLIPFORMAT_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF)
204 wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer;
206 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, pCF);
208 pBuffer += sizeof(*wirecf);
209 if (wirecf->fContext == WDT_INPROC_CALL)
210 *pCF = (CLIPFORMAT)wirecf->u.dwValue;
211 else if (wirecf->fContext == WDT_REMOTE_CALL)
214 INT len = *(INT *)pBuffer;
215 pBuffer += sizeof(INT);
216 if (*(INT *)pBuffer != 0)
217 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
218 pBuffer += sizeof(INT);
219 if (*(INT *)pBuffer != len)
220 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
221 pBuffer += sizeof(INT);
222 if (((WCHAR *)pBuffer)[len] != '\0')
223 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
224 TRACE("unmarshaling clip format %s\n", debugstr_w((LPCWSTR)pBuffer));
225 cf = RegisterClipboardFormatW((LPCWSTR)pBuffer);
226 pBuffer += (len + 1) * sizeof(WCHAR);
228 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
232 /* code not really appropriate, but nearest I can find */
233 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
237 /******************************************************************************
238 * CLIPFORMAT_UserFree [OLE32.@]
240 * Frees an unmarshaled clip format.
243 * pFlags [I] Flags. See notes.
244 * pCF [I] Clip format to free.
247 * The end of the marshaled data in the buffer.
250 * Even though the function is documented to take a pointer to an unsigned
251 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB
252 * structure, of which the first parameter is an unsigned long.
253 * This function is only intended to be called by the RPC runtime.
255 void __RPC_USER CLIPFORMAT_UserFree(ULONG *pFlags, CLIPFORMAT *pCF)
257 /* there is no inverse of the RegisterClipboardFormat function,
258 * so nothing to do */
261 static ULONG __RPC_USER handle_UserSize(ULONG *pFlags, ULONG StartingSize, HANDLE *handle)
263 if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)
265 ERR("can't remote a local handle\n");
266 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
269 return StartingSize + sizeof(RemotableHandle);
272 static unsigned char * __RPC_USER handle_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
274 RemotableHandle *remhandle = (RemotableHandle *)pBuffer;
275 if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)
277 ERR("can't remote a local handle\n");
278 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
281 remhandle->fContext = WDT_INPROC_CALL;
282 remhandle->u.hInproc = (LONG_PTR)*handle;
283 return pBuffer + sizeof(RemotableHandle);
286 static unsigned char * __RPC_USER handle_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
288 RemotableHandle *remhandle = (RemotableHandle *)pBuffer;
289 if (remhandle->fContext != WDT_INPROC_CALL)
290 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
291 *handle = (HANDLE)remhandle->u.hInproc;
292 return pBuffer + sizeof(RemotableHandle);
295 static void __RPC_USER handle_UserFree(ULONG *pFlags, HANDLE *phMenu)
300 #define IMPL_WIREM_HANDLE(type) \
301 ULONG __RPC_USER type##_UserSize(ULONG *pFlags, ULONG StartingSize, type *handle) \
303 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, handle); \
304 return handle_UserSize(pFlags, StartingSize, (HANDLE *)handle); \
307 unsigned char * __RPC_USER type##_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, type *handle) \
309 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *handle); \
310 return handle_UserMarshal(pFlags, pBuffer, (HANDLE *)handle); \
313 unsigned char * __RPC_USER type##_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, type *handle) \
315 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, handle); \
316 return handle_UserUnmarshal(pFlags, pBuffer, (HANDLE *)handle); \
319 void __RPC_USER type##_UserFree(ULONG *pFlags, type *handle) \
321 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *handle); \
322 return handle_UserFree(pFlags, (HANDLE *)handle); \
325 IMPL_WIREM_HANDLE(HACCEL)
326 IMPL_WIREM_HANDLE(HMENU)
327 IMPL_WIREM_HANDLE(HWND)
329 /******************************************************************************
330 * HGLOBAL_UserSize [OLE32.@]
332 * Calculates the buffer size required to marshal an HGLOBAL.
335 * pFlags [I] Flags. See notes.
336 * StartingSize [I] Starting size of the buffer. This value is added on to
337 * the buffer size required for the clip format.
338 * phGlobal [I] HGLOBAL to size.
341 * The buffer size required to marshal an HGLOBAL plus the starting size.
344 * Even though the function is documented to take a pointer to a ULONG in
345 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
346 * the first parameter is a ULONG.
347 * This function is only intended to be called by the RPC runtime.
349 ULONG __RPC_USER HGLOBAL_UserSize(ULONG *pFlags, ULONG StartingSize, HGLOBAL *phGlobal)
351 ULONG size = StartingSize;
353 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, phGlobal);
355 ALIGN_LENGTH(size, 3);
357 size += sizeof(ULONG);
359 if (LOWORD(*pFlags == MSHCTX_INPROC))
360 size += sizeof(HGLOBAL);
363 size += sizeof(ULONG);
367 size += 3 * sizeof(ULONG);
368 ret = GlobalSize(*phGlobal);
376 /******************************************************************************
377 * HGLOBAL_UserMarshal [OLE32.@]
379 * Marshals an HGLOBAL into a buffer.
382 * pFlags [I] Flags. See notes.
383 * pBuffer [I] Buffer to marshal the clip format into.
384 * phGlobal [I] HGLOBAL to marshal.
387 * The end of the marshaled data in the buffer.
390 * Even though the function is documented to take a pointer to a ULONG in
391 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
392 * the first parameter is a ULONG.
393 * This function is only intended to be called by the RPC runtime.
395 unsigned char * __RPC_USER HGLOBAL_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HGLOBAL *phGlobal)
397 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phGlobal);
399 ALIGN_POINTER(pBuffer, 3);
401 if (LOWORD(*pFlags == MSHCTX_INPROC))
403 if (sizeof(*phGlobal) == 8)
404 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
406 *(ULONG *)pBuffer = WDT_INPROC_CALL;
407 pBuffer += sizeof(ULONG);
408 *(HGLOBAL *)pBuffer = *phGlobal;
409 pBuffer += sizeof(HGLOBAL);
413 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
414 pBuffer += sizeof(ULONG);
415 *(ULONG *)pBuffer = (ULONG)*phGlobal;
416 pBuffer += sizeof(ULONG);
419 const unsigned char *memory;
420 SIZE_T size = GlobalSize(*phGlobal);
421 *(ULONG *)pBuffer = (ULONG)size;
422 pBuffer += sizeof(ULONG);
423 *(ULONG *)pBuffer = (ULONG)*phGlobal;
424 pBuffer += sizeof(ULONG);
425 *(ULONG *)pBuffer = (ULONG)size;
426 pBuffer += sizeof(ULONG);
428 memory = GlobalLock(*phGlobal);
429 memcpy(pBuffer, memory, size);
431 GlobalUnlock(*phGlobal);
438 /******************************************************************************
439 * HGLOBAL_UserUnmarshal [OLE32.@]
441 * Unmarshals an HGLOBAL from a buffer.
444 * pFlags [I] Flags. See notes.
445 * pBuffer [I] Buffer to marshal the clip format from.
446 * phGlobal [O] Address that receive the unmarshaled HGLOBAL.
449 * The end of the marshaled data in the buffer.
452 * Even though the function is documented to take a pointer to an ULONG in
453 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
454 * the first parameter is an ULONG.
455 * This function is only intended to be called by the RPC runtime.
457 unsigned char * __RPC_USER HGLOBAL_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HGLOBAL *phGlobal)
461 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phGlobal);
463 ALIGN_POINTER(pBuffer, 3);
465 fContext = *(ULONG *)pBuffer;
466 pBuffer += sizeof(ULONG);
468 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phGlobal) < 8)) ||
469 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phGlobal) == 8)))
471 *phGlobal = *(HGLOBAL *)pBuffer;
472 pBuffer += sizeof(*phGlobal);
474 else if (fContext == WDT_REMOTE_CALL)
478 handle = *(ULONG *)pBuffer;
479 pBuffer += sizeof(ULONG);
486 size = *(ULONG *)pBuffer;
487 pBuffer += sizeof(ULONG);
488 /* redundancy is bad - it means you have to check consistency like
490 if (*(ULONG *)pBuffer != handle)
492 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
495 pBuffer += sizeof(ULONG);
496 /* redundancy is bad - it means you have to check consistency like
498 if (*(ULONG *)pBuffer != size)
500 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
503 pBuffer += sizeof(ULONG);
505 /* FIXME: check size is not too big */
507 *phGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
508 memory = GlobalLock(*phGlobal);
509 memcpy(memory, pBuffer, size);
511 GlobalUnlock(*phGlobal);
517 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
522 /******************************************************************************
523 * HGLOBAL_UserFree [OLE32.@]
525 * Frees an unmarshaled HGLOBAL.
528 * pFlags [I] Flags. See notes.
529 * phGlobal [I] HGLOBAL to free.
532 * The end of the marshaled data in the buffer.
535 * Even though the function is documented to take a pointer to a ULONG in
536 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
537 * which the first parameter is a ULONG.
538 * This function is only intended to be called by the RPC runtime.
540 void __RPC_USER HGLOBAL_UserFree(ULONG *pFlags, HGLOBAL *phGlobal)
542 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phGlobal);
544 if (LOWORD(*pFlags != MSHCTX_INPROC) && *phGlobal)
545 GlobalFree(*phGlobal);
548 /******************************************************************************
549 * HBITMAP_UserSize [OLE32.@]
551 * Calculates the buffer size required to marshal a bitmap.
554 * pFlags [I] Flags. See notes.
555 * StartingSize [I] Starting size of the buffer. This value is added on to
556 * the buffer size required for the clip format.
557 * phBmp [I] Bitmap to size.
560 * The buffer size required to marshal an bitmap plus the starting size.
563 * Even though the function is documented to take a pointer to a ULONG in
564 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
565 * the first parameter is a ULONG.
566 * This function is only intended to be called by the RPC runtime.
568 ULONG __RPC_USER HBITMAP_UserSize(ULONG *pFlags, ULONG StartingSize, HBITMAP *phBmp)
574 /******************************************************************************
575 * HBITMAP_UserMarshal [OLE32.@]
577 * Marshals a bitmap into a buffer.
580 * pFlags [I] Flags. See notes.
581 * pBuffer [I] Buffer to marshal the clip format into.
582 * phBmp [I] Bitmap to marshal.
585 * The end of the marshaled data in the buffer.
588 * Even though the function is documented to take a pointer to a ULONG in
589 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
590 * the first parameter is a ULONG.
591 * This function is only intended to be called by the RPC runtime.
593 unsigned char * __RPC_USER HBITMAP_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HBITMAP *phBmp)
599 /******************************************************************************
600 * HBITMAP_UserUnmarshal [OLE32.@]
602 * Unmarshals a bitmap from a buffer.
605 * pFlags [I] Flags. See notes.
606 * pBuffer [I] Buffer to marshal the clip format from.
607 * phBmp [O] Address that receive the unmarshaled bitmap.
610 * The end of the marshaled data in the buffer.
613 * Even though the function is documented to take a pointer to an ULONG in
614 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
615 * the first parameter is an ULONG.
616 * This function is only intended to be called by the RPC runtime.
618 unsigned char * __RPC_USER HBITMAP_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HBITMAP *phBmp)
624 /******************************************************************************
625 * HBITMAP_UserFree [OLE32.@]
627 * Frees an unmarshaled bitmap.
630 * pFlags [I] Flags. See notes.
631 * phBmp [I] Bitmap to free.
634 * The end of the marshaled data in the buffer.
637 * Even though the function is documented to take a pointer to a ULONG in
638 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
639 * which the first parameter is a ULONG.
640 * This function is only intended to be called by the RPC runtime.
642 void __RPC_USER HBITMAP_UserFree(ULONG *pFlags, HBITMAP *phBmp)
647 /******************************************************************************
648 * HDC_UserSize [OLE32.@]
650 * Calculates the buffer size required to marshal an HDC.
653 * pFlags [I] Flags. See notes.
654 * StartingSize [I] Starting size of the buffer. This value is added on to
655 * the buffer size required for the clip format.
656 * phGlobal [I] HDC to size.
659 * The buffer size required to marshal an HDC plus the starting size.
662 * Even though the function is documented to take a pointer to a ULONG in
663 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
664 * the first parameter is a ULONG.
665 * This function is only intended to be called by the RPC runtime.
667 ULONG __RPC_USER HDC_UserSize(ULONG *pFlags, ULONG StartingSize, HDC *phdc)
673 /******************************************************************************
674 * HDC_UserMarshal [OLE32.@]
676 * Marshals an HDC into a buffer.
679 * pFlags [I] Flags. See notes.
680 * pBuffer [I] Buffer to marshal the clip format into.
681 * phdc [I] HDC to marshal.
684 * The end of the marshaled data in the buffer.
687 * Even though the function is documented to take a pointer to a ULONG in
688 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
689 * the first parameter is a ULONG.
690 * This function is only intended to be called by the RPC runtime.
692 unsigned char * __RPC_USER HDC_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HDC *phdc)
698 /******************************************************************************
699 * HDC_UserUnmarshal [OLE32.@]
701 * Unmarshals an HDC from a buffer.
704 * pFlags [I] Flags. See notes.
705 * pBuffer [I] Buffer to marshal the clip format from.
706 * phdc [O] Address that receive the unmarshaled HDC.
709 * The end of the marshaled data in the buffer.
712 * Even though the function is documented to take a pointer to an ULONG in
713 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
714 * the first parameter is an ULONG.
715 * This function is only intended to be called by the RPC runtime.
717 unsigned char * __RPC_USER HDC_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HDC *phdc)
723 /******************************************************************************
724 * HDC_UserFree [OLE32.@]
726 * Frees an unmarshaled HDC.
729 * pFlags [I] Flags. See notes.
730 * phdc [I] HDC to free.
733 * The end of the marshaled data in the buffer.
736 * Even though the function is documented to take a pointer to a ULONG in
737 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
738 * which the first parameter is a ULONG.
739 * This function is only intended to be called by the RPC runtime.
741 void __RPC_USER HDC_UserFree(ULONG *pFlags, HDC *phdc)
746 /******************************************************************************
747 * HPALETTE_UserSize [OLE32.@]
749 * Calculates the buffer size required to marshal a palette.
752 * pFlags [I] Flags. See notes.
753 * StartingSize [I] Starting size of the buffer. This value is added on to
754 * the buffer size required for the clip format.
755 * phPal [I] Palette to size.
758 * The buffer size required to marshal a palette plus the starting size.
761 * Even though the function is documented to take a pointer to a ULONG in
762 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
763 * the first parameter is a ULONG.
764 * This function is only intended to be called by the RPC runtime.
766 ULONG __RPC_USER HPALETTE_UserSize(ULONG *pFlags, ULONG StartingSize, HPALETTE *phPal)
772 /******************************************************************************
773 * HPALETTE_UserMarshal [OLE32.@]
775 * Marshals a palette into a buffer.
778 * pFlags [I] Flags. See notes.
779 * pBuffer [I] Buffer to marshal the clip format into.
780 * phPal [I] Palette to marshal.
783 * The end of the marshaled data in the buffer.
786 * Even though the function is documented to take a pointer to a ULONG in
787 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
788 * the first parameter is a ULONG.
789 * This function is only intended to be called by the RPC runtime.
791 unsigned char * __RPC_USER HPALETTE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HPALETTE *phPal)
797 /******************************************************************************
798 * HPALETTE_UserUnmarshal [OLE32.@]
800 * Unmarshals a palette from a buffer.
803 * pFlags [I] Flags. See notes.
804 * pBuffer [I] Buffer to marshal the clip format from.
805 * phPal [O] Address that receive the unmarshaled palette.
808 * The end of the marshaled data in the buffer.
811 * Even though the function is documented to take a pointer to an ULONG in
812 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
813 * the first parameter is an ULONG.
814 * This function is only intended to be called by the RPC runtime.
816 unsigned char * __RPC_USER HPALETTE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HPALETTE *phPal)
822 /******************************************************************************
823 * HPALETTE_UserFree [OLE32.@]
825 * Frees an unmarshaled palette.
828 * pFlags [I] Flags. See notes.
829 * phPal [I] Palette to free.
832 * The end of the marshaled data in the buffer.
835 * Even though the function is documented to take a pointer to a ULONG in
836 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
837 * which the first parameter is a ULONG.
838 * This function is only intended to be called by the RPC runtime.
840 void __RPC_USER HPALETTE_UserFree(ULONG *pFlags, HPALETTE *phPal)
846 /******************************************************************************
847 * HMETAFILE_UserSize [OLE32.@]
849 * Calculates the buffer size required to marshal a metafile.
852 * pFlags [I] Flags. See notes.
853 * StartingSize [I] Starting size of the buffer. This value is added on to
854 * the buffer size required for the clip format.
855 * phmf [I] Metafile to size.
858 * The buffer size required to marshal a metafile plus the starting size.
861 * Even though the function is documented to take a pointer to a ULONG in
862 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
863 * the first parameter is a ULONG.
864 * This function is only intended to be called by the RPC runtime.
866 ULONG __RPC_USER HMETAFILE_UserSize(ULONG *pFlags, ULONG StartingSize, HMETAFILE *phmf)
868 ULONG size = StartingSize;
870 TRACE("(%s, %d, &%p\n", debugstr_user_flags(pFlags), StartingSize, *phmf);
872 ALIGN_LENGTH(size, 3);
874 size += sizeof(ULONG);
875 if (LOWORD(*pFlags) == MSHCTX_INPROC)
876 size += sizeof(ULONG_PTR);
879 size += sizeof(ULONG);
885 size += 2 * sizeof(ULONG);
886 mfsize = GetMetaFileBitsEx(*phmf, 0, NULL);
894 /******************************************************************************
895 * HMETAFILE_UserMarshal [OLE32.@]
897 * Marshals a metafile into a buffer.
900 * pFlags [I] Flags. See notes.
901 * pBuffer [I] Buffer to marshal the clip format into.
902 * phEmf [I] Metafile to marshal.
905 * The end of the marshaled data in the buffer.
908 * Even though the function is documented to take a pointer to a ULONG in
909 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
910 * the first parameter is a ULONG.
911 * This function is only intended to be called by the RPC runtime.
913 unsigned char * __RPC_USER HMETAFILE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILE *phmf)
915 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phmf);
917 ALIGN_POINTER(pBuffer, 3);
919 if (LOWORD(*pFlags) == MSHCTX_INPROC)
921 if (sizeof(*phmf) == 8)
922 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
924 *(ULONG *)pBuffer = WDT_INPROC_CALL;
925 pBuffer += sizeof(ULONG);
926 *(HMETAFILE *)pBuffer = *phmf;
927 pBuffer += sizeof(HMETAFILE);
931 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
932 pBuffer += sizeof(ULONG);
933 *(ULONG *)pBuffer = (ULONG)(ULONG_PTR)*phmf;
934 pBuffer += sizeof(ULONG);
938 UINT mfsize = GetMetaFileBitsEx(*phmf, 0, NULL);
940 *(ULONG *)pBuffer = mfsize;
941 pBuffer += sizeof(ULONG);
942 *(ULONG *)pBuffer = mfsize;
943 pBuffer += sizeof(ULONG);
944 GetMetaFileBitsEx(*phmf, mfsize, pBuffer);
952 /******************************************************************************
953 * HMETAFILE_UserUnmarshal [OLE32.@]
955 * Unmarshals a metafile from a buffer.
958 * pFlags [I] Flags. See notes.
959 * pBuffer [I] Buffer to marshal the clip format from.
960 * phmf [O] Address that receive the unmarshaled metafile.
963 * The end of the marshaled data in the buffer.
966 * Even though the function is documented to take a pointer to an ULONG in
967 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
968 * the first parameter is an ULONG.
969 * This function is only intended to be called by the RPC runtime.
971 unsigned char * __RPC_USER HMETAFILE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILE *phmf)
975 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, phmf);
977 ALIGN_POINTER(pBuffer, 3);
979 fContext = *(ULONG *)pBuffer;
980 pBuffer += sizeof(ULONG);
982 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phmf) < 8)) ||
983 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phmf) == 8)))
985 *phmf = *(HMETAFILE *)pBuffer;
986 pBuffer += sizeof(*phmf);
988 else if (fContext == WDT_REMOTE_CALL)
992 handle = *(ULONG *)pBuffer;
993 pBuffer += sizeof(ULONG);
998 size = *(ULONG *)pBuffer;
999 pBuffer += sizeof(ULONG);
1000 if (size != *(ULONG *)pBuffer)
1002 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
1005 pBuffer += sizeof(ULONG);
1006 *phmf = SetMetaFileBitsEx(size, pBuffer);
1013 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
1018 /******************************************************************************
1019 * HMETAFILE_UserFree [OLE32.@]
1021 * Frees an unmarshaled metafile.
1024 * pFlags [I] Flags. See notes.
1025 * phmf [I] Metafile to free.
1028 * The end of the marshaled data in the buffer.
1031 * Even though the function is documented to take a pointer to a ULONG in
1032 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1033 * which the first parameter is a ULONG.
1034 * This function is only intended to be called by the RPC runtime.
1036 void __RPC_USER HMETAFILE_UserFree(ULONG *pFlags, HMETAFILE *phmf)
1038 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phmf);
1040 if (LOWORD(*pFlags) != MSHCTX_INPROC)
1041 DeleteMetaFile(*phmf);
1044 /******************************************************************************
1045 * HENHMETAFILE_UserSize [OLE32.@]
1047 * Calculates the buffer size required to marshal an enhanced metafile.
1050 * pFlags [I] Flags. See notes.
1051 * StartingSize [I] Starting size of the buffer. This value is added on to
1052 * the buffer size required for the clip format.
1053 * phEmf [I] Enhanced metafile to size.
1056 * The buffer size required to marshal an enhanced metafile plus the starting size.
1059 * Even though the function is documented to take a pointer to a ULONG in
1060 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1061 * the first parameter is a ULONG.
1062 * This function is only intended to be called by the RPC runtime.
1064 ULONG __RPC_USER HENHMETAFILE_UserSize(ULONG *pFlags, ULONG StartingSize, HENHMETAFILE *phEmf)
1066 ULONG size = StartingSize;
1068 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, *phEmf);
1070 size += sizeof(ULONG);
1071 if (LOWORD(*pFlags) == MSHCTX_INPROC)
1072 size += sizeof(ULONG_PTR);
1075 size += sizeof(ULONG);
1081 size += 2 * sizeof(ULONG);
1082 emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
1090 /******************************************************************************
1091 * HENHMETAFILE_UserMarshal [OLE32.@]
1093 * Marshals an enhance metafile into a buffer.
1096 * pFlags [I] Flags. See notes.
1097 * pBuffer [I] Buffer to marshal the clip format into.
1098 * phEmf [I] Enhanced metafile to marshal.
1101 * The end of the marshaled data in the buffer.
1104 * Even though the function is documented to take a pointer to a ULONG in
1105 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1106 * the first parameter is a ULONG.
1107 * This function is only intended to be called by the RPC runtime.
1109 unsigned char * __RPC_USER HENHMETAFILE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
1111 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phEmf);
1113 if (LOWORD(*pFlags) == MSHCTX_INPROC)
1115 if (sizeof(*phEmf) == 8)
1116 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
1118 *(ULONG *)pBuffer = WDT_INPROC_CALL;
1119 pBuffer += sizeof(ULONG);
1120 *(HENHMETAFILE *)pBuffer = *phEmf;
1121 pBuffer += sizeof(HENHMETAFILE);
1125 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
1126 pBuffer += sizeof(ULONG);
1127 *(ULONG *)pBuffer = (ULONG)(ULONG_PTR)*phEmf;
1128 pBuffer += sizeof(ULONG);
1132 UINT emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
1134 *(ULONG *)pBuffer = emfsize;
1135 pBuffer += sizeof(ULONG);
1136 *(ULONG *)pBuffer = emfsize;
1137 pBuffer += sizeof(ULONG);
1138 GetEnhMetaFileBits(*phEmf, emfsize, pBuffer);
1146 /******************************************************************************
1147 * HENHMETAFILE_UserUnmarshal [OLE32.@]
1149 * Unmarshals an enhanced metafile from a buffer.
1152 * pFlags [I] Flags. See notes.
1153 * pBuffer [I] Buffer to marshal the clip format from.
1154 * phEmf [O] Address that receive the unmarshaled enhanced metafile.
1157 * The end of the marshaled data in the buffer.
1160 * Even though the function is documented to take a pointer to an ULONG in
1161 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1162 * the first parameter is an ULONG.
1163 * This function is only intended to be called by the RPC runtime.
1165 unsigned char * __RPC_USER HENHMETAFILE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
1169 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, phEmf);
1171 fContext = *(ULONG *)pBuffer;
1172 pBuffer += sizeof(ULONG);
1174 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phEmf) < 8)) ||
1175 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phEmf) == 8)))
1177 *phEmf = *(HENHMETAFILE *)pBuffer;
1178 pBuffer += sizeof(*phEmf);
1180 else if (fContext == WDT_REMOTE_CALL)
1184 handle = *(ULONG *)pBuffer;
1185 pBuffer += sizeof(ULONG);
1190 size = *(ULONG *)pBuffer;
1191 pBuffer += sizeof(ULONG);
1192 if (size != *(ULONG *)pBuffer)
1194 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
1197 pBuffer += sizeof(ULONG);
1198 *phEmf = SetEnhMetaFileBits(size, pBuffer);
1205 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
1210 /******************************************************************************
1211 * HENHMETAFILE_UserFree [OLE32.@]
1213 * Frees an unmarshaled enhanced metafile.
1216 * pFlags [I] Flags. See notes.
1217 * phEmf [I] Enhanced metafile to free.
1220 * The end of the marshaled data in the buffer.
1223 * Even though the function is documented to take a pointer to a ULONG in
1224 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1225 * which the first parameter is a ULONG.
1226 * This function is only intended to be called by the RPC runtime.
1228 void __RPC_USER HENHMETAFILE_UserFree(ULONG *pFlags, HENHMETAFILE *phEmf)
1230 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phEmf);
1232 if (LOWORD(*pFlags) != MSHCTX_INPROC)
1233 DeleteEnhMetaFile(*phEmf);
1236 /******************************************************************************
1237 * HMETAFILEPICT_UserSize [OLE32.@]
1239 * Calculates the buffer size required to marshal an metafile pict.
1242 * pFlags [I] Flags. See notes.
1243 * StartingSize [I] Starting size of the buffer. This value is added on to
1244 * the buffer size required for the clip format.
1245 * phMfp [I] Metafile pict to size.
1248 * The buffer size required to marshal a metafile pict plus the starting size.
1251 * Even though the function is documented to take a pointer to a ULONG in
1252 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1253 * the first parameter is a ULONG.
1254 * This function is only intended to be called by the RPC runtime.
1256 ULONG __RPC_USER HMETAFILEPICT_UserSize(ULONG *pFlags, ULONG StartingSize, HMETAFILEPICT *phMfp)
1258 ULONG size = StartingSize;
1260 TRACE("(%s, %d, &%p)\n", debugstr_user_flags(pFlags), StartingSize, *phMfp);
1262 size += sizeof(ULONG);
1263 size += sizeof(HMETAFILEPICT);
1265 if ((LOWORD(*pFlags) != MSHCTX_INPROC) && *phMfp)
1267 METAFILEPICT *mfpict = GlobalLock(*phMfp);
1269 /* FIXME: raise an exception if mfpict is NULL? */
1270 size += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
1271 size += sizeof(ULONG);
1273 size = HMETAFILE_UserSize(pFlags, size, &mfpict->hMF);
1275 GlobalUnlock(*phMfp);
1281 /******************************************************************************
1282 * HMETAFILEPICT_UserMarshal [OLE32.@]
1284 * Marshals a metafile pict into a buffer.
1287 * pFlags [I] Flags. See notes.
1288 * pBuffer [I] Buffer to marshal the clip format into.
1289 * phMfp [I] Metafile pict to marshal.
1292 * The end of the marshaled data in the buffer.
1295 * Even though the function is documented to take a pointer to a ULONG in
1296 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1297 * the first parameter is a ULONG.
1298 * This function is only intended to be called by the RPC runtime.
1300 unsigned char * __RPC_USER HMETAFILEPICT_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILEPICT *phMfp)
1302 TRACE("(%s, %p, &%p)\n", debugstr_user_flags(pFlags), pBuffer, *phMfp);
1304 if (LOWORD(*pFlags) == MSHCTX_INPROC)
1305 *(ULONG *)pBuffer = WDT_INPROC_CALL;
1307 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
1308 pBuffer += sizeof(ULONG);
1310 *(HMETAFILEPICT *)pBuffer = *phMfp;
1311 pBuffer += sizeof(HMETAFILEPICT);
1313 if ((LOWORD(*pFlags) != MSHCTX_INPROC) && *phMfp)
1315 METAFILEPICT *mfpict = GlobalLock(*phMfp);
1316 remoteMETAFILEPICT * remmfpict = (remoteMETAFILEPICT *)pBuffer;
1318 /* FIXME: raise an exception if mfpict is NULL? */
1319 remmfpict->mm = mfpict->mm;
1320 remmfpict->xExt = mfpict->xExt;
1321 remmfpict->yExt = mfpict->yExt;
1322 pBuffer += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
1323 *(ULONG *)pBuffer = USER_MARSHAL_PTR_PREFIX;
1324 pBuffer += sizeof(ULONG);
1326 pBuffer = HMETAFILE_UserMarshal(pFlags, pBuffer, &mfpict->hMF);
1328 GlobalUnlock(*phMfp);
1334 /******************************************************************************
1335 * HMETAFILEPICT_UserUnmarshal [OLE32.@]
1337 * Unmarshals an metafile pict from a buffer.
1340 * pFlags [I] Flags. See notes.
1341 * pBuffer [I] Buffer to marshal the clip format from.
1342 * phMfp [O] Address that receive the unmarshaled metafile pict.
1345 * The end of the marshaled data in the buffer.
1348 * Even though the function is documented to take a pointer to an ULONG in
1349 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1350 * the first parameter is an ULONG.
1351 * This function is only intended to be called by the RPC runtime.
1353 unsigned char * __RPC_USER HMETAFILEPICT_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILEPICT *phMfp)
1357 TRACE("(%s, %p, %p)\n", debugstr_user_flags(pFlags), pBuffer, phMfp);
1359 fContext = *(ULONG *)pBuffer;
1360 pBuffer += sizeof(ULONG);
1362 if ((fContext == WDT_INPROC_CALL) || !*(HMETAFILEPICT *)pBuffer)
1364 *phMfp = *(HMETAFILEPICT *)pBuffer;
1365 pBuffer += sizeof(HMETAFILEPICT);
1369 METAFILEPICT *mfpict;
1370 const remoteMETAFILEPICT *remmfpict;
1371 ULONG user_marshal_prefix;
1373 pBuffer += sizeof(HMETAFILEPICT);
1374 remmfpict = (const remoteMETAFILEPICT *)pBuffer;
1376 *phMfp = GlobalAlloc(GMEM_MOVEABLE, sizeof(METAFILEPICT));
1378 RpcRaiseException(E_OUTOFMEMORY);
1380 mfpict = GlobalLock(*phMfp);
1381 mfpict->mm = remmfpict->mm;
1382 mfpict->xExt = remmfpict->xExt;
1383 mfpict->yExt = remmfpict->yExt;
1384 pBuffer += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
1385 user_marshal_prefix = *(ULONG *)pBuffer;
1386 pBuffer += sizeof(ULONG);
1388 if (user_marshal_prefix != USER_MARSHAL_PTR_PREFIX)
1389 RpcRaiseException(RPC_X_INVALID_TAG);
1391 pBuffer = HMETAFILE_UserUnmarshal(pFlags, pBuffer, &mfpict->hMF);
1393 GlobalUnlock(*phMfp);
1399 /******************************************************************************
1400 * HMETAFILEPICT_UserFree [OLE32.@]
1402 * Frees an unmarshaled metafile pict.
1405 * pFlags [I] Flags. See notes.
1406 * phMfp [I] Metafile pict to free.
1409 * The end of the marshaled data in the buffer.
1412 * Even though the function is documented to take a pointer to a ULONG in
1413 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1414 * which the first parameter is a ULONG.
1415 * This function is only intended to be called by the RPC runtime.
1417 void __RPC_USER HMETAFILEPICT_UserFree(ULONG *pFlags, HMETAFILEPICT *phMfp)
1419 TRACE("(%s, &%p)\n", debugstr_user_flags(pFlags), *phMfp);
1421 if ((LOWORD(*pFlags) == MSHCTX_INPROC) && *phMfp)
1423 METAFILEPICT *mfpict;
1425 mfpict = GlobalLock(*phMfp);
1426 /* FIXME: raise an exception if mfpict is NULL? */
1428 GlobalUnlock(*phMfp);
1432 /******************************************************************************
1433 * STGMEDIUM_UserSize [OLE32.@]
1435 * Calculates the buffer size required to marshal an STGMEDIUM.
1438 * pFlags [I] Flags. See notes.
1439 * StartingSize [I] Starting size of the buffer. This value is added on to
1440 * the buffer size required for the clip format.
1441 * pStgMedium [I] STGMEDIUM to size.
1444 * The buffer size required to marshal an STGMEDIUM plus the starting size.
1447 * Even though the function is documented to take a pointer to a ULONG in
1448 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1449 * the first parameter is a ULONG.
1450 * This function is only intended to be called by the RPC runtime.
1452 ULONG __RPC_USER STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, STGMEDIUM *pStgMedium)
1454 ULONG size = StartingSize;
1456 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, pStgMedium);
1458 ALIGN_LENGTH(size, 3);
1460 size += 2 * sizeof(DWORD);
1461 if (pStgMedium->tymed != TYMED_NULL)
1462 size += sizeof(DWORD);
1464 switch (pStgMedium->tymed)
1467 TRACE("TYMED_NULL\n");
1470 TRACE("TYMED_HGLOBAL\n");
1471 size = HGLOBAL_UserSize(pFlags, size, &pStgMedium->u.hGlobal);
1474 FIXME("TYMED_FILE\n");
1477 FIXME("TYMED_ISTREAM\n");
1479 case TYMED_ISTORAGE:
1480 FIXME("TYMED_ISTORAGE\n");
1483 FIXME("TYMED_GDI\n");
1486 TRACE("TYMED_MFPICT\n");
1487 size = HMETAFILEPICT_UserSize(pFlags, size, &pStgMedium->u.hMetaFilePict);
1490 TRACE("TYMED_ENHMF\n");
1491 size = HENHMETAFILE_UserSize(pFlags, size, &pStgMedium->u.hEnhMetaFile);
1494 RaiseException(DV_E_TYMED, 0, 0, NULL);
1497 if (pStgMedium->pUnkForRelease)
1498 FIXME("buffer size pUnkForRelease\n");
1503 /******************************************************************************
1504 * STGMEDIUM_UserMarshal [OLE32.@]
1506 * Marshals a STGMEDIUM into a buffer.
1509 * pFlags [I] Flags. See notes.
1510 * pBuffer [I] Buffer to marshal the clip format into.
1511 * pCF [I] STGMEDIUM to marshal.
1514 * The end of the marshaled data in the buffer.
1517 * Even though the function is documented to take a pointer to a ULONG in
1518 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1519 * the first parameter is a ULONG.
1520 * This function is only intended to be called by the RPC runtime.
1522 unsigned char * __RPC_USER STGMEDIUM_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, STGMEDIUM *pStgMedium)
1524 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, pStgMedium);
1526 ALIGN_POINTER(pBuffer, 3);
1528 *(DWORD *)pBuffer = pStgMedium->tymed;
1529 pBuffer += sizeof(DWORD);
1530 if (pStgMedium->tymed != TYMED_NULL)
1532 *(DWORD *)pBuffer = (DWORD)(DWORD_PTR)pStgMedium->u.pstg;
1533 pBuffer += sizeof(DWORD);
1535 *(DWORD *)pBuffer = (DWORD)(DWORD_PTR)pStgMedium->pUnkForRelease;
1536 pBuffer += sizeof(DWORD);
1538 switch (pStgMedium->tymed)
1541 TRACE("TYMED_NULL\n");
1544 TRACE("TYMED_HGLOBAL\n");
1545 pBuffer = HGLOBAL_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hGlobal);
1548 FIXME("TYMED_FILE\n");
1551 FIXME("TYMED_ISTREAM\n");
1553 case TYMED_ISTORAGE:
1554 FIXME("TYMED_ISTORAGE\n");
1557 FIXME("TYMED_GDI\n");
1560 TRACE("TYMED_MFPICT\n");
1561 pBuffer = HMETAFILEPICT_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hMetaFilePict);
1564 TRACE("TYMED_ENHMF\n");
1565 pBuffer = HENHMETAFILE_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hEnhMetaFile);
1568 RaiseException(DV_E_TYMED, 0, 0, NULL);
1571 if (pStgMedium->pUnkForRelease)
1572 FIXME("marshal pUnkForRelease\n");
1577 /******************************************************************************
1578 * STGMEDIUM_UserUnmarshal [OLE32.@]
1580 * Unmarshals a STGMEDIUM from a buffer.
1583 * pFlags [I] Flags. See notes.
1584 * pBuffer [I] Buffer to marshal the clip format from.
1585 * pStgMedium [O] Address that receive the unmarshaled STGMEDIUM.
1588 * The end of the marshaled data in the buffer.
1591 * Even though the function is documented to take a pointer to an ULONG in
1592 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1593 * the first parameter is an ULONG.
1594 * This function is only intended to be called by the RPC runtime.
1596 unsigned char * __RPC_USER STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, STGMEDIUM *pStgMedium)
1601 ALIGN_POINTER(pBuffer, 3);
1603 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, pStgMedium);
1605 pStgMedium->tymed = *(DWORD *)pBuffer;
1606 pBuffer += sizeof(DWORD);
1607 if (pStgMedium->tymed != TYMED_NULL)
1609 content = *(DWORD *)pBuffer;
1610 pBuffer += sizeof(DWORD);
1612 releaseunk = *(DWORD *)pBuffer;
1613 pBuffer += sizeof(DWORD);
1615 switch (pStgMedium->tymed)
1618 TRACE("TYMED_NULL\n");
1621 TRACE("TYMED_HGLOBAL\n");
1622 pBuffer = HGLOBAL_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hGlobal);
1625 FIXME("TYMED_FILE\n");
1628 FIXME("TYMED_ISTREAM\n");
1630 case TYMED_ISTORAGE:
1631 FIXME("TYMED_ISTORAGE\n");
1634 FIXME("TYMED_GDI\n");
1637 TRACE("TYMED_MFPICT\n");
1638 pBuffer = HMETAFILEPICT_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hMetaFilePict);
1641 TRACE("TYMED_ENHMF\n");
1642 pBuffer = HENHMETAFILE_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hEnhMetaFile);
1645 RaiseException(DV_E_TYMED, 0, 0, NULL);
1648 pStgMedium->pUnkForRelease = NULL;
1650 FIXME("unmarshal pUnkForRelease\n");
1655 /******************************************************************************
1656 * STGMEDIUM_UserFree [OLE32.@]
1658 * Frees an unmarshaled STGMEDIUM.
1661 * pFlags [I] Flags. See notes.
1662 * pStgmedium [I] STGMEDIUM to free.
1665 * The end of the marshaled data in the buffer.
1668 * Even though the function is documented to take a pointer to a ULONG in
1669 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1670 * which the first parameter is a ULONG.
1671 * This function is only intended to be called by the RPC runtime.
1673 void __RPC_USER STGMEDIUM_UserFree(ULONG *pFlags, STGMEDIUM *pStgMedium)
1675 TRACE("(%s, %p\n", debugstr_user_flags(pFlags), pStgMedium);
1677 ReleaseStgMedium(pStgMedium);
1680 ULONG __RPC_USER ASYNC_STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, ASYNC_STGMEDIUM *pStgMedium)
1683 return StartingSize;
1686 unsigned char * __RPC_USER ASYNC_STGMEDIUM_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, ASYNC_STGMEDIUM *pStgMedium)
1692 unsigned char * __RPC_USER ASYNC_STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, ASYNC_STGMEDIUM *pStgMedium)
1698 void __RPC_USER ASYNC_STGMEDIUM_UserFree(ULONG *pFlags, ASYNC_STGMEDIUM *pStgMedium)
1703 ULONG __RPC_USER FLAG_STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, FLAG_STGMEDIUM *pStgMedium)
1706 return StartingSize;
1709 unsigned char * __RPC_USER FLAG_STGMEDIUM_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, FLAG_STGMEDIUM *pStgMedium)
1715 unsigned char * __RPC_USER FLAG_STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, FLAG_STGMEDIUM *pStgMedium)
1721 void __RPC_USER FLAG_STGMEDIUM_UserFree(ULONG *pFlags, FLAG_STGMEDIUM *pStgMedium)
1726 ULONG __RPC_USER SNB_UserSize(ULONG *pFlags, ULONG StartingSize, SNB *pSnb)
1729 return StartingSize;
1732 unsigned char * __RPC_USER SNB_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, SNB *pSnb)
1738 unsigned char * __RPC_USER SNB_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, SNB *pSnb)
1744 void __RPC_USER SNB_UserFree(ULONG *pFlags, SNB *pSnb)