#ifndef __SENSOR_EVENT_H #define __SENSOR_EVENT_H #pragma once #include "stdafx.h" #include #include #include class CMyEvents : public ISensorEvents { public: STDMETHODIMP QueryInterface(REFIID iid, void** ppv) { if (ppv == NULL) { return E_POINTER; } if (iid == __uuidof(IUnknown)) { *ppv = static_cast(this); } else if (iid == __uuidof(ISensorEvents)) { *ppv = static_cast(this); } else { *ppv = NULL; return E_NOINTERFACE; } AddRef(); m_count = 0; return S_OK; } STDMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&m_cRef); } STDMETHODIMP_(ULONG) Release() { ULONG count = InterlockedDecrement(&m_cRef); if (count == 0) { delete this; return 0; } return count; } // // ISensorEvents methods. // STDMETHODIMP OnEvent( ISensor *pSensor, REFGUID eventID, IPortableDeviceValues *pEventData) { HRESULT hr = S_OK; // Handle custom events here. return hr; } STDMETHODIMP OnLeave( REFSENSOR_ID sensorID) { HRESULT hr = S_OK; // Peform any housekeeping tasks for the sensor that is leaving. // For example, if you have maintained a reference to the sensor, // release it now and set the pointer to NULL. return hr; } STDMETHODIMP OnDataUpdated(ISensor *pSensor,ISensorDataReport *pNewData); STDMETHODIMP OnStateChanged( ISensor* pSensor, SensorState state) { HRESULT hr = S_OK; if(NULL == pSensor) { return E_INVALIDARG; } if(state == SENSOR_STATE_READY) { wprintf_s(L"\nTime sensor is now ready."); } else if(state == SENSOR_STATE_ACCESS_DENIED) { wprintf_s(L"\nNo permission for the time sensor.\n"); wprintf_s(L"Enable the sensor in the control panel.\n"); } return hr; } private: long m_cRef; int m_count; }; #endif //__SENSOR_EVENT_H