📄 usrmarshal.c
字号:
*(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.
*
* 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.
* phEmf [I] Enhanced metafile to size.
*
* RETURNS
* The buffer size required to marshal an enhanced 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 HENHMETAFILE_UserSize(ULONG *pFlags, ULONG StartingSize, HENHMETAFILE *phEmf)
{
ULONG size = StartingSize;
TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, *phEmf);
size += sizeof(ULONG);
if (LOWORD(*pFlags) == MSHCTX_INPROC)
size += sizeof(ULONG_PTR);
else
{
size += sizeof(ULONG);
if (*phEmf)
{
UINT emfsize;
size += 2 * sizeof(ULONG);
emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
size += emfsize;
}
}
return size;
}
/******************************************************************************
* HENHMETAFILE_UserMarshal [OLE32.@]
*
* Marshals an enhance metafile into a buffer.
*
* PARAMS
* pFlags [I] Flags. See notes.
* pBuffer [I] Buffer to marshal the clip format into.
* phEmf [I] Enhanced 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 HENHMETAFILE_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
{
TRACE("(%s, %p, &%p\n", debugstr_user_flags(pFlags), pBuffer, *phEmf);
if (LOWORD(*pFlags) == MSHCTX_INPROC)
{
if (sizeof(*phEmf) == 8)
*(ULONG *)pBuffer = WDT_INPROC64_CALL;
else
*(ULONG *)pBuffer = WDT_INPROC_CALL;
pBuffer += sizeof(ULONG);
*(HENHMETAFILE *)pBuffer = *phEmf;
pBuffer += sizeof(HENHMETAFILE);
}
else
{
*(ULONG *)pBuffer = WDT_REMOTE_CALL;
pBuffer += sizeof(ULONG);
*(ULONG *)pBuffer = (ULONG)(ULONG_PTR)*phEmf;
pBuffer += sizeof(ULONG);
if (*phEmf)
{
UINT emfsize = GetEnhMetaFileBits(*phEmf, 0, NULL);
*(ULONG *)pBuffer = emfsize;
pBuffer += sizeof(ULONG);
*(ULONG *)pBuffer = emfsize;
pBuffer += sizeof(ULONG);
GetEnhMetaFileBits(*phEmf, emfsize, pBuffer);
pBuffer += emfsize;
}
}
return pBuffer;
}
/******************************************************************************
* HENHMETAFILE_UserUnmarshal [OLE32.@]
*
* Unmarshals an enhanced metafile from a buffer.
*
* PARAMS
* pFlags [I] Flags. See notes.
* pBuffer [I] Buffer to marshal the clip format from.
* phEmf [O] Address that receive the unmarshaled enhanced 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 HENHMETAFILE_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
{
ULONG fContext;
TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, phEmf);
fContext = *(ULONG *)pBuffer;
pBuffer += sizeof(ULONG);
if (((fContext == WDT_INPROC_CALL) && (sizeof(*phEmf) < 8)) ||
((fContext == WDT_INPROC64_CALL) && (sizeof(*phEmf) == 8)))
{
*phEmf = *(HENHMETAFILE *)pBuffer;
pBuffer += sizeof(*phEmf);
}
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);
*phEmf = SetEnhMetaFileBits(size, pBuffer);
pBuffer += size;
}
else
*phEmf = NULL;
}
else
RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
return pBuffer;
}
/******************************************************************************
* HENHMETAFILE_UserFree [OLE32.@]
*
* Frees an unmarshaled enhanced metafile.
*
* PARAMS
* pFlags [I] Flags. See notes.
* phEmf [I] Enhanced 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 HENHMETAFILE_UserFree(ULONG *pFlags, HENHMETAFILE *phEmf)
{
TRACE("(%s, &%p\n", debugstr_user_flags(pFlags), *phEmf);
if (LOWORD(*pFlags) != MSHCTX_INPROC)
DeleteEnhMetaFile(*phEmf);
}
/******************************************************************************
* 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -