ole32: Implement HMETAFILE and HMETAFILEPICT user marshaling
functions and add tests for these.
Robert Shearman
rob at codeweavers.com
Sun Dec 17 17:46:11 CST 2006
---
dlls/ole32/ole32.spec | 16 +-
dlls/ole32/tests/usrmarshal.c | 155 ++++++++++++++++
dlls/ole32/usrmarshal.c | 407
+++++++++++++++++++++++++++++++++++++++++
3 files changed, 567 insertions(+), 11 deletions(-)
-------------- next part --------------
diff --git a/dlls/ole32/ole32.spec b/dlls/ole32/ole32.spec
index 5c26b31..675edb6 100644
--- a/dlls/ole32/ole32.spec
+++ b/dlls/ole32/ole32.spec
@@ -135,14 +135,14 @@
@ stdcall HMENU_UserMarshal(ptr ptr ptr)
@ stdcall HMENU_UserSize(ptr long ptr)
@ stdcall HMENU_UserUnmarshal(ptr ptr ptr)
-@ stub HMETAFILEPICT_UserFree
-@ stub HMETAFILEPICT_UserMarshal
-@ stub HMETAFILEPICT_UserSize
-@ stub HMETAFILEPICT_UserUnmarshal
-@ stub HMETAFILE_UserFree
-@ stub HMETAFILE_UserMarshal
-@ stub HMETAFILE_UserSize
-@ stub HMETAFILE_UserUnmarshal
+@ stdcall HMETAFILEPICT_UserFree(ptr ptr)
+@ stdcall HMETAFILEPICT_UserMarshal(ptr ptr ptr)
+@ stdcall HMETAFILEPICT_UserSize(ptr long ptr)
+@ stdcall HMETAFILEPICT_UserUnmarshal(ptr ptr ptr)
+@ stdcall HMETAFILE_UserFree(ptr ptr)
+@ stdcall HMETAFILE_UserMarshal(ptr ptr ptr)
+@ stdcall HMETAFILE_UserSize(ptr long ptr)
+@ stdcall HMETAFILE_UserUnmarshal(ptr ptr ptr)
@ stdcall HPALETTE_UserFree(ptr ptr)
@ stdcall HPALETTE_UserMarshal(ptr ptr ptr)
@ stdcall HPALETTE_UserSize(ptr long ptr)
diff --git a/dlls/ole32/tests/usrmarshal.c b/dlls/ole32/tests/usrmarshal.c
index 664ed98..3915894 100644
--- a/dlls/ole32/tests/usrmarshal.c
+++ b/dlls/ole32/tests/usrmarshal.c
@@ -29,6 +29,11 @@ #include "objidl.h"
#include "wine/test.h"
+ULONG __RPC_USER HMETAFILE_UserSize(ULONG *, unsigned long, HMETAFILE *);
+unsigned char * __RPC_USER HMETAFILE_UserMarshal(ULONG *, unsigned char *, HMETAFILE *);
+unsigned char * __RPC_USER HMETAFILE_UserUnmarshal(ULONG *, unsigned char *, HMETAFILE *);
+void __RPC_USER HMETAFILE_UserFree(ULONG *, HMETAFILE *);
+
static const char cf_marshaled[] =
{
0x9, 0x0, 0x0, 0x0,
@@ -213,6 +218,154 @@ static void test_marshal_HENHMETAFILE(vo
HENHMETAFILE_UserFree(&flags, &hemf2);
}
+static HMETAFILE create_mf(void)
+{
+ RECT rect = {0, 0, 100, 100};
+ HDC hdc = CreateMetaFile(NULL);
+ ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rect, "Test String", strlen("Test String"), NULL);
+ return CloseMetaFile(hdc);
+}
+
+static void test_marshal_HMETAFILE(void)
+{
+ unsigned char *buffer;
+ ULONG size;
+ ULONG flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
+ HMETAFILE hmf;
+ HMETAFILE hmf2 = NULL;
+ unsigned char *wirehmf;
+
+ hmf = create_mf();
+
+ size = HMETAFILE_UserSize(&flags, 0, &hmf);
+ ok(size > 20, "size should be at least 20 bytes, not %d\n", size);
+ buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
+ HMETAFILE_UserMarshal(&flags, buffer, &hmf);
+ wirehmf = buffer;
+ ok(*(DWORD *)wirehmf == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmf);
+ wirehmf += sizeof(DWORD);
+ ok(*(DWORD *)wirehmf == (DWORD)(DWORD_PTR)hmf, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmf);
+ wirehmf += sizeof(DWORD);
+ ok(*(DWORD *)wirehmf == (size - 0x10), "wirestgm + 0x8 should be size - 0x10 instead of 0x%08x\n", *(DWORD *)wirehmf);
+ wirehmf += sizeof(DWORD);
+ ok(*(DWORD *)wirehmf == (size - 0x10), "wirestgm + 0xc should be size - 0x10 instead of 0x%08x\n", *(DWORD *)wirehmf);
+ wirehmf += sizeof(DWORD);
+ ok(*(WORD *)wirehmf == 1, "wirestgm + 0x10 should be 1 instead of 0x%08x\n", *(DWORD *)wirehmf);
+ wirehmf += sizeof(DWORD);
+ /* ... rest of data not tested - refer to tests for GetMetaFileBits
+ * at this point */
+
+ HMETAFILE_UserUnmarshal(&flags, buffer, &hmf2);
+ ok(hmf2 != NULL, "HMETAFILE didn't unmarshal\n");
+ HeapFree(GetProcessHeap(), 0, buffer);
+ HMETAFILE_UserFree(&flags, &hmf2);
+ DeleteMetaFile(hmf);
+
+ /* test NULL emf */
+ hmf = NULL;
+
+ size = HMETAFILE_UserSize(&flags, 0, &hmf);
+ ok(size == 8, "size should be 8 bytes, not %d\n", size);
+ buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
+ HMETAFILE_UserMarshal(&flags, buffer, &hmf);
+ wirehmf = buffer;
+ ok(*(DWORD *)wirehmf == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmf);
+ wirehmf += sizeof(DWORD);
+ ok(*(DWORD *)wirehmf == (DWORD)(DWORD_PTR)hmf, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmf);
+ wirehmf += sizeof(DWORD);
+
+ HMETAFILE_UserUnmarshal(&flags, buffer, &hmf2);
+ ok(hmf2 == NULL, "NULL HMETAFILE didn't unmarshal\n");
+ HeapFree(GetProcessHeap(), 0, buffer);
+ HMETAFILE_UserFree(&flags, &hmf2);
+}
+
+#define USER_MARSHAL_PTR_PREFIX \
+ ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
+ ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
+
+static void test_marshal_HMETAFILEPICT(void)
+{
+ unsigned char *buffer;
+ ULONG size;
+ ULONG flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
+ HMETAFILEPICT hmfp;
+ HMETAFILEPICT hmfp2 = NULL;
+ METAFILEPICT *pmfp;
+ unsigned char *wirehmfp;
+
+ hmfp = GlobalAlloc(GMEM_MOVEABLE, sizeof(*pmfp));
+ pmfp = GlobalLock(hmfp);
+ pmfp->mm = MM_ISOTROPIC;
+ pmfp->xExt = 1;
+ pmfp->yExt = 2;
+ pmfp->hMF = create_mf();
+ GlobalUnlock(hmfp);
+
+ size = HMETAFILEPICT_UserSize(&flags, 0, &hmfp);
+ ok(size > 20, "size should be at least 20 bytes, not %d\n", size);
+ trace("size is %d\n", size);
+ buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
+ HMETAFILEPICT_UserMarshal(&flags, buffer, &hmfp);
+ wirehmfp = buffer;
+ ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == MM_ISOTROPIC, "wirestgm + 0x8 should be MM_ISOTROPIC instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == 1, "wirestgm + 0xc should be 1 instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == 2, "wirestgm + 0x10 should be 2 instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == USER_MARSHAL_PTR_PREFIX, "wirestgm + 0x14 should be \"User\" instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x18 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ pmfp = GlobalLock(hmfp);
+ ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)pmfp->hMF, "wirestgm + 0x1c should be pmfp->hMF instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ GlobalUnlock(hmfp);
+ wirehmfp += sizeof(DWORD);
+ todo_wine {
+ ok(*(DWORD *)wirehmfp == (size - 0x34), "wirestgm + 0x20 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == (size - 0x34), "wirestgm + 0x24 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ }
+ ok(*(WORD *)wirehmfp == 1, "wirehmfp + 0x28 should be 1 instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ /* ... rest of data not tested - refer to tests for GetMetaFileBits
+ * at this point */
+
+ HMETAFILEPICT_UserUnmarshal(&flags, buffer, &hmfp2);
+ ok(hmfp2 != NULL, "HMETAFILEPICT didn't unmarshal\n");
+ HeapFree(GetProcessHeap(), 0, buffer);
+ HMETAFILEPICT_UserFree(&flags, &hmfp2);
+ pmfp = GlobalLock(hmfp);
+ DeleteMetaFile(pmfp->hMF);
+ GlobalUnlock(hmfp);
+ GlobalFree(hmfp);
+
+ /* test NULL emf */
+ hmfp = NULL;
+
+ size = HMETAFILEPICT_UserSize(&flags, 0, &hmfp);
+ ok(size == 8, "size should be 8 bytes, not %d\n", size);
+ buffer = HeapAlloc(GetProcessHeap(), 0, size);
+ HMETAFILEPICT_UserMarshal(&flags, buffer, &hmfp);
+ wirehmfp = buffer;
+ ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+ ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ wirehmfp += sizeof(DWORD);
+
+ hmfp2 = NULL;
+ HMETAFILEPICT_UserUnmarshal(&flags, buffer, &hmfp2);
+ ok(hmfp2 == NULL, "NULL HMETAFILE didn't unmarshal\n");
+ HeapFree(GetProcessHeap(), 0, buffer);
+ HMETAFILEPICT_UserFree(&flags, &hmfp2);
+}
+
START_TEST(usrmarshal)
{
CoInitialize(NULL);
@@ -221,6 +374,8 @@ START_TEST(usrmarshal)
test_marshal_HWND();
test_marshal_HGLOBAL();
test_marshal_HENHMETAFILE();
+ test_marshal_HMETAFILE();
+ test_marshal_HMETAFILEPICT();
CoUninitialize();
}
\ No newline at end of file
diff --git a/dlls/ole32/usrmarshal.c b/dlls/ole32/usrmarshal.c
index b9bffd1..65e74e6 100644
--- a/dlls/ole32/usrmarshal.c
+++ b/dlls/ole32/usrmarshal.c
@@ -44,6 +44,10 @@ #define ALIGNED_POINTER(_Ptr, _Align) ((
#define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
#define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
+#define USER_MARSHAL_PTR_PREFIX \
+ ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
+ ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
+
static const char* debugstr_user_flags(ULONG *pFlags)
{
char buf[12];
@@ -840,6 +844,204 @@ void __RPC_USER HPALETTE_UserFree(ULONG
/******************************************************************************
+ * HMETAFILE_UserSize [OLE32.@]
+ *
+ * Calculates the buffer size required to marshal a metafile.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * StartingSize [I] Starting size of the buffer. This value is added on to
+ * the buffer size required for the clip format.
+ * phmf [I] Metafile to size.
+ *
+ * RETURNS
+ * The buffer size required to marshal a metafile plus the starting size.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to a ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
+ * the first parameter is a ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+ULONG __RPC_USER HMETAFILE_UserSize(ULONG *pFlags, ULONG StartingSize, HMETAFILE *phmf)
+{
+ ULONG size = StartingSize;
+
+ TRACE("(%s, %d, &%p\n", debugstr_user_flags(pFlags), StartingSize, *phmf);
+
+ ALIGN_LENGTH(size, 3);
+
+ size += sizeof(ULONG);
+ if (LOWORD(*pFlags) == MSHCTX_INPROC)
+ size += sizeof(ULONG_PTR);
+ else
+ {
+ size += sizeof(ULONG);
+
+ if (*phmf)
+ {
+ UINT mfsize;
+
+ size += 2 * sizeof(ULONG);
+ mfsize = GetMetaFileBitsEx(*phmf, 0, NULL);
+ size += mfsize;
+ }
+ }
+
+ return size;
+}
+
+/******************************************************************************
+ * HMETAFILE_UserMarshal [OLE32.@]
+ *
+ * Marshals a metafile into a buffer.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * pBuffer [I] Buffer to marshal the clip format into.
+ * phEmf [I] Metafile to marshal.
+ *
+ * RETURNS
+ * The end of the marshaled data in the buffer.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to a ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
+ * the first parameter is a ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+unsigned char * __RPC_USER HMETAFILE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILE *phmf)
+{
+ TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phmf);
+
+ ALIGN_POINTER(pBuffer, 3);
+
+ if (LOWORD(*pFlags) == MSHCTX_INPROC)
+ {
+ if (sizeof(*phmf) == 8)
+ *(ULONG *)pBuffer = WDT_INPROC64_CALL;
+ else
+ *(ULONG *)pBuffer = WDT_INPROC_CALL;
+ pBuffer += sizeof(ULONG);
+ *(HMETAFILE *)pBuffer = *phmf;
+ pBuffer += sizeof(HMETAFILE);
+ }
+ else
+ {
+ *(ULONG *)pBuffer = WDT_REMOTE_CALL;
+ pBuffer += sizeof(ULONG);
+ *(ULONG *)pBuffer = (ULONG)(ULONG_PTR)*phmf;
+ pBuffer += sizeof(ULONG);
+
+ if (*phmf)
+ {
+ UINT mfsize = GetMetaFileBitsEx(*phmf, 0, NULL);
+
+ *(ULONG *)pBuffer = mfsize;
+ pBuffer += sizeof(ULONG);
+ *(ULONG *)pBuffer = mfsize;
+ pBuffer += sizeof(ULONG);
+ GetMetaFileBitsEx(*phmf, mfsize, pBuffer);
+ pBuffer += mfsize;
+ }
+ }
+
+ return pBuffer;
+}
+
+/******************************************************************************
+ * HMETAFILE_UserUnmarshal [OLE32.@]
+ *
+ * Unmarshals a metafile from a buffer.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * pBuffer [I] Buffer to marshal the clip format from.
+ * phmf [O] Address that receive the unmarshaled metafile.
+ *
+ * RETURNS
+ * The end of the marshaled data in the buffer.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to an ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
+ * the first parameter is an ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+unsigned char * __RPC_USER HMETAFILE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILE *phmf)
+{
+ ULONG fContext;
+
+ TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, phmf);
+
+ ALIGN_POINTER(pBuffer, 3);
+
+ fContext = *(ULONG *)pBuffer;
+ pBuffer += sizeof(ULONG);
+
+ if (((fContext == WDT_INPROC_CALL) && (sizeof(*phmf) < 8)) ||
+ ((fContext == WDT_INPROC64_CALL) && (sizeof(*phmf) == 8)))
+ {
+ *phmf = *(HMETAFILE *)pBuffer;
+ pBuffer += sizeof(*phmf);
+ }
+ else if (fContext == WDT_REMOTE_CALL)
+ {
+ ULONG handle;
+
+ handle = *(ULONG *)pBuffer;
+ pBuffer += sizeof(ULONG);
+
+ if (handle)
+ {
+ ULONG size;
+ size = *(ULONG *)pBuffer;
+ pBuffer += sizeof(ULONG);
+ if (size != *(ULONG *)pBuffer)
+ {
+ RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
+ return pBuffer;
+ }
+ pBuffer += sizeof(ULONG);
+ *phmf = SetMetaFileBitsEx(size, pBuffer);
+ pBuffer += size;
+ }
+ else
+ *phmf = NULL;
+ }
+ else
+ RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
+
+ return pBuffer;
+}
+
+/******************************************************************************
+ * HMETAFILE_UserFree [OLE32.@]
+ *
+ * Frees an unmarshaled metafile.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * phmf [I] Metafile to free.
+ *
+ * RETURNS
+ * The end of the marshaled data in the buffer.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to a ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
+ * which the first parameter is a ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+void __RPC_USER HMETAFILE_UserFree(ULONG *pFlags, HMETAFILE *phmf)
+{
+ TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phmf);
+
+ if (LOWORD(*pFlags) != MSHCTX_INPROC)
+ DeleteMetaFile(*phmf);
+}
+
+/******************************************************************************
* HENHMETAFILE_UserSize [OLE32.@]
*
* Calculates the buffer size required to marshal an enhanced metafile.
@@ -1032,6 +1234,202 @@ void __RPC_USER HENHMETAFILE_UserFree(UL
}
/******************************************************************************
+ * HMETAFILEPICT_UserSize [OLE32.@]
+ *
+ * Calculates the buffer size required to marshal an metafile pict.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * StartingSize [I] Starting size of the buffer. This value is added on to
+ * the buffer size required for the clip format.
+ * phMfp [I] Metafile pict to size.
+ *
+ * RETURNS
+ * The buffer size required to marshal a metafile pict plus the starting size.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to a ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
+ * the first parameter is a ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+ULONG __RPC_USER HMETAFILEPICT_UserSize(ULONG *pFlags, ULONG StartingSize, HMETAFILEPICT *phMfp)
+{
+ ULONG size = StartingSize;
+
+ TRACE("(%s, %d, &%p)\n", debugstr_user_flags(pFlags), StartingSize, *phMfp);
+
+ size += sizeof(ULONG);
+ size += sizeof(HMETAFILEPICT);
+
+ if ((LOWORD(*pFlags) != MSHCTX_INPROC) && *phMfp)
+ {
+ METAFILEPICT *mfpict = GlobalLock(*phMfp);
+
+ /* FIXME: raise an exception if mfpict is NULL? */
+ size += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
+ size += sizeof(ULONG);
+
+ size = HMETAFILE_UserSize(pFlags, size, &mfpict->hMF);
+
+ GlobalUnlock(*phMfp);
+ }
+
+ return size;
+}
+
+/******************************************************************************
+ * HMETAFILEPICT_UserMarshal [OLE32.@]
+ *
+ * Marshals a metafile pict into a buffer.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * pBuffer [I] Buffer to marshal the clip format into.
+ * phMfp [I] Metafile pict to marshal.
+ *
+ * RETURNS
+ * The end of the marshaled data in the buffer.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to a ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
+ * the first parameter is a ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+unsigned char * __RPC_USER HMETAFILEPICT_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILEPICT *phMfp)
+{
+ TRACE("(%s, %p, &%p)\n", debugstr_user_flags(pFlags), pBuffer, *phMfp);
+
+ if (LOWORD(*pFlags) == MSHCTX_INPROC)
+ *(ULONG *)pBuffer = WDT_INPROC_CALL;
+ else
+ *(ULONG *)pBuffer = WDT_REMOTE_CALL;
+ pBuffer += sizeof(ULONG);
+
+ *(HMETAFILEPICT *)pBuffer = *phMfp;
+ pBuffer += sizeof(HMETAFILEPICT);
+
+ if ((LOWORD(*pFlags) != MSHCTX_INPROC) && *phMfp)
+ {
+ METAFILEPICT *mfpict = GlobalLock(*phMfp);
+ remoteMETAFILEPICT * remmfpict = (remoteMETAFILEPICT *)pBuffer;
+
+ /* FIXME: raise an exception if mfpict is NULL? */
+ remmfpict->mm = mfpict->mm;
+ remmfpict->xExt = mfpict->xExt;
+ remmfpict->yExt = mfpict->yExt;
+ pBuffer += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
+ *(ULONG *)pBuffer = USER_MARSHAL_PTR_PREFIX;
+ pBuffer += sizeof(ULONG);
+
+ pBuffer = HMETAFILE_UserMarshal(pFlags, pBuffer, &mfpict->hMF);
+
+ GlobalUnlock(*phMfp);
+ }
+
+ return pBuffer;
+}
+
+/******************************************************************************
+ * HMETAFILEPICT_UserUnmarshal [OLE32.@]
+ *
+ * Unmarshals an metafile pict from a buffer.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * pBuffer [I] Buffer to marshal the clip format from.
+ * phMfp [O] Address that receive the unmarshaled metafile pict.
+ *
+ * RETURNS
+ * The end of the marshaled data in the buffer.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to an ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of which
+ * the first parameter is an ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+unsigned char * __RPC_USER HMETAFILEPICT_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HMETAFILEPICT *phMfp)
+{
+ ULONG fContext;
+
+ TRACE("(%s, %p, %p)\n", debugstr_user_flags(pFlags), pBuffer, phMfp);
+
+ fContext = *(ULONG *)pBuffer;
+ pBuffer += sizeof(ULONG);
+
+ if ((fContext == WDT_INPROC_CALL) || !*(HMETAFILEPICT *)pBuffer)
+ {
+ *phMfp = *(HMETAFILEPICT *)pBuffer;
+ pBuffer += sizeof(HMETAFILEPICT);
+ }
+ else
+ {
+ METAFILEPICT *mfpict;
+ const remoteMETAFILEPICT *remmfpict;
+ ULONG user_marshal_prefix;
+
+ pBuffer += sizeof(HMETAFILEPICT);
+ remmfpict = (const remoteMETAFILEPICT *)pBuffer;
+
+ *phMfp = GlobalAlloc(GMEM_MOVEABLE, sizeof(METAFILEPICT));
+ if (!*phMfp)
+ RpcRaiseException(E_OUTOFMEMORY);
+
+ mfpict = GlobalLock(*phMfp);
+ mfpict->mm = remmfpict->mm;
+ mfpict->xExt = remmfpict->xExt;
+ mfpict->yExt = remmfpict->yExt;
+ pBuffer += FIELD_OFFSET(remoteMETAFILEPICT, hMF);
+ user_marshal_prefix = *(ULONG *)pBuffer;
+ pBuffer += sizeof(ULONG);
+
+ if (user_marshal_prefix != USER_MARSHAL_PTR_PREFIX)
+ RpcRaiseException(RPC_X_INVALID_TAG);
+
+ pBuffer = HMETAFILE_UserUnmarshal(pFlags, pBuffer, &mfpict->hMF);
+
+ GlobalUnlock(*phMfp);
+ }
+
+ return pBuffer;
+}
+
+/******************************************************************************
+ * HMETAFILEPICT_UserFree [OLE32.@]
+ *
+ * Frees an unmarshaled metafile pict.
+ *
+ * PARAMS
+ * pFlags [I] Flags. See notes.
+ * phMfp [I] Metafile pict to free.
+ *
+ * RETURNS
+ * The end of the marshaled data in the buffer.
+ *
+ * NOTES
+ * Even though the function is documented to take a pointer to a ULONG in
+ * pFlags, it actually takes a pointer to a USER_MARSHAL_CB structure, of
+ * which the first parameter is a ULONG.
+ * This function is only intended to be called by the RPC runtime.
+ */
+void __RPC_USER HMETAFILEPICT_UserFree(ULONG *pFlags, HMETAFILEPICT *phMfp)
+{
+ TRACE("(%s, &%p)\n", debugstr_user_flags(pFlags), *phMfp);
+
+ if ((LOWORD(*pFlags) == MSHCTX_INPROC) && *phMfp)
+ {
+ METAFILEPICT *mfpict;
+
+ mfpict = GlobalLock(*phMfp);
+ /* FIXME: raise an exception if mfpict is NULL? */
+
+ GlobalUnlock(*phMfp);
+ }
+}
+
+/******************************************************************************
* STGMEDIUM_UserSize [OLE32.@]
*
* Calculates the buffer size required to marshal an STGMEDIUM.
@@ -1085,7 +1483,8 @@ ULONG __RPC_USER STGMEDIUM_UserSize(ULON
FIXME("TYMED_GDI\n");
break;
case TYMED_MFPICT:
- FIXME("TYMED_MFPICT\n");
+ TRACE("TYMED_MFPICT\n");
+ size = HMETAFILEPICT_UserSize(pFlags, size, &pStgMedium->u.hMetaFilePict);
break;
case TYMED_ENHMF:
TRACE("TYMED_ENHMF\n");
@@ -1158,7 +1557,8 @@ unsigned char * __RPC_USER STGMEDIUM_Use
FIXME("TYMED_GDI\n");
break;
case TYMED_MFPICT:
- FIXME("TYMED_MFPICT\n");
+ TRACE("TYMED_MFPICT\n");
+ pBuffer = HMETAFILEPICT_UserMarshal(pFlags, pBuffer, &pStgMedium->u.hMetaFilePict);
break;
case TYMED_ENHMF:
TRACE("TYMED_ENHMF\n");
@@ -1234,7 +1634,8 @@ unsigned char * __RPC_USER STGMEDIUM_Use
FIXME("TYMED_GDI\n");
break;
case TYMED_MFPICT:
- FIXME("TYMED_MFPICT\n");
+ TRACE("TYMED_MFPICT\n");
+ pBuffer = HMETAFILEPICT_UserUnmarshal(pFlags, pBuffer, &pStgMedium->u.hMetaFilePict);
break;
case TYMED_ENHMF:
TRACE("TYMED_ENHMF\n");
More information about the wine-patches
mailing list