ExternalCOM.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "main.h"
  2. #include "./externalCOM.h"
  3. #include "./util.h"
  4. #include "./rssCOM.h"
  5. #define DISPTABLE_CLASS ExternalCOM
  6. DISPTABLE_BEGIN()
  7. DISPENTRY_ADD(DISPATCH_PODCAST, L"Podcast", OnPodcast)
  8. DISPTABLE_END
  9. #undef DISPTABLE_CLASS
  10. ExternalCOM::ExternalCOM()
  11. {}
  12. ExternalCOM::~ExternalCOM()
  13. {}
  14. HRESULT ExternalCOM::CreateInstance(ExternalCOM **instance)
  15. {
  16. if (NULL == instance) return E_POINTER;
  17. *instance = new ExternalCOM();
  18. if (NULL == *instance) return E_OUTOFMEMORY;
  19. return S_OK;
  20. }
  21. STDMETHODIMP_( ULONG ) ExternalCOM::AddRef( void )
  22. {
  23. return _ref.fetch_add( 1 );
  24. }
  25. STDMETHODIMP_( ULONG ) ExternalCOM::Release( void )
  26. {
  27. if ( 0 == _ref.load() )
  28. return _ref.load();
  29. LONG r = _ref.fetch_sub( 1 );
  30. if ( 0 == r )
  31. delete( this );
  32. return r;
  33. }
  34. STDMETHODIMP ExternalCOM::QueryInterface(REFIID riid, PVOID *ppvObject)
  35. {
  36. if (NULL == ppvObject) return E_POINTER;
  37. if (IsEqualIID(riid, IID_IDispatch))
  38. *ppvObject = static_cast<IDispatch*>(this);
  39. else if (IsEqualIID(riid, IID_IUnknown))
  40. *ppvObject = static_cast<IUnknown*>(this);
  41. else
  42. {
  43. *ppvObject = NULL;
  44. return E_NOINTERFACE;
  45. }
  46. AddRef();
  47. return S_OK;
  48. }
  49. HRESULT ExternalCOM::OnPodcast(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  50. {
  51. if (NULL != pvarResult)
  52. {
  53. VariantInit(pvarResult);
  54. RssCOM *rss;
  55. if (SUCCEEDED(RssCOM::CreateInstance(&rss)))
  56. {
  57. V_VT(pvarResult) = VT_DISPATCH;
  58. V_DISPATCH(pvarResult) = rss;
  59. }
  60. else
  61. {
  62. V_VT(pvarResult) = VT_NULL;
  63. }
  64. }
  65. return S_OK;
  66. }