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.

181 lines
6.8 KiB

  1. /*****************************************************************************
  2. * (C) COPYRIGHT MICROSOFT CORPORATION, 2002
  3. *
  4. * AUTHOR: ByronC
  5. *
  6. * DATE: 4/1/2002
  7. *
  8. * @doc INTERNAL
  9. *
  10. * @module ClientEventRegistrationInfo.cpp - Declarations for <c ClientEventRegistrationInfo> |
  11. *
  12. * This file contains the implementation for <c ClientEventRegistrationInfo>.
  13. *
  14. *****************************************************************************/
  15. #include "cplusinc.h"
  16. #include "coredbg.h"
  17. /*****************************************************************************
  18. * @doc INTERNAL
  19. *
  20. * @mfunc | ClientEventRegistrationInfo | ClientEventRegistrationInfo |
  21. *
  22. * We initialize all member variables. In general, this sets the values to 0,
  23. * except:
  24. * <nl><md EventRegistrationInfo::m_cRef> is set to be 1.
  25. * <nl>We also save the callback interface, and, if it is not NULL,
  26. * we AddRef it here.
  27. *
  28. *****************************************************************************/
  29. ClientEventRegistrationInfo::ClientEventRegistrationInfo(
  30. DWORD dwFlags,
  31. GUID guidEvent,
  32. WCHAR *wszDeviceID,
  33. IWiaEventCallback *pIWiaEventCallback) :
  34. EventRegistrationInfo(dwFlags,
  35. guidEvent,
  36. wszDeviceID,
  37. (ULONG_PTR) pIWiaEventCallback),
  38. m_dwInterfaceCookie(0)
  39. {
  40. DBG_FN(ClientEventRegistrationInfo);
  41. HRESULT hr = S_OK;
  42. if (pIWiaEventCallback)
  43. {
  44. //
  45. // Store the calllback in the GIT
  46. //
  47. IGlobalInterfaceTable *pIGlobalInterfaceTable = NULL;
  48. hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
  49. NULL,
  50. CLSCTX_INPROC_SERVER,
  51. IID_IGlobalInterfaceTable,
  52. (void **)&pIGlobalInterfaceTable);
  53. if (SUCCEEDED(hr))
  54. {
  55. hr = pIGlobalInterfaceTable->RegisterInterfaceInGlobal(pIWiaEventCallback,
  56. IID_IWiaEventCallback,
  57. &m_dwInterfaceCookie);
  58. if (FAILED(hr))
  59. {
  60. DBG_ERR(("Could not store the client's pIWiaEventCallback in the Global Interface Table"));
  61. m_dwInterfaceCookie = 0;
  62. }
  63. pIGlobalInterfaceTable->Release();
  64. }
  65. else
  66. {
  67. DBG_ERR(("Could not get a pointer to the Global Interface Table, hr = 0x%08X", hr));
  68. }
  69. }
  70. }
  71. /*****************************************************************************
  72. * @doc INTERNAL
  73. *
  74. * @mfunc | ClientEventRegistrationInfo | ~ClientEventRegistrationInfo |
  75. *
  76. * Do any cleanup that is not already done.
  77. * Specifically, we release the callback interface if it is not NULL.
  78. *
  79. *****************************************************************************/
  80. ClientEventRegistrationInfo::~ClientEventRegistrationInfo()
  81. {
  82. DBG_FN(~ClientEventRegistrationInfo);
  83. HRESULT hr = S_OK;
  84. //
  85. // Remove the callback from the GIT
  86. //
  87. IGlobalInterfaceTable *pIGlobalInterfaceTable = NULL;
  88. hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
  89. NULL,
  90. CLSCTX_INPROC_SERVER,
  91. IID_IGlobalInterfaceTable,
  92. (void **)&pIGlobalInterfaceTable);
  93. if (SUCCEEDED(hr))
  94. {
  95. // TBD: Do we need to release after pulling it out?
  96. hr = pIGlobalInterfaceTable->RevokeInterfaceFromGlobal(m_dwInterfaceCookie);
  97. if (FAILED(hr))
  98. {
  99. DBG_ERR(("Could not revoke the client's pIWiaEventCallback from the Global Interface Table"));
  100. }
  101. pIGlobalInterfaceTable->Release();
  102. }
  103. else
  104. {
  105. DBG_ERR(("Could not get a pointer to the Global Interface Table, hr = 0x%08X", hr));
  106. }
  107. m_dwInterfaceCookie = 0;
  108. }
  109. /*****************************************************************************
  110. * @doc INTERNAL
  111. *
  112. * @mfunc IWiaEventCallback* | ClientEventRegistrationInfo | getCallbackInterface |
  113. *
  114. * Returns the callback interface used for this registration. When a matching event
  115. * occurs, this interface is used to notify the client of the event.
  116. *
  117. * This is AddRef'd - caller must release.
  118. *
  119. * @rvalue NULL |
  120. * No callback interface was provided.
  121. * @rvalue non-NULL |
  122. * The callback interface for this registration. Caller must Release.
  123. *****************************************************************************/
  124. IWiaEventCallback* ClientEventRegistrationInfo::getCallbackInterface()
  125. {
  126. HRESULT hr = S_OK;
  127. IWiaEventCallback *pIWiaEventCallback = NULL;
  128. //
  129. // Store the calllback in the GIT
  130. //
  131. IGlobalInterfaceTable *pIGlobalInterfaceTable = NULL;
  132. hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
  133. NULL,
  134. CLSCTX_INPROC_SERVER,
  135. IID_IGlobalInterfaceTable,
  136. (void **)&pIGlobalInterfaceTable);
  137. if (SUCCEEDED(hr))
  138. {
  139. hr = pIGlobalInterfaceTable->GetInterfaceFromGlobal(m_dwInterfaceCookie,
  140. IID_IWiaEventCallback,
  141. (void**)&pIWiaEventCallback);
  142. if (FAILED(hr))
  143. {
  144. DBG_ERR(("Could not get the client's IWiaEventCallback from the Global Interface Table"));
  145. pIWiaEventCallback = NULL;
  146. }
  147. pIGlobalInterfaceTable->Release();
  148. }
  149. else
  150. {
  151. DBG_ERR(("Could not get a pointer to the Global Interface Table, hr = 0x%08X", hr));
  152. }
  153. return pIWiaEventCallback;
  154. }
  155. /*****************************************************************************
  156. * @doc INTERNAL
  157. *
  158. * @mfunc VOID | ClientEventRegistrationInfo | setToUnregister |
  159. *
  160. * Ensures this registration is set to unregister. This is typically used by
  161. * the <c RegistrationCookie> class, which is created on a WIA event
  162. * regitration. When the cookie is released, that registration must be
  163. * unregistered, so it calls this method to change the registration object to
  164. * the equivalent unregistration object.
  165. *
  166. * This method simply sets <md EventRegistrationInfo::m_dwFlags> = WIA_UNREGISTER_EVENT_CALLBACK.
  167. *
  168. *****************************************************************************/
  169. VOID ClientEventRegistrationInfo::setToUnregister()
  170. {
  171. m_dwFlags = WIA_UNREGISTER_EVENT_CALLBACK;
  172. }