Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can design ABO applications so that they are notified when certain events occur. To receive event notifications, a listener object must implement a COM sink of a class inherited from the IMSAdminBaseSink interface. Also, the listener object should be free-threaded because notifications are asynchronous and might arrive out of order.
Example Code
The following code example shows you how to use the C++ programming language to to implement the IMSAdminBaseSink interface in a listener object. This example requires the header files iadmw.h and iiscnfg.h.
class CSvcExtImpIMDCOMSINK : public IMSAdminBaseSink { 
public: 
    CSvcExtImpIMDCOMSINK(); 
    ~CSvcExtImpIMDCOMSINK(); 
    STDMETHODIMP 
    QueryInterface(REFIID riid, void **ppObject); 
    STDMETHODIMP_(ULONG) 
    AddRef(); 
    STDMETHODIMP_(ULONG) 
    Release(); 
    STDMETHODIMP 
    SinkNotify( 
        DWORD            dwMDNumElements, 
        MD_CHANGE_OBJECT pcoChangeList[  ]); 
    STDMETHODIMP 
    ShutdownNotify(); 
private: 
    ULONG m_dwRefCount; 
}; 
CSvcExtImpIMDCOMSINK::CSvcExtImpIMDCOMSINK(): 
    m_dwRefCount(1), 
{ 
} 
CSvcExtImpIMDCOMSINK::~CSvcExtImpIMDCOMSINK() 
{ 
} 
STDMETHODIMP 
CSvcExtImpIMDCOMSINK::QueryInterface( 
    REFIID              riid, 
    void                **ppObject) 
{ 
    if ( ppObject == NULL ) 
    { 
        return E_INVALIDARG; 
    } 
    *ppObject = NULL; 
    if (riid==IID_IUnknown || riid==IID_IMSAdminBaseSink) 
    { 
        *ppObject = (IMSAdminBaseSink *) this; 
    } 
    else 
    { 
        return E_NOINTERFACE; 
    } 
    AddRef(); 
    return NO_ERROR; 
} 
STDMETHODIMP_(ULONG) 
CSvcExtImpIMDCOMSINK::AddRef() 
{ 
    DWORD dwRefCount; 
    dwRefCount = InterlockedIncrement((long *)&m_dwRefCount); 
    return dwRefCount; 
} 
STDMETHODIMP_(ULONG) 
CSvcExtImpIMDCOMSINK::Release() 
{ 
    DWORD dwRefCount; 
    dwRefCount = InterlockedDecrement((long *)&m_dwRefCount); 
    if (dwRefCount == 0) 
    { 
        delete this; 
    } 
    return dwRefCount; 
} 
STDMETHODIMP 
CSvcExtImpIMDCOMSINK::SinkNotify( 
    DWORD                       dwMDNumElements, 
    MD_CHANGE_OBJECT __RPC_FAR  pcoChangeList[  ]) { 
    DWORD                       i; 
    DWORD                       j; 
    for (i = 0; i < dwMDNumElements; i++) 
    { 
        if ( ( pcoChangeList[i].dwMDChangeType & MD_CHANGE_TYPE_SET_DATA ) != 0) 
        { 
            for (j = 0; j < pcoChangeList[i].dwMDNumDataIDs; j++) 
            { 
                switch (pcoChangeList[i].pdwMDDataIDs[j]) 
                { 
                case MD_*: 
  // Do something 
                    break; 
                default: 
                    break; 
                    // 
                    // No specific action for this command 
                    // 
                } 
            } 
        } 
    } 
    return S_OK; 
} 
STDMETHODIMP 
CSvcExtImpIMDCOMSINK::ShutdownNotify() 
{ 
    return S_OK; 
}