1
0

external.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "main.h"
  2. #include "./resource.h"
  3. #include "./external.h"
  4. ExternalDispatch::ExternalDispatch()
  5. : ref(1)
  6. {
  7. }
  8. ExternalDispatch::~ExternalDispatch()
  9. {
  10. }
  11. HRESULT ExternalDispatch::CreateInstance(ExternalDispatch **instance)
  12. {
  13. if (NULL == instance) return E_POINTER;
  14. *instance = new ExternalDispatch();
  15. if (NULL == *instance) return E_OUTOFMEMORY;
  16. return S_OK;
  17. }
  18. LPCWSTR ExternalDispatch::GetName()
  19. {
  20. return L"NowPlaying";
  21. }
  22. ULONG ExternalDispatch::AddRef(void)
  23. {
  24. return InterlockedIncrement((LONG*)&ref);
  25. }
  26. ULONG ExternalDispatch::Release(void)
  27. {
  28. if (0 == ref)
  29. return ref;
  30. LONG r = InterlockedDecrement((LONG*)&ref);
  31. if (0 == r)
  32. delete(this);
  33. return r;
  34. }
  35. STDMETHODIMP ExternalDispatch::QueryInterface(REFIID riid, void **ppvObject)
  36. {
  37. if (NULL == ppvObject) return E_POINTER;
  38. if (IsEqualIID(riid, IID_IDispatch))
  39. *ppvObject = static_cast<IDispatch*>(this);
  40. else if (IsEqualIID(riid, IID_IUnknown))
  41. *ppvObject = static_cast<IUnknown*>(this);
  42. else
  43. {
  44. *ppvObject = NULL;
  45. return E_NOINTERFACE;
  46. }
  47. AddRef();
  48. return S_OK;
  49. }
  50. HRESULT ExternalDispatch::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  51. {
  52. bool unknowns = false;
  53. for (unsigned int i = 0;i != cNames;i++)
  54. {
  55. if (_wcsicmp(rgszNames[i], L"hidden") == 0)
  56. rgdispid[i] = DISPATCH_HIDDEN;
  57. else
  58. {
  59. rgdispid[i] = DISPID_UNKNOWN;
  60. unknowns = true;
  61. }
  62. }
  63. if (unknowns)
  64. return DISP_E_UNKNOWNNAME;
  65. else
  66. return S_OK;
  67. }
  68. HRESULT ExternalDispatch::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  69. {
  70. return E_NOTIMPL;
  71. }
  72. HRESULT ExternalDispatch::GetTypeInfoCount(unsigned int FAR * pctinfo)
  73. {
  74. return E_NOTIMPL;
  75. }
  76. HRESULT ExternalDispatch::Invoke(DISPID dispId, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  77. {
  78. switch(dispId)
  79. {
  80. case DISPATCH_HIDDEN:
  81. if (NULL != pvarResult)
  82. {
  83. HWND hLibrary = Plugin_GetLibrary();
  84. VariantInit(pvarResult);
  85. V_VT(pvarResult) = VT_BOOL;
  86. V_BOOL(pvarResult) = (NULL == hLibrary || FALSE == SENDMLIPC(hLibrary, ML_IPC_IS_VISIBLE, 0));
  87. }
  88. return S_OK;
  89. }
  90. return DISP_E_MEMBERNOTFOUND;
  91. }