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
//CLSID for the new object that emulates the original



Specifies the CLSID of the object to be emulated.


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


Indicates the emulation was successfully established or removed.


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


Indicates error reading from registration database.


Indicates error writing to registration database.


Indicates the clsidOld parameter specifies an OLE 1 class.


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


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