Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
5.7 KiB

  1. //==========================================================================;
  2. //
  3. // devimpl.h : additional infrastructure to support implementing IMSVidDevice
  4. // nicely from c++
  5. // Copyright (c) Microsoft Corporation 1999.
  6. //
  7. /////////////////////////////////////////////////////////////////////////////
  8. #pragma once
  9. #ifndef DEVIMPL_H
  10. #define DEVIMPL_H
  11. #include "devsegimpl.h"
  12. namespace MSVideoControl {
  13. template<class T, LPCGUID LibID, LPCGUID Category, class MostDerivedInterface = IMSVidDevice>
  14. class DECLSPEC_NOVTABLE IMSVidDeviceImpl :
  15. public IDispatchImpl<MostDerivedInterface, &__uuidof(MostDerivedInterface), LibID>,
  16. public virtual CMSVidDeviceSegmentImpl {
  17. public:
  18. virtual ~IMSVidDeviceImpl() {}
  19. CComBSTR GetName(DSFilter& pF, DSFilterMoniker& pDev, CComBSTR& DefName) {
  20. if (pF) {
  21. CString csName(pF.GetName());
  22. if (!csName.IsEmpty()) {
  23. return CComBSTR(csName);
  24. }
  25. }
  26. if (pDev) {
  27. return pDev.GetName();
  28. }
  29. return DefName;
  30. }
  31. STDMETHOD(get_Status)(LONG * Status)
  32. {
  33. if (!m_fInit) {
  34. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidDevice), CO_E_NOTINITIALIZED);
  35. }
  36. if (Status == NULL)
  37. return E_POINTER;
  38. return E_NOTIMPL;
  39. }
  40. STDMETHOD(get_Power)(VARIANT_BOOL * Status)
  41. {
  42. if (!m_fInit) {
  43. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidDevice), CO_E_NOTINITIALIZED);
  44. }
  45. if (Status == NULL)
  46. return E_POINTER;
  47. return E_NOTIMPL;
  48. }
  49. STDMETHOD(put_Power)(VARIANT_BOOL Status)
  50. {
  51. if (!m_fInit) {
  52. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidDevice), CO_E_NOTINITIALIZED);
  53. }
  54. return E_NOTIMPL;
  55. }
  56. STDMETHOD(get_Category)(BSTR *guid)
  57. {
  58. if (!m_fInit) {
  59. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidDevice), CO_E_NOTINITIALIZED);
  60. }
  61. if (!guid) {
  62. return E_POINTER;
  63. }
  64. try {
  65. GUID2 g(Category);
  66. *guid = g.GetBSTR();
  67. } catch(...) {
  68. return E_UNEXPECTED;
  69. }
  70. return NOERROR;
  71. }
  72. STDMETHOD(get__Category)(GUID* guid)
  73. {
  74. if (!m_fInit) {
  75. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidDevice), CO_E_NOTINITIALIZED);
  76. }
  77. if (!guid) {
  78. return E_POINTER;
  79. }
  80. try {
  81. memcpy(guid, Category, sizeof(GUID));
  82. } catch(...) {
  83. return E_UNEXPECTED;
  84. }
  85. return NOERROR;
  86. }
  87. STDMETHOD(get_ClassID)(BSTR *guid)
  88. {
  89. if (!m_fInit) {
  90. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidDevice), CO_E_NOTINITIALIZED);
  91. }
  92. if (!guid) {
  93. return E_POINTER;
  94. }
  95. try {
  96. GUID2 g(__uuidof(T));
  97. *guid = g.GetBSTR();
  98. } catch(...) {
  99. return E_UNEXPECTED;
  100. }
  101. return NOERROR;
  102. }
  103. STDMETHOD(get__ClassID)(GUID* guid)
  104. {
  105. if (!m_fInit) {
  106. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidDevice), CO_E_NOTINITIALIZED);
  107. }
  108. if (!guid) {
  109. return E_POINTER;
  110. }
  111. try {
  112. memcpy(guid, &__uuidof(T), sizeof(GUID));
  113. } catch(...) {
  114. return E_UNEXPECTED;
  115. }
  116. return NOERROR;
  117. }
  118. STDMETHOD(IsEqualDevice)(IMSVidDevice *pDev, VARIANT_BOOL* pfAnswer) {
  119. if (!pDev || !pfAnswer) {
  120. return E_POINTER;
  121. }
  122. try {
  123. *pfAnswer = VARIANT_FALSE;
  124. PUnknown pt(this);
  125. PUnknown pd(pDev);
  126. if (pt == pd) {
  127. *pfAnswer = VARIANT_TRUE;
  128. return NOERROR;
  129. }
  130. GUID2 gt, gd;
  131. HRESULT hr = get__ClassID(&gt);
  132. if (FAILED(hr)) {
  133. return E_UNEXPECTED;
  134. }
  135. hr = pDev->get__ClassID(&gd);
  136. if (FAILED(hr)) {
  137. return E_UNEXPECTED;
  138. }
  139. if (gd != gt) {
  140. return S_FALSE;
  141. }
  142. PQGraphSegment pst(this), pdt(pDev);
  143. PUnknown pit, pid;
  144. hr = pst->get_Init(&pit);
  145. if (FAILED(hr)) {
  146. pit.Release();
  147. }
  148. hr = pdt->get_Init(&pid);
  149. if (FAILED(hr)) {
  150. pid.Release();
  151. }
  152. if (pit == pid) {
  153. *pfAnswer = VARIANT_TRUE;
  154. return NOERROR;
  155. }
  156. PQMoniker pmt(pit), pmd(pid);
  157. if (!pmt || !pmd) {
  158. // we don't know how to deal with init data that isn't a moniker
  159. return S_FALSE;
  160. }
  161. PQMalloc pmalloc;
  162. hr = CoGetMalloc(1, &pmalloc);
  163. if (FAILED(hr)) {
  164. return E_UNEXPECTED;
  165. }
  166. LPOLESTR pnt, pnd;
  167. hr = pmt->GetDisplayName(NULL, NULL, &pnt);
  168. if (FAILED(hr)) {
  169. return S_FALSE;
  170. }
  171. hr = pmd->GetDisplayName(NULL, NULL, &pnd);
  172. if (FAILED(hr)) {
  173. pmalloc->Free(pnt);
  174. return S_FALSE;
  175. }
  176. int rc = wcscmp(pnt, pnd);
  177. pmalloc->Free(pnt);
  178. pmalloc->Free(pnd);
  179. if (rc) {
  180. return S_FALSE;
  181. }
  182. *pfAnswer = VARIANT_TRUE;
  183. return NOERROR;
  184. } catch(...) {
  185. return E_UNEXPECTED;
  186. }
  187. }
  188. };
  189. }; // namespace
  190. #endif
  191. // end of file - devimpl.h