IMarshal::GetMarshalSizeMax

HRESULT IMarshal::GetMarshalSizeMax(iid, pvInterface, dwDestContext, pvDestContext, mshlflags, pcb)

Return an upper bound on the amount of data that would be written into the marshaling stream in an IMarshal::MarshalInterface() stream. The value returned must be an upper bound in the sense that it must be the case that a subsequent call to MarshalInterface() in fact require no more than the indicated number of bytes of marshaled data.

Callers can optionally use the returned upper bound to pre-allocate stream buffers used in the marshaling process. Note that when IMarshal::MarshalInterface() is ultimately called, the IMarshal implementation cannot rely on the caller actually having called GetMarshalSizeMax() beforehand; it must still be wary of STG_E_MEDIUMFULL errors returned by the stream.

The value returned by this function is guaranteed by the callee to be a conservative estimate of the amount of data needed to marshal the object; it is valid so long as the object instance is alive. Violation of this can be treated as a catastrophic error. To repeat for emphasis: an object must return a reasonable maximum size needed for marshaling: callers have the option of allocating a fixed-size marshaling buffer.

Argument

Type

Description

iid

REFIID

The interface of this object that we want to marshal.

pvInterface

void *

The actual pointer that will be marshaled. May be NULL.

dwDestContext

DWORD

As in CoMarshalInterface().

pvDestContext

void *

As in CoMarshalInterface().

mshlflags

DWORD

As in CoMarshalInterface().

pcb

ULONG *

The place at which the maximum marshal size should be returned. A return of zero indicates "unknown maximum size."

return value

HRESULT

S_OK, E_FAIL, E_NOINTERFACE, E_UNEXPECTED