Basic COM  «Prev 

Implementing COM objects

Creating COM objects with nested Classes

To create COM objects with nested classes:
  1. Define each COM interface, within the COM object, as a nested class.
  2. Declare a member variable for each class.
For example:


class CMyComObject{
  class CIMyComInterface : public IMyComInterface 
  {
    provide implementations of all pure
    virtual methods in IMyComInterface
     
  }
  CIMyComInterface m_im;

  class CIYourComInterface : public IYourComInterface { 
    provide implementations of all pure
    virtual methods in IYourComInterface     
  }
  CIYourComInterface m_iy;
};

The advantage of this method is that the implementation of the COM class reflects the COM containment relationship, for example the COM interfaces are contained in the COM object.