Microsoft Chat Server Development Guide

MsgFilterPP.cpp

// MsgFilterPP.cpp : Implementation of CMsgFilterPP
#include "stdafx.h"
#include "MsgFilterPP.h"


/////////////////////////////////////////////////////////////////////////////
// CMsgFilterPP


// CHATSDK: Implement the Activate method
/*******************************************************************/
/* Override of IPropertyPageImpl::Activate()                       */
/* We need to override this function in order to init the controls */
/* on the pages with the stored settings                           */
/*******************************************************************/
STDMETHODIMP CMsgFilterPP::Activate(HWND hWndParent, LPCRECT pRect , BOOL bModal)
{
    // call base class implementation of Activate() first
    IPropertyPageImpl<CMsgFilterPP>::Activate(hWndParent, pRect , bModal);

    // The following code navigates the Chat Object model to get 
    // an interface to the instance of our extension running on the server
    // ChatServer.Configuration.ChatExtensions("CLSID").Instance
    // All error checking is left-out for sample clarity

    //Get the reference to the chat server
    CComPtr<IChatServer> pCServer = (IChatServer *)(m_ppUnk[0]);
    
    // Get the variant holding the IDispatch to the ChatConfiguration object
    VARIANT varDisp;
    pCServer->get_Configuration(&varDisp);
    
    // We used the #import in StdAfx.h for chatcfg.dll's type-library
    // Get a QI from the configuration Dispatch for the IChatConfiguration interface
    IChatConfigurationPtr pCfg( V_DISPATCH(&varDisp) );

    // Retrieve the interface to the collection of installed extensions
    IChatExtensionsPtr pExtns( pCfg->ChatExtensions );

    // Get a string containing the CLSID for our extension
    wchar_t szwClsid[128];
    StringFromGUID2(CLSID_MessageFilter, szwClsid, 64);

    // Index into the ChatExtensions collection by our extensions CLSID
    _variant_t varClsid(szwClsid);
    IChatExtensionPtr pExtn( pExtns->Item[varClsid] );
    
    // And finally, QI the dispatch interface returned by .Instance to
    // get the interface to the our actual extension running on the server
    CComPtr<IDispatch> pDisp = pExtn->Instance;
    pDisp->QueryInterface(IID_IChatMsgFilter, (void **)&m_pMyExtension);

    // If we got it, fill in the list box with the words held by the extension 
    if( m_pMyExtension != NULL ) {        
        USES_CONVERSION;
        int max;
        BSTR word;
        
        // iterate through the words held by the extension and add then to the list box
        m_pMyExtension->get_Count(&max);
        for(int i = 0; i < max; i++) {            
            m_pMyExtension->get_Item(i, &word);

            SendDlgItemMessage(IDC_WORD_LIST, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR)OLE2A(word));
            SysFreeString(word); // COM defines the automation client responsible to free BSTR
        }
    }
    
    return S_OK;
}


// COMMAND_HANDLER for the BN_CLICKED event on the add button on the property page
LRESULT CMsgFilterPP::OnAddClick(WORD wNotify, WORD wID, HWND hWnd, BOOL& bHandled)
{
    // Check we have a valid reference to the extension on the chat server
    if( m_pMyExtension ) {
        USES_CONVERSION;
        char word[32];

        // Copy the text from the text box to the list box
        SendDlgItemMessage(IDC_WORD, WM_GETTEXT, sizeof(word), (LPARAM)word);
        SendDlgItemMessage(IDC_WORD_LIST, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR)(LPCTSTR)word);
        
        // add the word to the extension's list of words
        m_pMyExtension->Add( A2BSTR(word) );
    }
    return 0;
}

© 1998 Microsoft Corporation. All rights reserved.