The Context Object

COM+ represents each context by an object called the context object. Every context has exactly one context object. Objects can obtain a pointer to their context object by calling CoGetObjectContext( ) (see Figure 2-5). All objects in the same context get the same context object.

CoGetObjectContext( ) is defined as:

By calling CoGetObjectContext( ), objects can get a pointer to their context’s context object

Figure 2-5.  By calling CoGetObjectContext( ), objects can get a pointer to their context’s context object

HRESULT CoGetObjectContext(REFIID riid, void** ppInterface);

The context object supports a few interfaces, so the first parameter of CoGetObjectContext( ) is always an IID that specifies which interface to retrieve. Two of the context object’s interfaces, IObjectContext and IObjectContextActivity, are legacy interfaces from MTS and are provided primarily for backward compatibility with MTS components running under COM+. The other two interfaces, IContextState and IObjectContextInfo , are specific to COM+. Throughout this book, all chapters use these two interfaces, rather than the legacy MTS interfaces.

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.