Tracing Activities

COM+ makes it easy for an object to retrieve its activity identity, using the context object interface IObjectContextInfo, with the method:

HRESULT GetActivityID(GUID* pguidActivityID);

If the object does not take part in an activity, the method returns GUID_NULL. Retrieving the activity ID is useful for debugging and tracing purposes.

Example 5-1 demonstrates activity ID tracing.

Example 5-1. Tracing the activity ID

HRESULT hres = S_OK;
GUID guidActivityID = GUID_NULL;
IObjectContextInfo* pObjectContextInfo = NULL;

hres = ::CoGetObjectContext(IID_IObjectContextInfo,
                            (void**)&pObjectContextInfo);

ASSERT(pObjectContextInfo != NULL);//a non-configure object maybe?

hres = pObjectContextInfo->GetActivityId(&guidActivityID);

pObjectContextInfo->Release(  );

if(guidActivityID == GUID_NULL)
{
   TRACE("The object does not take part in an activity");
}
else
{
   USES_CONVERSION;
   WCHAR pwsGUID[150];

   ::StringFromGUID2(guidActivityID,pwsGUID,150);
   TRACE("The object takes place in activity with ID %s",W2A(pwsGUID));
}

COM+ provides the activity ID via another interface, called IObjectContextActivity , obtained by calling CoGetObjectContext( ) .

IObjectContextActivity has just one method, GetActivityId( ) , used exactly like the method of the same name in the example.

Get COM & .NET Component Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.