ISensorDriver::OnGetDataFields method

The ISensorDriver::OnGetDataFields method retrieves current sensor data.

Syntax


HRESULT OnGetDataFields(
  [in]   IWDFFile *pClientFile,
  [in]   LPWSTR pwszSensorID,
  [in]   IPortableDeviceKeyCollection *pDataFields,
  [out]  IPortableDeviceValues **ppDataValues
);

Parameters

pClientFile [in]

Pointer to an IWDFFile interface that represents the file object for the application requesting the data.

pwszSensorID [in]

LPWSTR that contains the ID for the sensor from which the client application is requesting data.

pDataFields [in]

Pointer to an IPortableDeviceKeyCollection that contains the list of PROPERTYKEY values that represent the data fields being requested.

ppDataValues [out]

Address of an IPortableDeviceValues pointer that receives the requested data.

Return value

This method returns an HRESULT. Possible values include, but are not limited to, one of the following values.

Return codeDescription
S_OK

The method succeeded.

HRESULT_FROM_WIN32(ERROR_NO_DATA)

The sensor has no data to report. Each of the data fields returned in the ppDataValues parameter is VT_EMPTY.

 

Remarks

Data fields contain sensor-generated data, as opposed to properties, which describe the sensor device. Platform-defined data fields are defined in sensors.h.

Each IPortableDeviceValues object returned by this method must contain a time stamp, as described in SENSOR_CATEGORY_ALL.

The sensor class extension is responsibile for freeing any PROPVARIANT structures returned by this method.

The sensor class extension calls this method only for sensors for which the user has granted permission through Control Panel.

IPortableDeviceKeyCollection and IPortableDeviceValues are documented in Windows Portable Devices.

Examples

The following example code returns data field values for a temperature sensor. The variable named m_pTemperatureSensorDataFieldValues points to an instance of IPortableDeviceValues that contains the current data field values for the sensor.


HRESULT CSensorDDI:: OnGetDataFields(
        __in  IWDFFile* pClientFile,
        __in  LPWSTR pwszObjectID,
        __in  IPortableDeviceKeyCollection* pKeys,
        __out IPortableDeviceValues** ppValues
        )
{
    UNREFERENCED_PARAMETER(pClientFile);

    HRESULT hr = ((NULL == pwszObjectID) || (NULL == pKeys) || 
                              (NULL == ppValues)) ? E_INVALIDARG : S_OK;

    if ( SUCCEEDED(hr) )
    {
        CComPtr<IPortableDeviceValues> spValues;
        hr = spValues.CoCreateInstance(CLSID_PortableDeviceValues);

        if ( SUCCEEDED(hr) )
        {
            CString strObjectID = pwszObjectID;
            if (0 == strObjectID.CompareNoCase(SENSOR_TEMPERATURE_ID))
            {
                DWORD cKeys = 0;
                hr = pKeys->GetCount(&cKeys);

                for (DWORD dwIndex = 0; SUCCEEDED(hr) && dwIndex < cKeys; dwIndex++)
                {
                    PROPERTYKEY Key = WPD_PROPERTY_NULL;
                    if ( (S_OK == pKeys->GetAt(dwIndex, &Key)) &&
                          !IsEqualPropertyKey(Key, WPD_PROPERTY_NULL) )
                    {
                        PROPVARIANT value;
                        PropVariantInit(&value);

                        hr = (NULL == m_pTemperatureSensorDataFieldValues) ? E_UNEXPECTED : S_OK;
                        if (SUCCEEDED(hr))
                        {
                            // Preset the property value to 'error not supported'.  The actual value
                            // will replace this value, if read from the device.
                            spValues->SetErrorValue(Key,
                                            HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED));
 
                            if ( SUCCEEDED(m_pTemperatureSensorDataFieldValues->GetValue(Key, &value)) )
                            {
                                spValues->SetValue(Key, &value);
                            }
                        }

                        PropVariantClear(&value);
                    }
                }
            }
            else
            {
                hr = E_UNEXPECTED;
            }

            // Copy over the IPortableDeviceValues
            *ppValues = spValues.Detach();
        }
    }
}

Requirements

Minimum supported client

Windows 7

Minimum supported server

None supported

Version

Available in Windows 7.

Header

Sensorsclassextension.h

Library

SensorsClassExtension.lib

See also

Constants
ISensorDriver::OnGetSupportedDataFields

 

 

Send comments about this topic to Microsoft

顯示:
© 2014 Microsoft