CoTreatAsClass

Establishes or removes an emulation so objects of one class are treated as objects of a different class.

STDAPI CoTreatAsClass(

REFCLSID clsidOld,
//CLSID for the original object to be emulated
REFCLSID clsidNew
//CLSID for the new object that emulates the original
);

Parameters

clsidOld

Specifies the CLSID of the object to be emulated.

clsidNew

Specifies the CLSID of the object that should emulate the original object. This replaces any existing emulation for clsidOld. Can be CLSID_NULL, in which case any existing emulation for clsidOld is removed.

Return Values

S_OK

Indicates the emulation was successfully established or removed.

REGDB_E_CLASSNOTREG

Indicates the clsidOld parameter is not properly registered in the registration database.

REGDB_E_READREGDB

Indicates error reading from registration database.

REGDB_E_WRITEREGDB

Indicates error writing to registration database.

E_INVALIDARG

Indicates the clsidOld parameter specifies an OLE 1 class.

Comments

This function sets the TreatAs entry in the registration database for the specified object. After this entry is set, the CoGetClassObject function and object handlers (including the default handler) are transparently forwarded to the new CLSID when they consult the registration database for the old CLSID. For example, launching the object application for clsidOld would actually launch the object application for clsidNew instead. The IOleObject::EnumVerbs method in the default handler enumerates the verbs from clsidNew instead of clsidOld.

During installation, setup programs should call CoTreatAsClass, setting the clsidNew parameter to CLSID_NULL to remove any existing emulation for the classes they install.

If you set a class to emulate itself, that is, the values for clsidNew and clsidOld are the same, this function has two possible results depending on the AutoTreatAs key in the registration database. If there is a CLSID assigned to the AutoTreatAs key, then the AutoTreatAs CLSID is assigned to the TreatAs key. If there is no value assigned to the AutoTreatAs key, then the TreatAs entry is removed.

The CoTreatAsClass function does not validate whether an appropriate registration database entry for clsidNew currently exists.

See Also

CoGetTreatAsClass

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database