Source code of Windows XP (NT5)
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.

129 lines
2.9 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: WiaEvent.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 2000/11/14
  10. *
  11. * DESCRIPTION: Implements callback for receiving WIA events.
  12. *
  13. *****************************************************************************/
  14. #include <stdafx.h>
  15. #include "wiavideotest.h"
  16. ///////////////////////////////
  17. // Constructor
  18. //
  19. CWiaEvent::CWiaEvent(void) :
  20. m_cRef(0)
  21. {
  22. }
  23. ///////////////////////////////
  24. // Destructor
  25. //
  26. CWiaEvent::~CWiaEvent(void)
  27. {
  28. }
  29. ///////////////////////////////
  30. // QueryInterface
  31. //
  32. STDMETHODIMP CWiaEvent::QueryInterface(REFIID riid,
  33. LPVOID *ppvObject )
  34. {
  35. if (IsEqualIID(riid, IID_IUnknown))
  36. {
  37. *ppvObject = static_cast<IWiaEventCallback*>(this);
  38. }
  39. else if (IsEqualIID(riid, IID_IWiaEventCallback))
  40. {
  41. *ppvObject = static_cast<IWiaEventCallback*>(this);
  42. }
  43. else
  44. {
  45. *ppvObject = NULL;
  46. return E_NOINTERFACE;
  47. }
  48. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  49. return S_OK;
  50. }
  51. ///////////////////////////////
  52. // AddRef
  53. //
  54. STDMETHODIMP_(ULONG) CWiaEvent::AddRef(void)
  55. {
  56. return InterlockedIncrement(&m_cRef);
  57. }
  58. ///////////////////////////////
  59. // Release
  60. //
  61. STDMETHODIMP_(ULONG) CWiaEvent::Release(void)
  62. {
  63. LONG nRefCount = InterlockedDecrement(&m_cRef);
  64. if (!nRefCount)
  65. {
  66. delete this;
  67. }
  68. return nRefCount;
  69. }
  70. ///////////////////////////////
  71. // ImageEventCallback
  72. //
  73. STDMETHODIMP CWiaEvent::ImageEventCallback(const GUID *pEventGUID,
  74. BSTR bstrEventDescription,
  75. BSTR bstrDeviceID,
  76. BSTR bstrDeviceDescription,
  77. DWORD dwDeviceType,
  78. BSTR bstrFullItemName,
  79. ULONG *pulEventType,
  80. ULONG ulReserved)
  81. {
  82. HRESULT hr = S_OK;
  83. if (pEventGUID == NULL)
  84. {
  85. return E_POINTER;
  86. }
  87. if (IsEqualIID(*pEventGUID, WIA_EVENT_ITEM_CREATED))
  88. {
  89. hr = ImageLst_PostAddImageRequest(bstrFullItemName);
  90. }
  91. else if (IsEqualIID(*pEventGUID, WIA_EVENT_ITEM_DELETED))
  92. {
  93. // do nothing for now.
  94. }
  95. else if (IsEqualIID(*pEventGUID, WIA_EVENT_DEVICE_CONNECTED))
  96. {
  97. WiaProc_PopulateDeviceList();
  98. }
  99. else if (IsEqualIID(*pEventGUID, WIA_EVENT_DEVICE_DISCONNECTED))
  100. {
  101. //
  102. // Simulate a push of the DestroyVideo Button.
  103. //
  104. VideoProc_ProcessMsg(IDC_BUTTON_DESTROY_VIDEO);
  105. AppUtil_MsgBox(IDS_DISCONNECTED, IDS_VIDEO_STREAM_SHUTDOWN,
  106. MB_OK | MB_ICONINFORMATION);
  107. WiaProc_PopulateDeviceList();
  108. }
  109. return S_OK;
  110. }