Platform SDK: MAPI

Implementing Objects in C++

C++ clients and service providers define MAPI objects by creating classes that inherit from the interfaces they are implementing. Each of the interface methods is public as are the constructor and destructor for the class. If the class has additional methods, they can be public or private, depending on the implementation. All data members are private.

The following example code shows how to define a C++ status object. The CMyMAPIObject class inherits from the IMAPIStatus : IMAPIProp interface. Many of the macros used in this example are defined in the OLE header file COMPOBJ.H.The first members of the class are the methods of the base interface, followed by the methods of the inherited interfaces in order of inheritance. Following the interface definitions are any additional methods, the constructor and destructor, and the data members.

class  CMyMAPIObject : public IMAPIStatus
{
public:
// Methods of IUnknown
    STDMETHODIMP QueryInterface (REFIID riid, LPVOID * ppvObj);
    STDMETHODIMP_(ULONG) AddRef ();
    STDMETHODIMP_(ULONG) Release ();

    MAPI_IMAPIPROP_METHODS(IMPL);
    MAPI_IMAPISTATUS_METHODS(IMPL);

// Other methods specific to CMyMAPIObject
    BOOL WINAPI Method1 ();
    void WINAPI Method2 ();

// Constructors and destructors
public :
    CMyMAPIObject () {};
    ~CMyMAPIObject () {};

// Data members specific to CMyMAPIObject
private :
    ULONG               m_cRef; 
    CAnotherObj *       m_pObj;
};
 

To use an instance of the CMyMAPIObject class, C++ clients or service providers make a call to one of its methods as follows:

lpMyObj->ValidateState(ulUIParam, ulFlags);