ObjectControl::Activate method (comsvcs.h)

Enables a COM+ object to perform context-specific initialization whenever it is activated.

This method is called by the COM+ run-time environment before any other methods are called on the object.

Syntax

HRESULT Activate();

Return value

This method can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, E_UNEXPECTED, E_FAIL, and S_OK.

Remarks

Whenever a client calls a COM+ object that isn't already active, the COM+ run-time environment automatically activates the object. This is called Just-in-Time Activation. For components that support ObjectControl as an interface, COM+ invokes the object's Activate method before passing the client's method call on to the object.

Any context-specific initialization procedures should be implemented in the Activate method for objects that expose ObjectControl.

For example, you can use the Activate method to obtain a reference to an object's context and store it in a member variable. Then the object context is available to any method that requires it, and you do not have to acquire a new one every time you want to use it. After you have a reference to the object's context, you can use the ObjectContext methods to check whether security is enabled, whether the object is executing in a transaction, or whether the caller is in a particular role.

If you are enabling object recycling (by implementing the CanBePooled method to query the object), the Activate method must be able to handle newly created objects as well as recycled objects. When the Activate method returns, there should be no distinguishable difference between a new object and a recycled one.

COM+ expressly forbids calling into an object that exposes ObjectControl before calling the Activate method (when it is in its constructor). Such a call would result in an RPC_E_DISCONNECTED error. For example, if an object passes out a reference to itself while in its constructor and then the reference calls back into that object prior to the call to Activate, the disconnected error is returned.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header comsvcs.h

See also

ObjectControl