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.

286 lines
7.6 KiB

  1. #include <eapp.h>
  2. extern "C" const GUID IID_IDebugRegister;
  3. extern "C" const GUID IID_IDebugOut;
  4. #if DBG==1
  5. HRESULT DumpIID(REFIID riid)
  6. {
  7. HRESULT hr;
  8. LPOLESTR pszStr = NULL;
  9. hr = StringFromCLSID(riid, &pszStr);
  10. EProtDebugOut((DEB_NOTFSINK, "API >>> DumpIID (riid:%ws) \n", pszStr));
  11. if (pszStr)
  12. {
  13. delete pszStr;
  14. }
  15. return hr;
  16. }
  17. #else
  18. #define DumpIID(x)
  19. #endif
  20. HRESULT CreateNotificationTest(DWORD dwId, REFCLSID rclsid, IUnknown *pUnkOuter, REFIID riid, IUnknown **ppUnk)
  21. {
  22. EProtDebugOut((DEB_NOTFSINK, "API _IN CreateKnownProtocolInstance\n"));
  23. HRESULT hr = NOERROR;
  24. EProtAssert(( (dwId == 0) && ppUnk));
  25. do
  26. {
  27. if (!ppUnk)
  28. {
  29. // Note: aggregation only works if asked for IUnknown
  30. EProtAssert((FALSE && "Dude, need out parameter"));
  31. hr = E_INVALIDARG;
  32. break;
  33. }
  34. if (pUnkOuter)
  35. {
  36. hr = CLASS_E_NOAGGREGATION;
  37. break;
  38. }
  39. CNotfSink *pNotfSink = new CNotfSink(L"Notificaion Sink");
  40. if (pNotfSink)
  41. {
  42. hr = pNotfSink->QueryInterface(riid, (void **)ppUnk);
  43. // remove extra refcount
  44. pNotfSink->Release();
  45. }
  46. else
  47. {
  48. hr = E_OUTOFMEMORY;
  49. }
  50. break;
  51. } while (TRUE);
  52. EProtDebugOut((DEB_NOTFSINK, "API OUT CreateKnownProtocolInstance(hr:%lx)\n", hr));
  53. return hr;
  54. }
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Method: CNotfSink::QueryInterface
  58. //
  59. // Synopsis:
  60. //
  61. // Arguments: [riid] --
  62. // [ppvObj] --
  63. //
  64. // Returns:
  65. //
  66. // History: 11-22-96 JohannP (Johann Posch) Created
  67. //
  68. // Notes:
  69. //
  70. //----------------------------------------------------------------------------
  71. STDMETHODIMP CNotfSink::QueryInterface(REFIID riid, void **ppvObj)
  72. {
  73. VDATEPTROUT(ppvObj, void *);
  74. VDATETHIS(this);
  75. HRESULT hr = NOERROR;
  76. EProtDebugOut((DEB_NOTFSINK, "%p _IN CNotfSink::QueryInterface\n", this));
  77. EProtAssert(( IsApartmentThread() ));
  78. *ppvObj = NULL;
  79. if ((riid == IID_IUnknown) || (riid == IID_INotificationSink) )
  80. {
  81. *ppvObj = this;
  82. AddRef();
  83. }
  84. else if ((riid == IID_IDebugRegister) )
  85. {
  86. *ppvObj = (IDebugRegister *) this;
  87. AddRef();
  88. }
  89. else
  90. {
  91. hr = E_NOINTERFACE;
  92. }
  93. EProtDebugOut((DEB_NOTFSINK, "%p OUT CNotfSink::QueryInterface (hr:%lx\n", this,hr));
  94. return hr;
  95. }
  96. //+---------------------------------------------------------------------------
  97. //
  98. // Function: CNotfSink::AddRef
  99. //
  100. // Synopsis:
  101. //
  102. // Arguments: [ULONG] --
  103. //
  104. // Returns:
  105. //
  106. // History: 11-22-96 JohannP (Johann Posch) Created
  107. //
  108. // Notes:
  109. //
  110. //----------------------------------------------------------------------------
  111. STDMETHODIMP_(ULONG) CNotfSink::AddRef(void)
  112. {
  113. EProtDebugOut((DEB_NOTFSINK, "%p _IN CNotfSink::AddRef\n", this));
  114. EProtAssert(( IsApartmentThread() ));
  115. LONG lRet = ++_CRefs;
  116. EProtDebugOut((DEB_NOTFSINK, "%p OUT CNotfSink::AddRef (cRefs:%ld)\n", this,lRet));
  117. return lRet;
  118. }
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Function: CNotfSink::Release
  122. //
  123. // Synopsis:
  124. //
  125. // Arguments: [ULONG] --
  126. //
  127. // Returns:
  128. //
  129. // History: 11-22-96 JohannP (Johann Posch) Created
  130. //
  131. // Notes:
  132. //
  133. //----------------------------------------------------------------------------
  134. STDMETHODIMP_(ULONG) CNotfSink::Release(void)
  135. {
  136. EProtDebugOut((DEB_NOTFSINK, "%p _IN CNotfSink::Release\n", this));
  137. EProtAssert(( IsApartmentThread() ));
  138. LONG lRet = --_CRefs;
  139. if (_CRefs == 0)
  140. {
  141. delete this;
  142. }
  143. EProtDebugOut((DEB_NOTFSINK, "%p OUT CNotfSink::Release (cRefs:%ld)\n",this,lRet));
  144. return lRet;
  145. }
  146. //+---------------------------------------------------------------------------
  147. //
  148. // Method: CNotfSink::OnNotification
  149. //
  150. // Synopsis:
  151. //
  152. // Arguments: [itemtype] --
  153. // [pWChkItem] --
  154. // [dwReserved] --
  155. //
  156. // Returns:
  157. //
  158. // History: 12-02-1996 JohannP (Johann Posch) Created
  159. //
  160. // Notes:
  161. //
  162. //----------------------------------------------------------------------------
  163. STDMETHODIMP CNotfSink::OnNotification(
  164. // the notification object itself
  165. LPNOTIFICATION pNotification,
  166. // the cookie of the object the notification is targeted too
  167. //PNOTIFICATIONCOOKIE pRunningNotfCookie,
  168. // flags how it was delivered and how it should
  169. // be processed
  170. //NOTIFICATIONFLAGS grfNotification,
  171. // the report sink if - can be NULL
  172. LPNOTIFICATIONREPORT pNotfctnReport,
  173. DWORD dwReserved
  174. )
  175. {
  176. EProtDebugOut((DEB_NOTFSINK, "%p _IN CNotfSink::OnNotification\n", this));
  177. EProtAssert(( IsApartmentThread() ));
  178. EProtAssert((pNotification));
  179. HRESULT hr = NOERROR;
  180. LPOLESTR pszStr = NULL;
  181. NOTIFICATIONTYPE notfType;
  182. NOTIFICATIONCOOKIE notfCookie;
  183. PNOTIFICATIONCOOKIE pRunningNotfCookie = 0;
  184. // flags how it was delivered and how it should
  185. // be processed
  186. NOTIFICATIONFLAGS grfNotification = (NOTIFICATIONFLAGS)0;
  187. //hr = pNotification->GetNotificationType(&notfType);
  188. hr = pNotification->GetNotificationInfo(&notfType, &notfCookie, 0, 0, 0);
  189. if (hr == NOERROR)
  190. {
  191. hr = StringFromCLSID(notfType, &pszStr);
  192. }
  193. EProtDebugOut((DEB_NOTFSINK, "%p CNotfSink:%ws received pNotification:%p\n with id:%ws\n", this, _pwzName, pNotification,pszStr));
  194. //EProtDebugOut((DEB_NOTFSINK, "%p CNotfSink:%ws received pNotification:%p \n", this, _pwzName, pNotification));
  195. MessageBeep(1000);
  196. if (pszStr)
  197. {
  198. delete pszStr;
  199. }
  200. /*
  201. if (pNotification->pCustomData != 0)
  202. {
  203. IDebugOut *pDbgOut = 0;
  204. char szOutBuffer[256];
  205. pDbgOut = (IDebugOut *) pNotification->pCustomData;
  206. sprintf(szOutBuffer, "%p CNotfSink:%ws received pNotification:%p with id:%ws\n", this, _pwzName, pNotification, pNotification->pNotificationid);
  207. pDbgOut->SendEntry(GetCurrentThreadId(), 0, szOutBuffer, 0);
  208. }
  209. */
  210. // don't return an error!
  211. hr = NOERROR;
  212. EProtDebugOut((DEB_NOTFSINK, "%p OUT CNotfSink::OnNotification (hr:%lx)\n",this, hr));
  213. return hr;
  214. }
  215. STDMETHODIMP CNotfSink::GetFacilities (LPCWSTR *ppwzNames, DWORD *pcNames, DWORD dwReserved)
  216. {
  217. EProtDebugOut((DEB_NOTFSINK, "%p _IN CNotfSink::GetFacilities\n", this));
  218. EProtAssert(( IsApartmentThread() ));
  219. EProtAssert(( ppwzNames && pcNames ));
  220. HRESULT hr = NOERROR;
  221. ppwzNames = v_gDbgFacilitieNames;
  222. LONG x = sizeof(*v_gDbgFacilitieNames);
  223. LONG y = sizeof(LPCWSTR);
  224. *pcNames = (sizeof(*v_gDbgFacilitieNames)/sizeof(LPCWSTR));
  225. EProtDebugOut((DEB_NOTFSINK, "%p OUT CNotfSink::GetFacilities (hr:%lx)\n",this, hr));
  226. return hr;
  227. }
  228. STDMETHODIMP CNotfSink::Register ( LPCWSTR pwzName, IDebugOut *pDbgOut, DWORD dwFlags, DWORD dwReserved)
  229. {
  230. EProtDebugOut((DEB_NOTFSINK, "%p _IN CNotfSink::Register\n", this));
  231. EProtAssert(( IsApartmentThread() ));
  232. HRESULT hr = NOERROR;
  233. hr = RegisterDebugOut(pwzName, dwFlags, pDbgOut, dwReserved);
  234. EProtDebugOut((DEB_NOTFSINK, "%p OUT CNotfSink::Register (hr:%lx)\n",this, hr));
  235. return hr;
  236. }