GetObjectContext Function

Obtains a reference to the IObjectContext interface on the ObjectContext that's associated with the current MTS object.

The header file for the GetObjectContext function is mtx.h.

HRESULT GetObjectContext (
    IObjectContext** ppInstanceContext
);

Parameters

ppInstanceContext
[out] A reference to the IObjectContext interface on the object's context. If the object's component hasn't been imported into an MTS package, or if GetObjectContext is called from a constructor or an IUnknown method, this will be set to a NULL pointer.

Return Values

S_OK
A reference to the IObjectContext interface on the current object's context is returned in the ppInstanceContext parameter.

E_INVALIDARG
The argument passed in the ppInstanceContext parameter is invalid.

E_UNEXPECTED
An unexpected error occurred.

CONTEXT_E_NOCONTEXT
The current object doesn't have a context associated with it, because either the component wasn't imported into a package or the object wasn't created with one of the MTS CreateInstance methods. This error will also be returned if the GetObjectContext method was called from the constructor or from an IUnknown method.

Remarks

An object's context is not accessible from an object's constructor or from any IUnknown method (QueryInterface, AddRef, or Release).

An object should never attempt to pass its ObjectContext reference to another object. If you pass an ObjectContext reference to another object, it will no longer be a valid reference.

When an object obtains a reference to its ObjectContext, it must release the ObjectContext object when it's finished with it.

Example

See Also

Building Scalable Components, Context Objects, IObjectContext::CreateInstance Method