Type manipulation and verification


Inline Query Interface (QI)

You can use the built-in smart types to QI to other supported interfaces of a coclass on which you have an interface:
[C++]
// ipTin is of type ITinPtr and is an interface to an instance of the Tin coclass
// The Tin coclass supports both the ITin and ITinSurface interfaces
// GetVolume is a method on the ITinSurface interface
((ITinSurfacePtr)ipTin)->GetVolume(...);
For the sake of simplicity, the code snippets given don't always check HRESULT's, although as a developer you should always do so.

Replicate the functionality of instanceof (Java) or TypeOf (Visual Basic)

It is common to have an interface pointer that could point to one of several coclasses. You can find out more information about the coclass by attempting to QI to other interfaces using if/else logic. For example, both the RasterDataset and FeatureDataset coclasses implement IDataset. If you are passed IDataset as a function parameter you can determine which coclass the IDataset references as follows:
[C++]
void Foo(IDataset *pDataset)
{
  IFeatureDatasetPtr ipFeatureDataset(pDataset);
  if (ipFeatureDataset != 0)
  {
    // use IFeatureDataset methods
  }
  else
  {
    IRasterDataset2Ptr ipRasterDataset(pDataset);
    if (ipRasterDataset != 0)
    {
      // use IRasterDataset2 methods
    }
  }
}