Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CoSwitchCallContext function

Switches the call context object used by CoGetCallContext.


HRESULT CoSwitchCallContext(
  _In_opt_ IUnknown *pNewObject,
  _Out_    IUnknown **ppOldObject


pNewObject [in, optional]

A pointer to an interface on the new call context object. COM stores this pointer without adding a reference to the pointer until CoSwitchCallContext is called with another object. This parameter may be NULL if you are calling CoSwitchCallContext to switch back to the original call context but there was no original call context.

ppOldObject [out]

The address of pointer variable that receives a pointer to the call context object of the call currently in progress. This value is returned so that the original call context can be restored by the custom marshaller. The returned pointer will be NULL if there was no call in progress.

Return value

This function can return the following values.

Return codeDescription

The function was successful.


Out of memory.



Custom marshallers call CoSwitchCallContext to change the call context object used by the CoGetCallContext function. Before dispatching an arriving call, custom marshallers call CoSwitchCallContext, specifying the new context object. After sending a reply, they must restore the original call context by calling CoSwitchCallContext again, this time passing a pointer to the original context object.

CoSwitchCallContext does not add a reference to the new context object. Custom marshallers must ensure that the lifetime of their context object continues throughout their call and until the call to restore the original context. Custom marshallers should not release the value that they placed into the ppOldObject parameter when they set their context.

Call context objects provided by custom marshallers should support the IServerSecurity interface.


Minimum supported client

Windows 2000 Professional [desktop apps | Windows Store apps]

Minimum supported server

Windows 2000 Server [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8







See also

Security in COM



© 2016 Microsoft