home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / AutoPC / apcsdk10.exe / data1.cab / Win32_Samples / win32 / simpleclock / scsink.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-13  |  3.5 KB  |  155 lines

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. Copyright (c) 1998 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     SimpleClockSink.cpp
  8.  
  9. Abstract:
  10.  
  11.     Implementation of IUnknown, IASEventSink, and IASClassMsgSink 
  12.  
  13. Environment:
  14.  
  15.     AutoPC
  16.  
  17. -------------------------------------------------------------------*/
  18.  
  19. //Non-application header files
  20. #include <windows.h>
  21. #include <olectl.h>
  22. #include <asfc.h>        //Header for AS Forms Manager
  23. #include <ascmnctl.h>    //Header for AS Common Controls
  24. #include <apcdebug.h>
  25.  
  26. //Application header files
  27. #include "simpleclock.h"
  28.  
  29. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30. Function:
  31.     CSimpleClockSink
  32.  
  33. Description:
  34.     Constructor, sets member variables
  35.  
  36. Parameters:
  37.     [IN] DWORD dwThreadID - Current process thread ID
  38. -------------------------------------------------------------------*/
  39.  
  40. CSimpleClockSink::CSimpleClockSink(DWORD dwThreadID)
  41. {
  42.     m_dwThreadID = dwThreadID;
  43. }
  44.  
  45. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46. Function:
  47.     ~CSimpleClockSink
  48.  
  49. Description:
  50.     Destructor, does nothing in this case
  51. -------------------------------------------------------------------*/
  52.  
  53. CSimpleClockSink::~CSimpleClockSink()
  54. {
  55.  
  56. }
  57.  
  58. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  59. Function:
  60.     QueryInterface
  61.  
  62. Description:
  63.     Returns the requested interface pointer
  64.  
  65. Parameters:
  66.     [IN] REFIID riid - Interface GUID requested
  67.     [OUT] PVOID *ppv - Pointer to the requested interface
  68.     returns HRESULT status
  69. -------------------------------------------------------------------*/
  70.  
  71. STDMETHODIMP
  72. CSimpleClockSink::QueryInterface(REFIID riid,
  73.                                  PVOID *ppv)
  74. {
  75.     HRESULT hr = NOERROR;
  76.  
  77.     if(!ppv) hr = E_INVALIDARG;
  78.  
  79.     if(SUCCEEDED(hr))
  80.     {
  81.         if (riid == IID_ASCLASSMSGSINK) *ppv = (PVOID) (IASClassMsgSink *) this; 
  82.         else if (riid == IID_ASEVENTSINK) *ppv = (PVOID) (IASEventSink*) this; 
  83.         else if (riid == IID_IUnknown) *ppv = (PVOID) (IUnknown *) (IASClassMsgSink *)this;
  84.         else if (riid == IID_IDispatch)    *ppv = (PVOID) (IDispatch *) (IASClassMsgSink *)this;
  85.         else hr = E_NOINTERFACE;
  86.     }
  87.  
  88.     if(SUCCEEDED(hr)) AddRef();
  89.  
  90.     return hr;
  91. }
  92.  
  93. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  94. Function:
  95.     AddRef
  96.  
  97. Description:
  98.     Adds to this objects reference count
  99.  
  100. Parameters:
  101.     returns current reference count
  102. -------------------------------------------------------------------*/
  103.  
  104. STDMETHODIMP_(ULONG)
  105. CSimpleClockSink::AddRef()
  106. {
  107.     InterlockedIncrement(&m_lRefCount);
  108.  
  109.     return m_lRefCount;         
  110. }
  111.  
  112. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  113. Function:
  114.     Release
  115.  
  116. Description:
  117.     Decreases reference count, deletes object when necessary ref=0
  118.  
  119. Parameters:
  120.     returns current reference count
  121. -------------------------------------------------------------------*/
  122.  
  123. STDMETHODIMP_(ULONG)
  124. CSimpleClockSink::Release()
  125. {
  126.     if(InterlockedDecrement(&m_lRefCount) == 0)
  127.     {
  128.         delete this;
  129.         return(0);
  130.     }
  131.     return m_lRefCount;
  132. }            
  133.  
  134. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  135. Function:
  136.     HandleKeyPress
  137.  
  138. Description:
  139.     Posts a WM_QUIT.  Exits app when any key pressed
  140.  
  141. Parameters:
  142.     returns S_OK
  143. -------------------------------------------------------------------*/
  144.  
  145.  
  146. STDMETHODIMP 
  147. CSimpleClockSink::HandleKeyPress(IDispatch* pdispControl,
  148.                                  LONG lKeyPress)
  149. {
  150.  
  151.     PostThreadMessage(m_dwThreadID, WM_QUIT, 0, 0);
  152.     return S_OK;
  153. }
  154.  
  155.