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.

236 lines
4.9 KiB

  1. //EventCallBack.cpp
  2. #include "stdafx.h"
  3. #include "wiatest.h"
  4. #include "eventcallback.h"
  5. #include "mainfrm.h"
  6. #include "WIATestView.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CEventCallback message handlers
  9. /**************************************************************************\
  10. * CEventCallback::QueryInterface()
  11. *
  12. * QI for IWiaEventCallback Interface
  13. *
  14. *
  15. * Arguments:
  16. *
  17. * iid - Interface ID
  18. * ppv - Callback Interface pointer
  19. *
  20. * Return Value:
  21. *
  22. * none
  23. *
  24. * History:
  25. *
  26. * 2/14/1999 Original Version
  27. *
  28. \**************************************************************************/
  29. HRESULT _stdcall CEventCallback::QueryInterface(const IID& iid, void** ppv)
  30. {
  31. *ppv = NULL;
  32. if (iid == IID_IUnknown || iid == IID_IWiaEventCallback)
  33. *ppv = (IWiaEventCallback*) this;
  34. else
  35. return E_NOINTERFACE;
  36. AddRef();
  37. return S_OK;
  38. }
  39. /**************************************************************************\
  40. * CEventCallback::AddRef()
  41. *
  42. * Increment the Ref count
  43. *
  44. *
  45. * Arguments:
  46. *
  47. * none
  48. *
  49. * Return Value:
  50. *
  51. * ULONG - current ref count
  52. *
  53. * History:
  54. *
  55. * 2/14/1999 Original Version
  56. *
  57. \**************************************************************************/
  58. ULONG _stdcall CEventCallback::AddRef()
  59. {
  60. InterlockedIncrement((long*)&m_cRef);
  61. return m_cRef;
  62. }
  63. /**************************************************************************\
  64. * CEventCallback::Release()
  65. *
  66. * Release the callback Interface
  67. *
  68. *
  69. * Arguments:
  70. *
  71. * none
  72. *
  73. * Return Value:
  74. *
  75. * ULONG - Current Ref count
  76. *
  77. * History:
  78. *
  79. * 2/14/1999 Original Version
  80. *
  81. \**************************************************************************/
  82. ULONG _stdcall CEventCallback::Release()
  83. {
  84. ULONG ulRefCount = m_cRef - 1;
  85. if (InterlockedDecrement((long*) &m_cRef) == 0)
  86. {
  87. delete this;
  88. return 0;
  89. }
  90. return ulRefCount;
  91. }
  92. /**************************************************************************\
  93. * CEventCallback::CEventCallback()
  94. *
  95. * Constructor for callback class
  96. *
  97. *
  98. * Arguments:
  99. *
  100. * none
  101. *
  102. * Return Value:
  103. *
  104. * none
  105. *
  106. * History:
  107. *
  108. * 2/14/1999 Original Version
  109. *
  110. \**************************************************************************/
  111. CEventCallback::CEventCallback()
  112. {
  113. m_cRef = 0;
  114. m_pIUnkRelease = NULL;
  115. }
  116. /**************************************************************************\
  117. * CEventCallback::~CEventCallback()
  118. *
  119. * Destructor for Callback class
  120. *
  121. *
  122. * Arguments:
  123. *
  124. * none
  125. *
  126. * Return Value:
  127. *
  128. * none
  129. *
  130. * History:
  131. *
  132. * 2/14/1999 Original Version
  133. *
  134. \**************************************************************************/
  135. CEventCallback::~CEventCallback()
  136. {
  137. }
  138. /**************************************************************************\
  139. * CEventCallback::Initialize()
  140. *
  141. * Initializes Callback event type
  142. *
  143. *
  144. * Arguments:
  145. *
  146. * none
  147. *
  148. * Return Value:
  149. *
  150. * none
  151. *
  152. * History:
  153. *
  154. * 2/14/1999 Original Version
  155. *
  156. \**************************************************************************/
  157. HRESULT _stdcall CEventCallback::Initialize(int EventID)
  158. {
  159. if((EventID > 1)||(EventID < 0))
  160. return S_FALSE;
  161. m_EventID = EventID;
  162. return S_OK;
  163. }
  164. /**************************************************************************\
  165. * CEventCallback::ImageEventCallback()
  166. *
  167. * Handles the event trapping
  168. *
  169. *
  170. * Arguments:
  171. *
  172. * lReason - not used
  173. * lStatus - not used
  174. * lPercentComplete - not used
  175. * pEventGUID - not used
  176. * bstrDeviceID - not used
  177. * lReserved - not used
  178. *
  179. * Return Value:
  180. *
  181. * status
  182. *
  183. * History:
  184. *
  185. * 2/14/1999 Original Version
  186. *
  187. \**************************************************************************/
  188. HRESULT _stdcall CEventCallback::ImageEventCallback(
  189. const GUID *pEventGUID,
  190. BSTR bstrEventDescription,
  191. BSTR bstrDeviceID,
  192. BSTR bstrDeviceDescription,
  193. DWORD dwDeviceType,
  194. BSTR bstrFullItemName,
  195. ULONG *plEventType,
  196. ULONG ulReserved)
  197. {
  198. CWIATestApp* pApp = (CWIATestApp*)AfxGetApp();
  199. CMainFrame* pFrame = (CMainFrame*)pApp->GetMainWnd();
  200. CWIATestView* pView = (CWIATestView*)pFrame->GetActiveView();
  201. switch(m_EventID)
  202. {
  203. case ID_WIAEVENT_CONNECT:
  204. MessageBox(NULL,"a connect event has been trapped...","WIATest Event Notice",MB_OK);
  205. if(pView != NULL)
  206. {
  207. pView->RefreshDeviceList();
  208. pView->EnumerateWIADevices();
  209. pView->UpdateUI();
  210. }
  211. break;
  212. case ID_WIAEVENT_DISCONNECT:
  213. MessageBox(NULL,"a disconnect event has been trapped...","WIATest Event Notice",MB_OK);
  214. if(pView != NULL)
  215. {
  216. pView->RefreshDeviceList();
  217. pView->EnumerateWIADevices();
  218. pView->UpdateUI();
  219. }
  220. break;
  221. default:
  222. AfxMessageBox("Ah HA!..an event just happened!!!!\n and...I have no clue what is was..");
  223. break;
  224. }
  225. return S_OK;
  226. }