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
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(ole);
44 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
45 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
46 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
47 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
49 #define USER_MARSHAL_PTR_PREFIX \
50 ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
51 ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
53 static const char* debugstr_user_flags(ULONG *pFlags)
57 switch (LOWORD(*pFlags))
60 loword="MSHCTX_LOCAL";
62 case MSHCTX_NOSHAREDMEM:
63 loword="MSHCTX_NOSHAREDMEM";
65 case MSHCTX_DIFFERENTMACHINE:
66 loword="MSHCTX_DIFFERENTMACHINE";
69 loword="MSHCTX_INPROC";
72 sprintf(buf, "%d", LOWORD(*pFlags));
76 if (HIWORD(*pFlags) == NDR_LOCAL_DATA_REPRESENTATION)
77 return wine_dbg_sprintf("MAKELONG(NDR_LOCAL_REPRESENTATION, %s)", loword);
79 return wine_dbg_sprintf("MAKELONG(0x%04x, %s)", HIWORD(*pFlags), loword);
82 /******************************************************************************
83 * CLIPFORMAT_UserSize [OLE32.@]
85 * Calculates the buffer size required to marshal a clip format.
88 * pFlags [I] Flags. See notes.
89 * StartingSize [I] Starting size of the buffer. This value is added on to
90 * the buffer size required for the clip format.
91 * pCF [I] Clip format to size.
94 * The buffer size required to marshal a clip format plus the starting size.
97 * Even though the function is documented to take a pointer to an unsigned
98 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
99 * the first parameter is an unsigned long.
100 * This function is only intended to be called by the RPC runtime.
102 ULONG __RPC_USER CLIPFORMAT_UserSize(ULONG *pFlags, ULONG StartingSize, CLIPFORMAT *pCF)
104 ULONG size = StartingSize;
106 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, pCF);
108 size += sizeof(userCLIPFORMAT);
110 /* only need to marshal the name if it is not a pre-defined type and
111 * we are going remote */
112 if ((*pCF >= 0xc000) && (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE))
116 size += 3 * sizeof(INT);
117 /* urg! this function is badly designed because it won't tell us how
118 * much space is needed without doing a dummy run of storing the
119 * name into a buffer */
120 ret = GetClipboardFormatNameW(*pCF, format, sizeof(format)/sizeof(format[0])-1);
122 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
123 size += (ret + 1) * sizeof(WCHAR);
128 /******************************************************************************
129 * CLIPFORMAT_UserMarshal [OLE32.@]
131 * Marshals a clip format into a buffer.
134 * pFlags [I] Flags. See notes.
135 * pBuffer [I] Buffer to marshal the clip format into.
136 * pCF [I] Clip format to marshal.
139 * The end of the marshaled data in the buffer.
142 * Even though the function is documented to take a pointer to an unsigned
143 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
144 * the first parameter is an unsigned long.
145 * This function is only intended to be called by the RPC runtime.
147 unsigned char * __RPC_USER CLIPFORMAT_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF)
149 wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer;
151 TRACE("(%s, %p, &0x%04x\n", debugstr_user_flags(pFlags), pBuffer, *pCF);
153 wirecf->u.dwValue = *pCF;
154 pBuffer += sizeof(*wirecf);
156 /* only need to marshal the name if it is not a pre-defined type and
157 * we are going remote */
158 if ((*pCF >= 0xc000) && (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE))
162 wirecf->fContext = WDT_REMOTE_CALL;
163 len = GetClipboardFormatNameW(*pCF, format, sizeof(format)/sizeof(format[0])-1);
165 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
167 *(INT *)pBuffer = len;
168 pBuffer += sizeof(INT);
170 pBuffer += sizeof(INT);
171 *(INT *)pBuffer = len;
172 pBuffer += sizeof(INT);
173 TRACE("marshaling format name %s\n", debugstr_wn(format, len-1));
174 lstrcpynW((LPWSTR)pBuffer, format, len);
175 pBuffer += len * sizeof(WCHAR);
176 *(WCHAR *)pBuffer = '\0';
177 pBuffer += sizeof(WCHAR);
180 wirecf->fContext = WDT_INPROC_CALL;
185 /******************************************************************************
186 * CLIPFORMAT_UserUnmarshal [OLE32.@]
188 * Unmarshals a clip format from a buffer.
191 * pFlags [I] Flags. See notes.
192 * pBuffer [I] Buffer to marshal the clip format from.
193 * pCF [O] Address that receive the unmarshaled clip format.
196 * The end of the marshaled data in the buffer.
199 * Even though the function is documented to take a pointer to an unsigned
200 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
201 * the first parameter is an unsigned long.
202 * This function is only intended to be called by the RPC runtime.
204 unsigned char * __RPC_USER CLIPFORMAT_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF)
206 wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer;
208 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, pCF);
210 pBuffer += sizeof(*wirecf);
211 if (wirecf->fContext == WDT_INPROC_CALL)
212 *pCF = (CLIPFORMAT)wirecf->u.dwValue;
213 else if (wirecf->fContext == WDT_REMOTE_CALL)
216 INT len = *(INT *)pBuffer;
217 pBuffer += sizeof(INT);
218 if (*(INT *)pBuffer != 0)
219 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
220 pBuffer += sizeof(INT);
221 if (*(INT *)pBuffer != len)
222 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
223 pBuffer += sizeof(INT);
224 if (((WCHAR *)pBuffer)[len] != '\0')
225 RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL);
226 TRACE("unmarshaling clip format %s\n", debugstr_w((LPCWSTR)pBuffer));
227 cf = RegisterClipboardFormatW((LPCWSTR)pBuffer);
228 pBuffer += (len + 1) * sizeof(WCHAR);
230 RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL);
234 /* code not really appropriate, but nearest I can find */
235 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
239 /******************************************************************************
240 * CLIPFORMAT_UserFree [OLE32.@]
242 * Frees an unmarshaled clip format.
245 * pFlags [I] Flags. See notes.
246 * pCF [I] Clip format to free.
249 * The end of the marshaled data in the buffer.
252 * Even though the function is documented to take a pointer to an unsigned
253 * long in pFlags, it actually takes a pointer to a USER_MARSHAL_CB
254 * structure, of which the first parameter is an unsigned long.
255 * This function is only intended to be called by the RPC runtime.
257 void __RPC_USER CLIPFORMAT_UserFree(ULONG *pFlags, CLIPFORMAT *pCF)
259 /* there is no inverse of the RegisterClipboardFormat function,
260 * so nothing to do */
263 static ULONG __RPC_USER handle_UserSize(ULONG *pFlags, ULONG StartingSize, HANDLE *handle)
265 if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)
267 ERR("can't remote a local handle\n");
268 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
271 return StartingSize + sizeof(RemotableHandle);
274 static unsigned char * __RPC_USER handle_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
276 RemotableHandle *remhandle = (RemotableHandle *)pBuffer;
277 if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)
279 ERR("can't remote a local handle\n");
280 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
283 remhandle->fContext = WDT_INPROC_CALL;
284 remhandle->u.hInproc = (LONG_PTR)*handle;
285 return pBuffer + sizeof(RemotableHandle);
288 static unsigned char * __RPC_USER handle_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
290 RemotableHandle *remhandle = (RemotableHandle *)pBuffer;
291 if (remhandle->fContext != WDT_INPROC_CALL)
292 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
293 *handle = (HANDLE)remhandle->u.hInproc;
294 return pBuffer + sizeof(RemotableHandle);
297 static void __RPC_USER handle_UserFree(ULONG *pFlags, HANDLE *phMenu)
302 #define IMPL_WIREM_HANDLE(type) \
303 ULONG __RPC_USER type##_UserSize(ULONG *pFlags, ULONG StartingSize, type *handle) \
305 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, handle); \
306 return handle_UserSize(pFlags, StartingSize, (HANDLE *)handle); \
309 unsigned char * __RPC_USER type##_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, type *handle) \
311 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *handle); \
312 return handle_UserMarshal(pFlags, pBuffer, (HANDLE *)handle); \
315 unsigned char * __RPC_USER type##_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, type *handle) \
317 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, handle); \
318 return handle_UserUnmarshal(pFlags, pBuffer, (HANDLE *)handle); \
321 void __RPC_USER type##_UserFree(ULONG *pFlags, type *handle) \
323 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *handle); \
324 handle_UserFree(pFlags, (HANDLE *)handle); \
327 IMPL_WIREM_HANDLE(HACCEL)
328 IMPL_WIREM_HANDLE(HMENU)
329 IMPL_WIREM_HANDLE(HWND)
331 /******************************************************************************
332 * HGLOBAL_UserSize [OLE32.@]
334 * Calculates the buffer size required to marshal an HGLOBAL.
337 * pFlags [I] Flags. See notes.
338 * StartingSize [I] Starting size of the buffer. This value is added on to
339 * the buffer size required for the clip format.
340 * phGlobal [I] HGLOBAL to size.
343 * The buffer size required to marshal an HGLOBAL plus the starting size.
346 * Even though the function is documented to take a pointer to a ULONG in
347 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
348 * the first parameter is a ULONG.
349 * This function is only intended to be called by the RPC runtime.
351 ULONG __RPC_USER HGLOBAL_UserSize(ULONG *pFlags, ULONG StartingSize, HGLOBAL *phGlobal)
353 ULONG size = StartingSize;
355 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, phGlobal);
357 ALIGN_LENGTH(size, 3);
359 size += sizeof(ULONG);
361 if (LOWORD(*pFlags == MSHCTX_INPROC))
362 size += sizeof(HGLOBAL);
365 size += sizeof(ULONG);
369 size += 3 * sizeof(ULONG);
370 ret = GlobalSize(*phGlobal);
378 /******************************************************************************
379 * HGLOBAL_UserMarshal [OLE32.@]
381 * Marshals an HGLOBAL into a buffer.
384 * pFlags [I] Flags. See notes.
385 * pBuffer [I] Buffer to marshal the clip format into.
386 * phGlobal [I] HGLOBAL to marshal.
389 * The end of the marshaled data in the buffer.
392 * Even though the function is documented to take a pointer to a ULONG in
393 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
394 * the first parameter is a ULONG.
395 * This function is only intended to be called by the RPC runtime.
397 unsigned char * __RPC_USER HGLOBAL_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HGLOBAL *phGlobal)
399 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phGlobal);
401 ALIGN_POINTER(pBuffer, 3);
403 if (LOWORD(*pFlags == MSHCTX_INPROC))
405 if (sizeof(*phGlobal) == 8)
406 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
408 *(ULONG *)pBuffer = WDT_INPROC_CALL;
409 pBuffer += sizeof(ULONG);
410 *(HGLOBAL *)pBuffer = *phGlobal;
411 pBuffer += sizeof(HGLOBAL);
415 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
416 pBuffer += sizeof(ULONG);
417 *(ULONG *)pBuffer = (ULONG)*phGlobal;
418 pBuffer += sizeof(ULONG);
421 const unsigned char *memory;
422 SIZE_T size = GlobalSize(*phGlobal);
423 *(ULONG *)pBuffer = (ULONG)size;
424 pBuffer += sizeof(ULONG);
425 *(ULONG *)pBuffer = (ULONG)*phGlobal;
426 pBuffer += sizeof(ULONG);
427 *(ULONG *)pBuffer = (ULONG)size;
428 pBuffer += sizeof(ULONG);
430 memory = GlobalLock(*phGlobal);
431 memcpy(pBuffer, memory, size);
433 GlobalUnlock(*phGlobal);
440 /******************************************************************************
441 * HGLOBAL_UserUnmarshal [OLE32.@]
443 * Unmarshals an HGLOBAL from a buffer.
446 * pFlags [I] Flags. See notes.
447 * pBuffer [I] Buffer to marshal the clip format from.
448 * phGlobal [O] Address that receive the unmarshaled HGLOBAL.
451 * The end of the marshaled data in the buffer.
454 * Even though the function is documented to take a pointer to an ULONG in
455 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
456 * the first parameter is an ULONG.
457 * This function is only intended to be called by the RPC runtime.
459 unsigned char * __RPC_USER HGLOBAL_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HGLOBAL *phGlobal)
463 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phGlobal);
465 ALIGN_POINTER(pBuffer, 3);
467 fContext = *(ULONG *)pBuffer;
468 pBuffer += sizeof(ULONG);
470 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phGlobal) < 8)) ||
471 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phGlobal) == 8)))
473 *phGlobal = *(HGLOBAL *)pBuffer;
474 pBuffer += sizeof(*phGlobal);
476 else if (fContext == WDT_REMOTE_CALL)
480 handle = *(ULONG *)pBuffer;
481 pBuffer += sizeof(ULONG);
488 size = *(ULONG *)pBuffer;
489 pBuffer += sizeof(ULONG);
490 /* redundancy is bad - it means you have to check consistency like
492 if (*(ULONG *)pBuffer != handle)
494 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
497 pBuffer += sizeof(ULONG);
498 /* redundancy is bad - it means you have to check consistency like
500 if (*(ULONG *)pBuffer != size)
502 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
505 pBuffer += sizeof(ULONG);
507 /* FIXME: check size is not too big */
509 *phGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
510 memory = GlobalLock(*phGlobal);
511 memcpy(memory, pBuffer, size);
513 GlobalUnlock(*phGlobal);
519 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
524 /******************************************************************************
525 * HGLOBAL_UserFree [OLE32.@]
527 * Frees an unmarshaled HGLOBAL.
530 * pFlags [I] Flags. See notes.
531 * phGlobal [I] HGLOBAL to free.
534 * The end of the marshaled data in the buffer.
537 * Even though the function is documented to take a pointer to a ULONG in
538 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
539 * which the first parameter is a ULONG.
540 * This function is only intended to be called by the RPC runtime.
542 void __RPC_USER HGLOBAL_UserFree(ULONG *pFlags, HGLOBAL *phGlobal)
544 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phGlobal);
546 if (LOWORD(*pFlags != MSHCTX_INPROC) && *phGlobal)
547 GlobalFree(*phGlobal);
550 /******************************************************************************
551 * HBITMAP_UserSize [OLE32.@]
553 * Calculates the buffer size required to marshal a bitmap.
556 * pFlags [I] Flags. See notes.
557 * StartingSize [I] Starting size of the buffer. This value is added on to
558 * the buffer size required for the clip format.
559 * phBmp [I] Bitmap to size.
562 * The buffer size required to marshal an bitmap plus the starting size.
565 * Even though the function is documented to take a pointer to a ULONG in
566 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
567 * the first parameter is a ULONG.
568 * This function is only intended to be called by the RPC runtime.
570 ULONG __RPC_USER HBITMAP_UserSize(ULONG *pFlags, ULONG StartingSize, HBITMAP *phBmp)
576 /******************************************************************************
577 * HBITMAP_UserMarshal [OLE32.@]
579 * Marshals a bitmap into a buffer.
582 * pFlags [I] Flags. See notes.
583 * pBuffer [I] Buffer to marshal the clip format into.
584 * phBmp [I] Bitmap to marshal.
587 * The end of the marshaled data in the buffer.
590 * Even though the function is documented to take a pointer to a ULONG in
591 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
592 * the first parameter is a ULONG.
593 * This function is only intended to be called by the RPC runtime.
595 unsigned char * __RPC_USER HBITMAP_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HBITMAP *phBmp)
601 /******************************************************************************
602 * HBITMAP_UserUnmarshal [OLE32.@]
604 * Unmarshals a bitmap from a buffer.
607 * pFlags [I] Flags. See notes.
608 * pBuffer [I] Buffer to marshal the clip format from.
609 * phBmp [O] Address that receive the unmarshaled bitmap.
612 * The end of the marshaled data in the buffer.
615 * Even though the function is documented to take a pointer to an ULONG in
616 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
617 * the first parameter is an ULONG.
618 * This function is only intended to be called by the RPC runtime.
620 unsigned char * __RPC_USER HBITMAP_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HBITMAP *phBmp)
626 /******************************************************************************
627 * HBITMAP_UserFree [OLE32.@]
629 * Frees an unmarshaled bitmap.
632 * pFlags [I] Flags. See notes.
633 * phBmp [I] Bitmap to free.
636 * The end of the marshaled data in the buffer.
639 * Even though the function is documented to take a pointer to a ULONG in
640 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
641 * which the first parameter is a ULONG.
642 * This function is only intended to be called by the RPC runtime.
644 void __RPC_USER HBITMAP_UserFree(ULONG *pFlags, HBITMAP *phBmp)
649 /******************************************************************************
650 * HDC_UserSize [OLE32.@]
652 * Calculates the buffer size required to marshal an HDC.
655 * pFlags [I] Flags. See notes.
656 * StartingSize [I] Starting size of the buffer. This value is added on to
657 * the buffer size required for the clip format.
658 * phGlobal [I] HDC to size.
661 * The buffer size required to marshal an HDC plus the starting size.
664 * Even though the function is documented to take a pointer to a ULONG in
665 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
666 * the first parameter is a ULONG.
667 * This function is only intended to be called by the RPC runtime.
669 ULONG __RPC_USER HDC_UserSize(ULONG *pFlags, ULONG StartingSize, HDC *phdc)
675 /******************************************************************************
676 * HDC_UserMarshal [OLE32.@]
678 * Marshals an HDC into a buffer.
681 * pFlags [I] Flags. See notes.
682 * pBuffer [I] Buffer to marshal the clip format into.
683 * phdc [I] HDC to marshal.
686 * The end of the marshaled data in the buffer.
689 * Even though the function is documented to take a pointer to a ULONG in
690 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
691 * the first parameter is a ULONG.
692 * This function is only intended to be called by the RPC runtime.
694 unsigned char * __RPC_USER HDC_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HDC *phdc)
700 /******************************************************************************
701 * HDC_UserUnmarshal [OLE32.@]
703 * Unmarshals an HDC from a buffer.
706 * pFlags [I] Flags. See notes.
707 * pBuffer [I] Buffer to marshal the clip format from.
708 * phdc [O] Address that receive the unmarshaled HDC.
711 * The end of the marshaled data in the buffer.
714 * Even though the function is documented to take a pointer to an ULONG in
715 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
716 * the first parameter is an ULONG.
717 * This function is only intended to be called by the RPC runtime.
719 unsigned char * __RPC_USER HDC_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HDC *phdc)
725 /******************************************************************************
726 * HDC_UserFree [OLE32.@]
728 * Frees an unmarshaled HDC.
731 * pFlags [I] Flags. See notes.
732 * phdc [I] HDC to free.
735 * The end of the marshaled data in the buffer.
738 * Even though the function is documented to take a pointer to a ULONG in
739 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
740 * which the first parameter is a ULONG.
741 * This function is only intended to be called by the RPC runtime.
743 void __RPC_USER HDC_UserFree(ULONG *pFlags, HDC *phdc)
748 /******************************************************************************
749 * HPALETTE_UserSize [OLE32.@]
751 * Calculates the buffer size required to marshal a palette.
754 * pFlags [I] Flags. See notes.
755 * StartingSize [I] Starting size of the buffer. This value is added on to
756 * the buffer size required for the clip format.
757 * phPal [I] Palette to size.
760 * The buffer size required to marshal a palette plus the starting size.
763 * Even though the function is documented to take a pointer to a ULONG in
764 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
765 * the first parameter is a ULONG.
766 * This function is only intended to be called by the RPC runtime.
768 ULONG __RPC_USER HPALETTE_UserSize(ULONG *pFlags, ULONG StartingSize, HPALETTE *phPal)
774 /******************************************************************************
775 * HPALETTE_UserMarshal [OLE32.@]
777 * Marshals a palette into a buffer.
780 * pFlags [I] Flags. See notes.
781 * pBuffer [I] Buffer to marshal the clip format into.
782 * phPal [I] Palette to marshal.
785 * The end of the marshaled data in the buffer.
788 * Even though the function is documented to take a pointer to a ULONG in
789 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
790 * the first parameter is a ULONG.
791 * This function is only intended to be called by the RPC runtime.
793 unsigned char * __RPC_USER HPALETTE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HPALETTE *phPal)
799 /******************************************************************************
800 * HPALETTE_UserUnmarshal [OLE32.@]
802 * Unmarshals a palette from a buffer.
805 * pFlags [I] Flags. See notes.
806 * pBuffer [I] Buffer to marshal the clip format from.
807 * phPal [O] Address that receive the unmarshaled palette.
810 * The end of the marshaled data in the buffer.
813 * Even though the function is documented to take a pointer to an ULONG in
814 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
815 * the first parameter is an ULONG.
816 * This function is only intended to be called by the RPC runtime.
818 unsigned char * __RPC_USER HPALETTE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HPALETTE *phPal)
824 /******************************************************************************
825 * HPALETTE_UserFree [OLE32.@]
827 * Frees an unmarshaled palette.
830 * pFlags [I] Flags. See notes.
831 * phPal [I] Palette to free.
834 * The end of the marshaled data in the buffer.
837 * Even though the function is documented to take a pointer to a ULONG in
838 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
839 * which the first parameter is a ULONG.
840 * This function is only intended to be called by the RPC runtime.
842 void __RPC_USER HPALETTE_UserFree(ULONG *pFlags, HPALETTE *phPal)
848 /******************************************************************************
849 * HMETAFILE_UserSize [OLE32.@]
851 * Calculates the buffer size required to marshal a metafile.
854 * pFlags [I] Flags. See notes.
855 * StartingSize [I] Starting size of the buffer. This value is added on to
856 * the buffer size required for the clip format.
857 * phmf [I] Metafile to size.
860 * The buffer size required to marshal a metafile plus the starting size.
863 * Even though the function is documented to take a pointer to a ULONG in
864 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
865 * the first parameter is a ULONG.
866 * This function is only intended to be called by the RPC runtime.
868 ULONG __RPC_USER HMETAFILE_UserSize(ULONG *pFlags, ULONG StartingSize, HMETAFILE *phmf)
870 ULONG size = StartingSize;
872 TRACE("(%s, %d, &%p\n", debugstr_user_flags(pFlags), StartingSize, *phmf);
874 ALIGN_LENGTH(size, 3);
876 size += sizeof(ULONG);
877 if (LOWORD(*pFlags) == MSHCTX_INPROC)
878 size += sizeof(ULONG_PTR);
881 size += sizeof(ULONG);
887 size += 2 * sizeof(ULONG);
888 mfsize = GetMetaFileBitsEx(*phmf, 0, NULL);
896 /******************************************************************************
897 * HMETAFILE_UserMarshal [OLE32.@]
899 * Marshals a metafile into a buffer.
902 * pFlags [I] Flags. See notes.
903 * pBuffer [I] Buffer to marshal the clip format into.
904 * phEmf [I] Metafile to marshal.
907 * The end of the marshaled data in the buffer.
910 * Even though the function is documented to take a pointer to a ULONG in
911 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
912 * the first parameter is a ULONG.
913 * This function is only intended to be called by the RPC runtime.
915 unsigned char * __RPC_USER HMETAFILE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILE *phmf)
917 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phmf);
919 ALIGN_POINTER(pBuffer, 3);
921 if (LOWORD(*pFlags) == MSHCTX_INPROC)
923 if (sizeof(*phmf) == 8)
924 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
926 *(ULONG *)pBuffer = WDT_INPROC_CALL;
927 pBuffer += sizeof(ULONG);
928 *(HMETAFILE *)pBuffer = *phmf;
929 pBuffer += sizeof(HMETAFILE);
933 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
934 pBuffer += sizeof(ULONG);
935 *(ULONG *)pBuffer = (ULONG)(ULONG_PTR)*phmf;
936 pBuffer += sizeof(ULONG);
940 UINT mfsize = GetMetaFileBitsEx(*phmf, 0, NULL);
942 *(ULONG *)pBuffer = mfsize;
943 pBuffer += sizeof(ULONG);
944 *(ULONG *)pBuffer = mfsize;
945 pBuffer += sizeof(ULONG);
946 GetMetaFileBitsEx(*phmf, mfsize, pBuffer);
954 /******************************************************************************
955 * HMETAFILE_UserUnmarshal [OLE32.@]
957 * Unmarshals a metafile from a buffer.
960 * pFlags [I] Flags. See notes.
961 * pBuffer [I] Buffer to marshal the clip format from.
962 * phmf [O] Address that receive the unmarshaled metafile.
965 * The end of the marshaled data in the buffer.
968 * Even though the function is documented to take a pointer to an ULONG in
969 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
970 * the first parameter is an ULONG.
971 * This function is only intended to be called by the RPC runtime.
973 unsigned char * __RPC_USER HMETAFILE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILE *phmf)
977 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, phmf);
979 ALIGN_POINTER(pBuffer, 3);
981 fContext = *(ULONG *)pBuffer;
982 pBuffer += sizeof(ULONG);
984 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phmf) < 8)) ||
985 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phmf) == 8)))
987 *phmf = *(HMETAFILE *)pBuffer;
988 pBuffer += sizeof(*phmf);
990 else if (fContext == WDT_REMOTE_CALL)
994 handle = *(ULONG *)pBuffer;
995 pBuffer += sizeof(ULONG);
1000 size = *(ULONG *)pBuffer;
1001 pBuffer += sizeof(ULONG);
1002 if (size != *(ULONG *)pBuffer)
1004 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
1007 pBuffer += sizeof(ULONG);
1008 *phmf = SetMetaFileBitsEx(size, pBuffer);
1015 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
1020 /******************************************************************************
1021 * HMETAFILE_UserFree [OLE32.@]
1023 * Frees an unmarshaled metafile.
1026 * pFlags [I] Flags. See notes.
1027 * phmf [I] Metafile to free.
1030 * The end of the marshaled data in the buffer.
1033 * Even though the function is documented to take a pointer to a ULONG in
1034 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1035 * which the first parameter is a ULONG.
1036 * This function is only intended to be called by the RPC runtime.
1038 void __RPC_USER HMETAFILE_UserFree(ULONG *pFlags, HMETAFILE *phmf)
1040 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phmf);
1042 if (LOWORD(*pFlags) != MSHCTX_INPROC)
1043 DeleteMetaFile(*phmf);
1046 /******************************************************************************
1047 * HENHMETAFILE_UserSize [OLE32.@]
1049 * Calculates the buffer size required to marshal an enhanced metafile.
1052 * pFlags [I] Flags. See notes.
1053 * StartingSize [I] Starting size of the buffer. This value is added on to
1054 * the buffer size required for the clip format.
1055 * phEmf [I] Enhanced metafile to size.
1058 * The buffer size required to marshal an enhanced metafile plus the starting size.
1061 * Even though the function is documented to take a pointer to a ULONG in
1062 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1063 * the first parameter is a ULONG.
1064 * This function is only intended to be called by the RPC runtime.
1066 ULONG __RPC_USER HENHMETAFILE_UserSize(ULONG *pFlags, ULONG StartingSize, HENHMETAFILE *phEmf)
1068 ULONG size = StartingSize;
1070 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, *phEmf);
1072 size += sizeof(ULONG);
1073 if (LOWORD(*pFlags) == MSHCTX_INPROC)
1074 size += sizeof(ULONG_PTR);
1077 size += sizeof(ULONG);
1083 size += 2 * sizeof(ULONG);
1084 emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
1092 /******************************************************************************
1093 * HENHMETAFILE_UserMarshal [OLE32.@]
1095 * Marshals an enhance metafile into a buffer.
1098 * pFlags [I] Flags. See notes.
1099 * pBuffer [I] Buffer to marshal the clip format into.
1100 * phEmf [I] Enhanced metafile to marshal.
1103 * The end of the marshaled data in the buffer.
1106 * Even though the function is documented to take a pointer to a ULONG in
1107 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1108 * the first parameter is a ULONG.
1109 * This function is only intended to be called by the RPC runtime.
1111 unsigned char * __RPC_USER HENHMETAFILE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
1113 TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phEmf);
1115 if (LOWORD(*pFlags) == MSHCTX_INPROC)
1117 if (sizeof(*phEmf) == 8)
1118 *(ULONG *)pBuffer = WDT_INPROC64_CALL;
1120 *(ULONG *)pBuffer = WDT_INPROC_CALL;
1121 pBuffer += sizeof(ULONG);
1122 *(HENHMETAFILE *)pBuffer = *phEmf;
1123 pBuffer += sizeof(HENHMETAFILE);
1127 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
1128 pBuffer += sizeof(ULONG);
1129 *(ULONG *)pBuffer = (ULONG)(ULONG_PTR)*phEmf;
1130 pBuffer += sizeof(ULONG);
1134 UINT emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
1136 *(ULONG *)pBuffer = emfsize;
1137 pBuffer += sizeof(ULONG);
1138 *(ULONG *)pBuffer = emfsize;
1139 pBuffer += sizeof(ULONG);
1140 GetEnhMetaFileBits(*phEmf, emfsize, pBuffer);
1148 /******************************************************************************
1149 * HENHMETAFILE_UserUnmarshal [OLE32.@]
1151 * Unmarshals an enhanced metafile from a buffer.
1154 * pFlags [I] Flags. See notes.
1155 * pBuffer [I] Buffer to marshal the clip format from.
1156 * phEmf [O] Address that receive the unmarshaled enhanced metafile.
1159 * The end of the marshaled data in the buffer.
1162 * Even though the function is documented to take a pointer to an ULONG in
1163 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1164 * the first parameter is an ULONG.
1165 * This function is only intended to be called by the RPC runtime.
1167 unsigned char * __RPC_USER HENHMETAFILE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
1171 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, phEmf);
1173 fContext = *(ULONG *)pBuffer;
1174 pBuffer += sizeof(ULONG);
1176 if (((fContext == WDT_INPROC_CALL) && (sizeof(*phEmf) < 8)) ||
1177 ((fContext == WDT_INPROC64_CALL) && (sizeof(*phEmf) == 8)))
1179 *phEmf = *(HENHMETAFILE *)pBuffer;
1180 pBuffer += sizeof(*phEmf);
1182 else if (fContext == WDT_REMOTE_CALL)
1186 handle = *(ULONG *)pBuffer;
1187 pBuffer += sizeof(ULONG);
1192 size = *(ULONG *)pBuffer;
1193 pBuffer += sizeof(ULONG);
1194 if (size != *(ULONG *)pBuffer)
1196 RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
1199 pBuffer += sizeof(ULONG);
1200 *phEmf = SetEnhMetaFileBits(size, pBuffer);
1207 RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
1212 /******************************************************************************
1213 * HENHMETAFILE_UserFree [OLE32.@]
1215 * Frees an unmarshaled enhanced metafile.
1218 * pFlags [I] Flags. See notes.
1219 * phEmf [I] Enhanced metafile to free.
1222 * The end of the marshaled data in the buffer.
1225 * Even though the function is documented to take a pointer to a ULONG in
1226 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1227 * which the first parameter is a ULONG.
1228 * This function is only intended to be called by the RPC runtime.
1230 void __RPC_USER HENHMETAFILE_UserFree(ULONG *pFlags, HENHMETAFILE *phEmf)
1232 TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phEmf);
1234 if (LOWORD(*pFlags) != MSHCTX_INPROC)
1235 DeleteEnhMetaFile(*phEmf);
1238 /******************************************************************************
1239 * HMETAFILEPICT_UserSize [OLE32.@]
1241 * Calculates the buffer size required to marshal an metafile pict.
1244 * pFlags [I] Flags. See notes.
1245 * StartingSize [I] Starting size of the buffer. This value is added on to
1246 * the buffer size required for the clip format.
1247 * phMfp [I] Metafile pict to size.
1250 * The buffer size required to marshal a metafile pict plus the starting size.
1253 * Even though the function is documented to take a pointer to a ULONG in
1254 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1255 * the first parameter is a ULONG.
1256 * This function is only intended to be called by the RPC runtime.
1258 ULONG __RPC_USER HMETAFILEPICT_UserSize(ULONG *pFlags, ULONG StartingSize, HMETAFILEPICT *phMfp)
1260 ULONG size = StartingSize;
1262 TRACE("(%s, %d, &%p)\n", debugstr_user_flags(pFlags), StartingSize, *phMfp);
1264 size += sizeof(ULONG);
1265 size += sizeof(HMETAFILEPICT);
1267 if ((LOWORD(*pFlags) != MSHCTX_INPROC) && *phMfp)
1269 METAFILEPICT *mfpict = GlobalLock(*phMfp);
1271 /* FIXME: raise an exception if mfpict is NULL? */
1272 size += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
1273 size += sizeof(ULONG);
1275 size = HMETAFILE_UserSize(pFlags, size, &mfpict->hMF);
1277 GlobalUnlock(*phMfp);
1283 /******************************************************************************
1284 * HMETAFILEPICT_UserMarshal [OLE32.@]
1286 * Marshals a metafile pict into a buffer.
1289 * pFlags [I] Flags. See notes.
1290 * pBuffer [I] Buffer to marshal the clip format into.
1291 * phMfp [I] Metafile pict to marshal.
1294 * The end of the marshaled data in the buffer.
1297 * Even though the function is documented to take a pointer to a ULONG in
1298 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1299 * the first parameter is a ULONG.
1300 * This function is only intended to be called by the RPC runtime.
1302 unsigned char * __RPC_USER HMETAFILEPICT_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILEPICT *phMfp)
1304 TRACE("(%s, %p, &%p)\n", debugstr_user_flags(pFlags), pBuffer, *phMfp);
1306 if (LOWORD(*pFlags) == MSHCTX_INPROC)
1307 *(ULONG *)pBuffer = WDT_INPROC_CALL;
1309 *(ULONG *)pBuffer = WDT_REMOTE_CALL;
1310 pBuffer += sizeof(ULONG);
1312 *(HMETAFILEPICT *)pBuffer = *phMfp;
1313 pBuffer += sizeof(HMETAFILEPICT);
1315 if ((LOWORD(*pFlags) != MSHCTX_INPROC) && *phMfp)
1317 METAFILEPICT *mfpict = GlobalLock(*phMfp);
1318 remoteMETAFILEPICT * remmfpict = (remoteMETAFILEPICT *)pBuffer;
1320 /* FIXME: raise an exception if mfpict is NULL? */
1321 remmfpict->mm = mfpict->mm;
1322 remmfpict->xExt = mfpict->xExt;
1323 remmfpict->yExt = mfpict->yExt;
1324 pBuffer += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
1325 *(ULONG *)pBuffer = USER_MARSHAL_PTR_PREFIX;
1326 pBuffer += sizeof(ULONG);
1328 pBuffer = HMETAFILE_UserMarshal(pFlags, pBuffer, &mfpict->hMF);
1330 GlobalUnlock(*phMfp);
1336 /******************************************************************************
1337 * HMETAFILEPICT_UserUnmarshal [OLE32.@]
1339 * Unmarshals an metafile pict from a buffer.
1342 * pFlags [I] Flags. See notes.
1343 * pBuffer [I] Buffer to marshal the clip format from.
1344 * phMfp [O] Address that receive the unmarshaled metafile pict.
1347 * The end of the marshaled data in the buffer.
1350 * Even though the function is documented to take a pointer to an ULONG in
1351 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1352 * the first parameter is an ULONG.
1353 * This function is only intended to be called by the RPC runtime.
1355 unsigned char * __RPC_USER HMETAFILEPICT_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILEPICT *phMfp)
1359 TRACE("(%s, %p, %p)\n", debugstr_user_flags(pFlags), pBuffer, phMfp);
1361 fContext = *(ULONG *)pBuffer;
1362 pBuffer += sizeof(ULONG);
1364 if ((fContext == WDT_INPROC_CALL) || !*(HMETAFILEPICT *)pBuffer)
1366 *phMfp = *(HMETAFILEPICT *)pBuffer;
1367 pBuffer += sizeof(HMETAFILEPICT);
1371 METAFILEPICT *mfpict;
1372 const remoteMETAFILEPICT *remmfpict;
1373 ULONG user_marshal_prefix;
1375 pBuffer += sizeof(HMETAFILEPICT);
1376 remmfpict = (const remoteMETAFILEPICT *)pBuffer;
1378 *phMfp = GlobalAlloc(GMEM_MOVEABLE, sizeof(METAFILEPICT));
1380 RpcRaiseException(E_OUTOFMEMORY);
1382 mfpict = GlobalLock(*phMfp);
1383 mfpict->mm = remmfpict->mm;
1384 mfpict->xExt = remmfpict->xExt;
1385 mfpict->yExt = remmfpict->yExt;
1386 pBuffer += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
1387 user_marshal_prefix = *(ULONG *)pBuffer;
1388 pBuffer += sizeof(ULONG);
1390 if (user_marshal_prefix != USER_MARSHAL_PTR_PREFIX)
1391 RpcRaiseException(RPC_X_INVALID_TAG);
1393 pBuffer = HMETAFILE_UserUnmarshal(pFlags, pBuffer, &mfpict->hMF);
1395 GlobalUnlock(*phMfp);
1401 /******************************************************************************
1402 * HMETAFILEPICT_UserFree [OLE32.@]
1404 * Frees an unmarshaled metafile pict.
1407 * pFlags [I] Flags. See notes.
1408 * phMfp [I] Metafile pict to free.
1411 * The end of the marshaled data in the buffer.
1414 * Even though the function is documented to take a pointer to a ULONG in
1415 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1416 * which the first parameter is a ULONG.
1417 * This function is only intended to be called by the RPC runtime.
1419 void __RPC_USER HMETAFILEPICT_UserFree(ULONG *pFlags, HMETAFILEPICT *phMfp)
1421 TRACE("(%s, &%p)\n", debugstr_user_flags(pFlags), *phMfp);
1423 if ((LOWORD(*pFlags) != MSHCTX_INPROC) && *phMfp)
1425 METAFILEPICT *mfpict;
1427 mfpict = GlobalLock(*phMfp);
1428 /* FIXME: raise an exception if mfpict is NULL? */
1429 HMETAFILE_UserFree(pFlags, &mfpict->hMF);
1430 GlobalUnlock(*phMfp);
1436 /******************************************************************************
1437 * WdtpInterfacePointer_UserSize [OLE32.@]
1439 * Calculates the buffer size required to marshal an interface pointer.
1442 * pFlags [I] Flags. See notes.
1443 * RealFlags [I] The MSHCTX to use when marshaling the interface.
1444 * punk [I] Interface pointer to size.
1445 * StartingSize [I] Starting size of the buffer. This value is added on to
1446 * the buffer size required for the clip format.
1447 * riid [I] ID of interface to size.
1450 * The buffer size required to marshal an interface pointer plus the starting size.
1453 * Even though the function is documented to take a pointer to a ULONG in
1454 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1455 * the first parameter is a ULONG.
1457 ULONG __RPC_USER WdtpInterfacePointer_UserSize(ULONG *pFlags, ULONG RealFlags, IUnknown *punk, ULONG StartingSize, REFIID riid)
1459 FIXME("(%s, 0%x, %p, %d, %s): stub\n", debugstr_user_flags(pFlags), RealFlags, punk, StartingSize, debugstr_guid(riid));
1463 /******************************************************************************
1464 * WdtpInterfacePointer_UserMarshal [OLE32.@]
1466 * Marshals an interface pointer into a buffer.
1469 * pFlags [I] Flags. See notes.
1470 * RealFlags [I] The MSHCTX to use when marshaling the interface.
1471 * pBuffer [I] Buffer to marshal the clip format into.
1472 * punk [I] Interface pointer to marshal.
1473 * riid [I] ID of interface to marshal.
1476 * The end of the marshaled data in the buffer.
1479 * Even though the function is documented to take a pointer to a ULONG in
1480 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1481 * the first parameter is a ULONG.
1483 unsigned char * WINAPI WdtpInterfacePointer_UserMarshal(ULONG *pFlags, ULONG RealFlags, unsigned char *pBuffer, IUnknown *punk, REFIID riid)
1485 FIXME("(%s, 0x%x, %p, &%p, %s): stub\n", debugstr_user_flags(pFlags), RealFlags, pBuffer, punk, debugstr_guid(riid));
1489 /******************************************************************************
1490 * WdtpInterfacePointer_UserUnmarshal [OLE32.@]
1492 * Unmarshals an interface pointer from a buffer.
1495 * pFlags [I] Flags. See notes.
1496 * pBuffer [I] Buffer to marshal the clip format from.
1497 * ppunk [I/O] Address that receives the unmarshaled interface pointer.
1498 * riid [I] ID of interface to unmarshal.
1501 * The end of the marshaled data in the buffer.
1504 * Even though the function is documented to take a pointer to an ULONG in
1505 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1506 * the first parameter is an ULONG.
1508 unsigned char * WINAPI WdtpInterfacePointer_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, IUnknown **ppunk, REFIID riid)
1510 FIXME("(%s, %p, %p, %s): stub\n", debugstr_user_flags(pFlags), pBuffer, ppunk, debugstr_guid(riid));
1514 /******************************************************************************
1515 * WdtpInterfacePointer_UserFree [OLE32.@]
1517 * Frees an unmarshaled interface pointer.
1520 * punk [I] Interface pointer to free.
1525 void WINAPI WdtpInterfacePointer_UserFree(IUnknown *punk)
1527 FIXME("(%p): stub\n", punk);
1530 /******************************************************************************
1531 * STGMEDIUM_UserSize [OLE32.@]
1533 * Calculates the buffer size required to marshal an STGMEDIUM.
1536 * pFlags [I] Flags. See notes.
1537 * StartingSize [I] Starting size of the buffer. This value is added on to
1538 * the buffer size required for the clip format.
1539 * pStgMedium [I] STGMEDIUM to size.
1542 * The buffer size required to marshal an STGMEDIUM plus the starting size.
1545 * Even though the function is documented to take a pointer to a ULONG in
1546 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1547 * the first parameter is a ULONG.
1548 * This function is only intended to be called by the RPC runtime.
1550 ULONG __RPC_USER STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, STGMEDIUM *pStgMedium)
1552 ULONG size = StartingSize;
1554 TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, pStgMedium);
1556 ALIGN_LENGTH(size, 3);
1558 size += 2 * sizeof(DWORD);
1559 if (pStgMedium->tymed != TYMED_NULL)
1560 size += sizeof(DWORD);
1562 switch (pStgMedium->tymed)
1565 TRACE("TYMED_NULL\n");
1568 TRACE("TYMED_HGLOBAL\n");
1569 if (pStgMedium->u.hGlobal)
1570 size = HGLOBAL_UserSize(pFlags, size, &pStgMedium->u.hGlobal);
1573 TRACE("TYMED_FILE\n");
1574 if (pStgMedium->u.lpszFileName)
1576 TRACE("file name is %s\n", debugstr_w(pStgMedium->u.lpszFileName));
1577 size += 3 * sizeof(DWORD) +
1578 (strlenW(pStgMedium->u.lpszFileName) + 1) * sizeof(WCHAR);
1582 TRACE("TYMED_ISTREAM\n");
1583 if (pStgMedium->u.pstm)
1585 FIXME("not implemented for IStream %p\n", pStgMedium->u.pstm);
1588 case TYMED_ISTORAGE:
1589 TRACE("TYMED_ISTORAGE\n");
1590 if (pStgMedium->u.pstg)
1592 FIXME("not implemented for IStorage %p\n", pStgMedium->u.pstg);
1596 TRACE("TYMED_GDI\n");
1597 if (pStgMedium->u.hBitmap)
1599 FIXME("not implemented for GDI object %p\n", pStgMedium->u.hBitmap);
1603 TRACE("TYMED_MFPICT\n");
1604 if (pStgMedium->u.hMetaFilePict)
1605 size = HMETAFILEPICT_UserSize(pFlags, size, &pStgMedium->u.hMetaFilePict);
1608 TRACE("TYMED_ENHMF\n");
1609 if (pStgMedium->u.hEnhMetaFile)
1610 size = HENHMETAFILE_UserSize(pFlags, size, &pStgMedium->u.hEnhMetaFile);
1613 RaiseException(DV_E_TYMED, 0, 0, NULL);
1616 if (pStgMedium->pUnkForRelease)
1617 FIXME("buffer size pUnkForRelease\n");
1622 /******************************************************************************
1623 * STGMEDIUM_UserMarshal [OLE32.@]
1625 * Marshals a STGMEDIUM into a buffer.
1628 * pFlags [I] Flags. See notes.
1629 * pBuffer [I] Buffer to marshal the clip format into.
1630 * pCF [I] STGMEDIUM to marshal.
1633 * The end of the marshaled data in the buffer.
1636 * Even though the function is documented to take a pointer to a ULONG in
1637 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1638 * the first parameter is a ULONG.
1639 * This function is only intended to be called by the RPC runtime.
1641 unsigned char * __RPC_USER STGMEDIUM_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, STGMEDIUM *pStgMedium)
1643 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, pStgMedium);
1645 ALIGN_POINTER(pBuffer, 3);
1647 *(DWORD *)pBuffer = pStgMedium->tymed;
1648 pBuffer += sizeof(DWORD);
1649 if (pStgMedium->tymed != TYMED_NULL)
1651 *(DWORD *)pBuffer = (DWORD)(DWORD_PTR)pStgMedium->u.pstg;
1652 pBuffer += sizeof(DWORD);
1654 *(DWORD *)pBuffer = (DWORD)(DWORD_PTR)pStgMedium->pUnkForRelease;
1655 pBuffer += sizeof(DWORD);
1657 switch (pStgMedium->tymed)
1660 TRACE("TYMED_NULL\n");
1663 TRACE("TYMED_HGLOBAL\n");
1664 if (pStgMedium->u.hGlobal)
1665 pBuffer = HGLOBAL_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hGlobal);
1668 TRACE("TYMED_FILE\n");
1669 if (pStgMedium->u.lpszFileName)
1672 len = strlenW(pStgMedium->u.lpszFileName);
1674 *(DWORD *)pBuffer = len + 1;
1675 pBuffer += sizeof(DWORD);
1677 *(DWORD *)pBuffer = 0;
1678 pBuffer += sizeof(DWORD);
1680 *(DWORD *)pBuffer = len + 1;
1681 pBuffer += sizeof(DWORD);
1683 TRACE("file name is %s\n", debugstr_w(pStgMedium->u.lpszFileName));
1684 memcpy(pBuffer, pStgMedium->u.lpszFileName, (len + 1) * sizeof(WCHAR));
1688 TRACE("TYMED_ISTREAM\n");
1689 if (pStgMedium->u.pstm)
1691 FIXME("not implemented for IStream %p\n", pStgMedium->u.pstm);
1694 case TYMED_ISTORAGE:
1695 TRACE("TYMED_ISTORAGE\n");
1696 if (pStgMedium->u.pstg)
1698 FIXME("not implemented for IStorage %p\n", pStgMedium->u.pstg);
1702 TRACE("TYMED_GDI\n");
1703 if (pStgMedium->u.hBitmap)
1705 FIXME("not implemented for GDI object %p\n", pStgMedium->u.hBitmap);
1709 TRACE("TYMED_MFPICT\n");
1710 if (pStgMedium->u.hMetaFilePict)
1711 pBuffer = HMETAFILEPICT_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hMetaFilePict);
1714 TRACE("TYMED_ENHMF\n");
1715 if (pStgMedium->u.hEnhMetaFile)
1716 pBuffer = HENHMETAFILE_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hEnhMetaFile);
1719 RaiseException(DV_E_TYMED, 0, 0, NULL);
1722 if (pStgMedium->pUnkForRelease)
1723 FIXME("marshal pUnkForRelease\n");
1728 /******************************************************************************
1729 * STGMEDIUM_UserUnmarshal [OLE32.@]
1731 * Unmarshals a STGMEDIUM from a buffer.
1734 * pFlags [I] Flags. See notes.
1735 * pBuffer [I] Buffer to marshal the clip format from.
1736 * pStgMedium [O] Address that receive the unmarshaled STGMEDIUM.
1739 * The end of the marshaled data in the buffer.
1742 * Even though the function is documented to take a pointer to an ULONG in
1743 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
1744 * the first parameter is an ULONG.
1745 * This function is only intended to be called by the RPC runtime.
1747 unsigned char * __RPC_USER STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, STGMEDIUM *pStgMedium)
1752 ALIGN_POINTER(pBuffer, 3);
1754 TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, pStgMedium);
1756 pStgMedium->tymed = *(DWORD *)pBuffer;
1757 pBuffer += sizeof(DWORD);
1758 if (pStgMedium->tymed != TYMED_NULL)
1760 content = *(DWORD *)pBuffer;
1761 pBuffer += sizeof(DWORD);
1763 releaseunk = *(DWORD *)pBuffer;
1764 pBuffer += sizeof(DWORD);
1766 switch (pStgMedium->tymed)
1769 TRACE("TYMED_NULL\n");
1772 TRACE("TYMED_HGLOBAL\n");
1774 pBuffer = HGLOBAL_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hGlobal);
1777 TRACE("TYMED_FILE\n");
1782 conformance = *(DWORD *)pBuffer;
1783 pBuffer += sizeof(DWORD);
1784 if (*(DWORD *)pBuffer != 0)
1786 ERR("invalid offset %d\n", *(DWORD *)pBuffer);
1787 RpcRaiseException(RPC_S_INVALID_BOUND);
1790 pBuffer += sizeof(DWORD);
1791 variance = *(DWORD *)pBuffer;
1792 pBuffer += sizeof(DWORD);
1793 if (conformance != variance)
1795 ERR("conformance (%d) and variance (%d) should be equal\n",
1796 conformance, variance);
1797 RpcRaiseException(RPC_S_INVALID_BOUND);
1800 if (conformance > 0x7fffffff)
1802 ERR("conformance 0x%x too large\n", conformance);
1803 RpcRaiseException(RPC_S_INVALID_BOUND);
1806 pStgMedium->u.lpszFileName = CoTaskMemAlloc(conformance * sizeof(WCHAR));
1807 if (!pStgMedium->u.lpszFileName) RpcRaiseException(ERROR_OUTOFMEMORY);
1808 TRACE("unmarshalled file name is %s\n", debugstr_wn((const WCHAR *)pBuffer, variance));
1809 memcpy(pStgMedium->u.lpszFileName, pBuffer, variance * sizeof(WCHAR));
1810 pBuffer += variance * sizeof(WCHAR);
1813 pStgMedium->u.lpszFileName = NULL;
1816 TRACE("TYMED_ISTREAM\n");
1819 FIXME("not implemented for IStream\n");
1822 pStgMedium->u.pstm = NULL;
1824 case TYMED_ISTORAGE:
1825 TRACE("TYMED_ISTORAGE\n");
1828 FIXME("not implemented for IStorage\n");
1831 pStgMedium->u.pstg = NULL;
1834 TRACE("TYMED_GDI\n");
1837 FIXME("not implemented for GDI object\n");
1840 pStgMedium->u.hBitmap = NULL;
1843 TRACE("TYMED_MFPICT\n");
1845 pBuffer = HMETAFILEPICT_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hMetaFilePict);
1847 pStgMedium->u.hMetaFilePict = NULL;
1850 TRACE("TYMED_ENHMF\n");
1852 pBuffer = HENHMETAFILE_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hEnhMetaFile);
1854 pStgMedium->u.hEnhMetaFile = NULL;
1857 RaiseException(DV_E_TYMED, 0, 0, NULL);
1860 pStgMedium->pUnkForRelease = NULL;
1862 FIXME("unmarshal pUnkForRelease\n");
1867 /******************************************************************************
1868 * STGMEDIUM_UserFree [OLE32.@]
1870 * Frees an unmarshaled STGMEDIUM.
1873 * pFlags [I] Flags. See notes.
1874 * pStgmedium [I] STGMEDIUM to free.
1877 * The end of the marshaled data in the buffer.
1880 * Even though the function is documented to take a pointer to a ULONG in
1881 * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
1882 * which the first parameter is a ULONG.
1883 * This function is only intended to be called by the RPC runtime.
1885 void __RPC_USER STGMEDIUM_UserFree(ULONG *pFlags, STGMEDIUM *pStgMedium)
1887 TRACE("(%s, %p\n", debugstr_user_flags(pFlags), pStgMedium);
1889 ReleaseStgMedium(pStgMedium);
1892 ULONG __RPC_USER ASYNC_STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, ASYNC_STGMEDIUM *pStgMedium)
1895 return StartingSize;
1898 unsigned char * __RPC_USER ASYNC_STGMEDIUM_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, ASYNC_STGMEDIUM *pStgMedium)
1904 unsigned char * __RPC_USER ASYNC_STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, ASYNC_STGMEDIUM *pStgMedium)
1910 void __RPC_USER ASYNC_STGMEDIUM_UserFree(ULONG *pFlags, ASYNC_STGMEDIUM *pStgMedium)
1915 ULONG __RPC_USER FLAG_STGMEDIUM_UserSize(ULONG *pFlags, ULONG StartingSize, FLAG_STGMEDIUM *pStgMedium)
1918 return StartingSize;
1921 unsigned char * __RPC_USER FLAG_STGMEDIUM_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, FLAG_STGMEDIUM *pStgMedium)
1927 unsigned char * __RPC_USER FLAG_STGMEDIUM_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, FLAG_STGMEDIUM *pStgMedium)
1933 void __RPC_USER FLAG_STGMEDIUM_UserFree(ULONG *pFlags, FLAG_STGMEDIUM *pStgMedium)
1938 ULONG __RPC_USER SNB_UserSize(ULONG *pFlags, ULONG StartingSize, SNB *pSnb)
1941 return StartingSize;
1944 unsigned char * __RPC_USER SNB_UserMarshal( ULONG *pFlags, unsigned char *pBuffer, SNB *pSnb)
1950 unsigned char * __RPC_USER SNB_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, SNB *pSnb)
1956 void __RPC_USER SNB_UserFree(ULONG *pFlags, SNB *pSnb)