RTCEvents.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:2k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "AVDConf.h"
  3. #include "RTCEvents.h"
  4. #include "rtccore_i.c"
  5. #include "rtccore.h"
  6. #include "defines.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. CRTCEvents::CRTCEvents()
  13. {
  14. m_dwRefCount = 0;
  15. m_dwCookie = 0;
  16. m_hWnd = NULL;
  17. }
  18. CRTCEvents::~CRTCEvents()
  19. {
  20. }
  21. ULONG STDMETHODCALLTYPE CRTCEvents::AddRef()
  22. {
  23.     m_dwRefCount++;
  24.     return m_dwRefCount;
  25. }
  26. ULONG STDMETHODCALLTYPE CRTCEvents::Release()
  27. {
  28.     m_dwRefCount--;
  29.     if ( 0 == m_dwRefCount)
  30.     {
  31.         delete this;
  32.     }
  33.     return m_dwRefCount;
  34. }
  35. HRESULT STDMETHODCALLTYPE CRTCEvents::QueryInterface(REFIID iid, void **ppvObject)
  36. {
  37.     if (iid == IID_IRTCEventNotification)
  38.     {
  39.         *ppvObject = (void *)this;
  40.         AddRef();
  41.         return S_OK;
  42.     }
  43.     if (iid == IID_IUnknown)
  44.     {
  45.         *ppvObject = (void *)this;
  46.         AddRef();
  47.         return S_OK;
  48.     }
  49. return E_NOINTERFACE;
  50. }
  51. HRESULT CRTCEvents::Advise(IRTCClient *pClient, HWND hWnd)
  52. {
  53. IConnectionPointContainer * pCPC = NULL;
  54. IConnectionPoint * pCP = NULL;
  55.     HRESULT hr;
  56.    
  57. hr = pClient->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
  58. if (SUCCEEDED(hr))
  59.     {
  60.         
  61. hr = pCPC->FindConnectionPoint(IID_IRTCEventNotification, &pCP);
  62.         SAFE_RELEASE(pCPC);
  63.         if (SUCCEEDED(hr))
  64.         {
  65.             
  66.     hr = pCP->Advise(this, &m_dwCookie);
  67.             SAFE_RELEASE(pCP);
  68.         }
  69.     }
  70.    
  71.     m_hWnd = hWnd;
  72. return hr;
  73. }
  74. HRESULT CRTCEvents::Unadvise(IRTCClient *pClient)
  75. {
  76. IConnectionPointContainer * pCPC = NULL;
  77. IConnectionPoint * pCP = NULL;
  78.     HRESULT hr;
  79.     if (m_dwCookie)
  80.     {
  81.         
  82.     hr = pClient->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
  83.     if (SUCCEEDED(hr))
  84.         {
  85.             
  86.     hr = pCPC->FindConnectionPoint(IID_IRTCEventNotification, &pCP);
  87.             SAFE_RELEASE(pCPC);
  88.             if (SUCCEEDED(hr))
  89.             {
  90.                
  91.         hr = pCP->Unadvise(m_dwCookie);
  92.                 SAFE_RELEASE(pCP);
  93.             }
  94.         }
  95.     }
  96. return hr;
  97. }
  98. HRESULT STDMETHODCALLTYPE CRTCEvents::Event(RTC_EVENT enEvent, IDispatch *pDisp)
  99. {
  100.     pDisp->AddRef();
  101.   
  102.     PostMessage( m_hWnd, WM_RTC_EVENT, (WPARAM)enEvent, (LPARAM)pDisp );
  103.     return S_OK;
  104. }