Basic COM  «Prev 

Implementing COM objects

Creating COM objects using member pointers to interfaces

To create COM objects using member pointers to interfaces:
  1. Define a concrete class for each of the object's interfaces.
  2. Add member variables that are pointers to each class.
  3. Within your COM object's class code, manage these classes.
For example:

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

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

class CMyComObject{
   CIMyComInterface    *m_pim;
   CIYourComInterface *m_piy;
   …
};

The member pointers to each COM interface can be instantiated when the COM object is created or on demand when one of the interfaces is requested. The main advantage of this technique is that most developers are familiar with using member pointers to other classes.