IMarshal::GetMarshalSizeMax
Returns an
upper bound on the number of bytes needed to marshal the specified interface
pointer on the specified object.
HRESULT GetMarshalSizeMax(
REFIID riid, |
//Reference to the identifier of the interface to be
marshaled |
void *pv, |
//Interface pointer to be marshaled |
DWORD dwDestContext, |
//Destination process |
void * pvDestContext, |
//Reserved for future use |
DWORD mshlflags, |
//Reason for marshaling |
ULONG * pSize |
//Pointer to upper-bound value |
); |
|
Parameters
riid
[in]
Reference to the identifier of the interface to be marshaled.
pv
[in]
Interface pointer to be marshaled; can be NULL.
dwDestContext
[in]
Destination context where the specified interface is to be unmarshaled. Values
for dwDestContext come from the enumeration MSHCTX
pvDestContext
[in] Reserved
for future use; must be NULL.
mshlflags
[in] Flag
indicating whether the data to be marshaled is to be transmitted back to the
client process the normal
case or written to a global table,
where it can be retrieved by multiple clients. Valid values come from the MSHLFLAGS
pSize
[out] Pointer
to the upper bound on the amount of data to be written to the marshaling
stream.
Return Values
The method
supports the standard return value E_FAIL, as well as the following:
S_OK
The maximum
size was returned successfully.
E_NOINTERFACE
The specified
interface was not supported.
Remarks
This method
is called indirectly, in a call to CoGetMarshalSizeMax
To create a
proxy for an object, COM requires two pieces of information from the original
object: the amount of data to be written to the marshaling stream and the
proxy s CLSID.
The marshaling
stub obtains these two pieces of information with successive calls to CoGetMarshalSizeMax
and CoMarshalInterface
Note to Callers
The
marshaling stub, through a call to CoGetMarshalSizeMax, calls the object s
implementation of this method to preallocate the stream buffer that will be
passed to IMarshal::MarshalInterface
You do not
explicitly call this method if you are:
Implementing existing COM
interfaces, or
Defining your own custom
interfaces, using the Microsoft Interface Definition Language (MIDL).
In both
cases, the MIDL-generated stub automatically makes the call.
If you are not
using MIDL to define your own interface (see Writing a Custom Interface
The value
returned by this method is only guaranteed to be valid as long as the internal
state of the object being marshaled does not change. Therefore, the actual
marshaling should be done immediately after this function returns, or the stub
runs the risk that the object, because of some change in state, might require
more memory to marshal than it originally indicated.
Notes to Implementers
Your
implementation of MarshalInterface will use this buffer to write
marshaling data into the stream. If the buffer is too small, the marshaling
operation will fail. Therefore, the value returned by this method must
be a conservative estimate of the amount of data that will, in fact, be needed
to marshal the interface. Violation of this requirement should be treated as a
catastrophic error.
In a
subsequent call to IMarshal::MarshalInterface, your 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 and be prepared to handle them gracefully.
To ensure
that your implementation of GetMarshalSizeMax will continue to work
properly as new destination contexts are supported in the future, delegate
marshaling to COM s default implementation for all dwDestContext values
that your implementation does not understand. To delegate marshaling to COM s
default implementation, call the CoGetStandardMarshal
See Also