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.

175 lines
4.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1998
  4. *
  5. * TITLE: CallBack.Cpp
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 4 Aug, 1998
  12. *
  13. * DESCRIPTION:
  14. * Implementation of event callbacks for the WIA device class driver.
  15. *
  16. *******************************************************************************/
  17. #include "precomp.h"
  18. #include "stiexe.h"
  19. #include "wiamindr.h"
  20. #include "callback.h"
  21. // Debugging interface, has DLL lifetime. Maintained by USD.
  22. /*******************************************************************************
  23. *
  24. * QueryInterface
  25. * AddRef
  26. * Release
  27. *
  28. * DESCRIPTION:
  29. * CEventCallback IUnknown Interface.
  30. *
  31. * PARAMETERS:
  32. *
  33. *******************************************************************************/
  34. HRESULT _stdcall CEventCallback::QueryInterface(const IID& iid, void** ppv)
  35. {
  36. *ppv = NULL;
  37. if (iid == IID_IUnknown || iid == IID_IWiaEventCallback) {
  38. *ppv = (IWiaEventCallback*) this;
  39. }
  40. else {
  41. return E_NOINTERFACE;
  42. }
  43. AddRef();
  44. return S_OK;
  45. }
  46. ULONG _stdcall CEventCallback::AddRef()
  47. {
  48. InterlockedIncrement((long*) &m_cRef);
  49. return m_cRef;
  50. }
  51. ULONG _stdcall CEventCallback::Release()
  52. {
  53. ULONG ulRefCount = m_cRef - 1;
  54. if (InterlockedDecrement((long*) &m_cRef) == 0) {
  55. delete this;
  56. return 0;
  57. }
  58. return ulRefCount;
  59. }
  60. /*******************************************************************************
  61. *
  62. * CEventCallback
  63. * Initialize
  64. * ~CEventCallback
  65. *
  66. * DESCRIPTION:
  67. * CEventCallback Constructor/Initialize/Destructor Methods.
  68. *
  69. * PARAMETERS:
  70. *
  71. *******************************************************************************/
  72. CEventCallback::CEventCallback()
  73. {
  74. m_cRef = 0;
  75. }
  76. HRESULT _stdcall CEventCallback::Initialize()
  77. {
  78. return S_OK;
  79. }
  80. CEventCallback::~CEventCallback()
  81. {
  82. }
  83. /*******************************************************************************
  84. *
  85. * ImageEventCallback
  86. *
  87. * DESCRIPTION:
  88. * Handles WIA events.
  89. *
  90. * PARAMETERS:
  91. *
  92. *******************************************************************************/
  93. HRESULT _stdcall CEventCallback::ImageEventCallback(
  94. const GUID *pEventGUID,
  95. BSTR bstrEventDescription,
  96. BSTR bstrDeviceID,
  97. BSTR bstrDeviceDescription,
  98. DWORD dwDeviceType,
  99. BSTR bstrFullItemName,
  100. ULONG *plEventType,
  101. ULONG ulReserved)
  102. {
  103. // Update properties in response to WIA events.
  104. return S_OK;
  105. }
  106. /*******************************************************************************
  107. *
  108. * RegisterForWIAEvents
  109. *
  110. * DESCRIPTION:
  111. * Handles WIA events.
  112. *
  113. * PARAMETERS:
  114. *
  115. *******************************************************************************/
  116. HRESULT RegisterForWIAEvents(IWiaEventCallback** ppIWiaEventCallback)
  117. {
  118. DBG_FN(::RegisterForWIAEvents);
  119. HRESULT hr;
  120. IWiaDevMgr *pIWiaDevMgr;
  121. // Get a WIA device manager object.
  122. hr = CoCreateInstance(CLSID_WiaDevMgr,
  123. NULL,
  124. CLSCTX_LOCAL_SERVER,
  125. IID_IWiaDevMgr,
  126. (void**)&pIWiaDevMgr);
  127. if (SUCCEEDED(hr)) {
  128. // Register with WIA event monitor to receive event notification.
  129. CEventCallback* pCEventCB = new CEventCallback();
  130. if (pCEventCB) {
  131. hr = pCEventCB->QueryInterface(IID_IWiaEventCallback,(void **)ppIWiaEventCallback);
  132. if (SUCCEEDED(hr)) {
  133. pCEventCB->Initialize();
  134. // hr = pIWiaDevMgr->RegisterEventCallback(0, NULL, 0, *ppIWiaEventCallback);
  135. }
  136. else {
  137. DBG_ERR(("RegisterForWIAEvents, QI of IID_IWiaEventCallback failed"));
  138. }
  139. }
  140. else {
  141. DBG_ERR(("RegisterForWIAEvents, new CEventCallback failed"));
  142. hr = E_OUTOFMEMORY;
  143. }
  144. pIWiaDevMgr->Release();
  145. }
  146. else {
  147. DBG_ERR(("RegisterForWIAEvents, CoCreateInstance of IID_IWiaDevMgr failed"));
  148. }
  149. return hr;
  150. }