Using COM+ Services Through CoCreateActivity

The CoCreateActivity function is used to submit batch work to the COM+ system. It allows script-based applications to support an application-wide COM+ service configuration.

The desired COM+ services are configured through a CServiceConfig object that is passed in to the function. The function creates an activity object and returns the IServiceActivity interface of that object. The batch work can be submitted either synchronously or asynchronously, by using the SynchronousCall or AsynchronousCall methods of IServiceActivity, respectively. A pointer to an IServiceCall interface is passed in to each of these methods, and the batch work is implemented by the developer in the OnCall method of the IServiceCall interface.

Component Services Administrative Tool

Does not apply.

Visual Basic

Does not apply.

C/C++

The following code fragment illustrates how to use COM+ services through CoCreateActivity. Error handling is omitted for brevity. This code fragment uses the CServiceConfig object that was created and configured in Configuring COM+ Services with CServiceConfig.

// A CServiceConfig object was created as follows:
// hr = CoCreateInstance(CLSID_CServiceConfig, NULL, CLSCTX_INPROC_SERVER,
//   IID_IUnknown, (void**)&pUnknownCSC);

// Create the activity for our services.
HRESULT hr = CoCreateActivity(pUnknownCSC, IID_IServiceActivity, (void**)&pActivity);
if (FAILED(hr)) throw(hr);

// Do the batch work synchronously.
// The batch work is implemented in pServiceCall->OnCall().
hr = pActivity->SynchronousCall(pServiceCall);
if (FAILED(hr)) throw(hr);

CoCreateActivity

Configuring COM+ Services with CServiceConfig

CServiceConfig

Using COM+ Services Through CoEnterServiceDomain and CoLeaveServiceDomain