home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap06 / ekoala3 / msgfilt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.2 KB  |  149 lines

  1. /*
  2.  * MSGFILT.CPP
  3.  * Koala Object for EXE Servers, Chapter 6
  4.  *
  5.  * Implementation of a message filter object to block or delay
  6.  * calls.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "ekoala3.h"
  17.  
  18.  
  19. /*
  20.  * CMessageFilter::CMessageFilter
  21.  * CMessageFilter::~CMessageFilter
  22.  *
  23.  * Parameters (Constructor):
  24.  *  pApp            PAPP of the application we're in
  25.  */
  26.  
  27. CMessageFilter::CMessageFilter(PAPP pApp)
  28.     {
  29.     m_cRef=0;
  30.     m_pApp=pApp;
  31.     return;
  32.     }
  33.  
  34. CMessageFilter::~CMessageFilter(void)
  35.     {
  36.     return;
  37.     }
  38.  
  39.  
  40.  
  41. /*
  42.  * CMessageFilter::QueryInterface
  43.  * CMessageFilter::AddRef
  44.  * CMessageFilter::Release
  45.  *
  46.  * Purpose:
  47.  *  Delegating IUnknown members for CMessageFilter.
  48.  */
  49.  
  50. STDMETHODIMP CMessageFilter::QueryInterface(REFIID riid
  51.     , LPVOID *ppv)
  52.     {
  53.     *ppv=NULL;
  54.  
  55.     if (IID_IUnknown==riid || IID_IMessageFilter==riid)
  56.         *ppv=this;
  57.  
  58.     if (NULL!=*ppv)
  59.         {
  60.         ((LPUNKNOWN)*ppv)->AddRef();
  61.         return NOERROR;
  62.         }
  63.  
  64.     return ResultFromScode(E_NOINTERFACE);
  65.     }
  66.  
  67. STDMETHODIMP_(ULONG) CMessageFilter::AddRef(void)
  68.     {
  69.     return ++m_cRef;
  70.     }
  71.  
  72. STDMETHODIMP_(ULONG) CMessageFilter::Release(void)
  73.     {
  74.     if (0!=--m_cRef)
  75.         return m_cRef;
  76.  
  77.     delete this;
  78.     return 0;
  79.     }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /*
  87.  * CMessageFilter::HandleInComingCall
  88.  *
  89.  * Purpose:
  90.  *  Requests that the container call OleSave for the object that
  91.  *  lives here.  Typically this happens on server shutdown.
  92.  *
  93.  * Parameters:
  94.  *  dwCallType      DWORD indicating the type of call received, from
  95.  *                  the CALLTYPE enumeration
  96.  *  hTaskCaller     HTASK of the caller
  97.  *  dwTickCount     DWORD elapsed tick count since the outgoing call
  98.  *                  was made if dwCallType is not CALLTYPE_TOPLEVEL.
  99.  *                  Ignored for other call types.
  100.  *  pInterfaceInfo  LPINTERFACEINFO providing information about the
  101.  *                  call.  Can be NULL.
  102.  *
  103.  * Return Value:
  104.  *  DWORD           One of SERVERCALL_ISHANDLED (if the call might
  105.  *                  be handled), SERVERCALL_REJECTED (call cannot
  106.  *                  be handled), or SERVERCALL_RETRYLATER (try
  107.  *                  again sometime).
  108.  */
  109.  
  110. STDMETHODIMP_(DWORD) CMessageFilter::HandleInComingCall
  111.     (DWORD dwCallType, HTASK htaskCaller, DWORD dwTickCount
  112. #ifdef WIN32
  113.     , LPINTERFACEINFO pInterfaceInfo)
  114. #else
  115.     , DWORD dwReserved)
  116. #endif
  117.     {
  118.     if (m_pApp->m_fBlock)
  119.         return SERVERCALL_REJECTED;
  120.  
  121.     if (m_pApp->m_fDelay)
  122.         return SERVERCALL_RETRYLATER;
  123.  
  124.     return SERVERCALL_ISHANDLED;
  125.     }
  126.  
  127.  
  128.  
  129.  
  130.  
  131. /*
  132.  * CMessageFilter::RetryRejectedCall
  133.  * CMessageFilter::MessagePending
  134.  *
  135.  * Not implemented:  no outgoing calls from this process.
  136.  */
  137.  
  138. STDMETHODIMP_(DWORD) CMessageFilter::RetryRejectedCall
  139.     (HTASK htaskCallee, DWORD dwTickCount, DWORD dwRejectType)
  140.     {
  141.     return 0;
  142.     }
  143.  
  144. STDMETHODIMP_(DWORD) CMessageFilter::MessagePending
  145.     (HTASK htaskCallee, DWORD dwTickCount, DWORD dwPendingType)
  146.     {
  147.     return PENDINGMSG_WAITDEFPROCESS;
  148.     }
  149.