Values from the CLSCTX enumeration are used in activation calls to indicate the execution contexts in which an object is to be run. These values are also used in calls to CoRegisterClassObject to indicate the set of execution contexts in which a class object is to be made available for requests to construct instances.
typedef enum tagCLSCTX
{
CLSCTX_INPROC_SERVER = 1,
CLSCTX_INPROC_HANDLER = 2,
CLSCTX_LOCAL_SERVER = 4
CLSCTX_REMOTE_SERVER = 16
} CLSCTX;
#define CLSCTX_SERVER (CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)
#define CLSCTX_ALL (CLSCTX_INPROC_HANDLER | CLSCTX_SERVER)
Values from the CLSCTX enumeration are used in activation calls (CoCreateInstance, CoCreateInstanceEx, CoGetClassObject, etc.) to indicate the preferred execution contexts – in-process, local, or remote – in which an object is to be run. They are also used in calls to CoRegisterClassObject to indicate the set of execution contexts in which a class object is to be made available for requests to construct instances (IClassFactory::CreateInstance).
To indicate that more than one context is acceptable, you can string multiple values together with Boolean ORs. The contexts are tried in the order in which they are listed.
The following table shows how other OLE functions and methods that call CoGetClassObject use the CLSCTX values:
Function Called | Context Flag Used |
---|---|
OleLoad | CLSCTX_INPROC_HANDLER | CLSCTX_INPROC_SERVER Putting an OLE object into the loaded state requires in-process access; but, it doesn't matter if all of the object's function is presently available. |
IRunnableObject::Run | CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER Running an OLE object requires connecting to the full code of the object wherever it is located. |
CoUnMarshalInterface | CLSCTX_INPROC_HANDLER Unmarshaling needs the form of the class designed for remote access. |
IMoniker::BindToObject, for a file moniker created through a call to CreateFileMoniker | In this case, uses CLSCTX_SERVER interally to create the instance after calling GetClassFile to determine the class to be instantiated. |
The CLSCTX_REMOTE_SERVER value is added to the CLSCTX enumeration for distributed COM. The CLSCTX_SERVER and CLSCTX_ALL constants are further updated to include the CLSCTX_REMOTE_SERVER value.
Given a set of CLSCTX flags, dwClsCtx, the execution context to be used depends on the availability of registered class codes and other parameters according to the following algorithm:
The first part of the processing determines whether CLSCTX_REMOTE SERVER should be specified as follows:
then CLSCTX_REMOTE_SERVER is implied and is added to dwClsCtx. The second case allows applications written prior to the release of distributed COM to be the configuration of classes for remote activation to be used by client applications available prior to DCOM and the CLSCTX_REMOTE_SERVER flag. The cases in which there would be no explicit COSERVERINFO structure are 1) The value is specified as NULL, or 2) It is not one of the function parameters, as would be the case in calls to CoCreateInstance or CoGetClassObject in existing applications.
The rest of the processing proceeds by looking at the value(s) of dwClsCtx in the following sequence.
Windows NT: Use version 3.1 and later.
Windows: Use Windows 95 and later.
Windows CE: Unsupported.
Header: Declared in wtypes.h.
CoCreateInstance, CoGetClassObject, CoRegisterClassObject, CoGetInstanceFromFile, CoGetInstanceFromIStorage, CoCreateInstanceEx, COSERVERINFO structure, Creating an Object through a Class Object, Registering a Running EXE Server