ISensorDriver::OnGetSupportedDataFields method

The ISensorDriver::OnGetSupportedDataFields method retrieves the list of data fields that the specified sensor can provide.

Syntax


HRESULT OnGetSupportedDataFields(
  [in]   LPWSTR                       pwszSensorID,
  [out]  IPortableDeviceKeyCollection **ppSupportedDataFields
);

Parameters

pwszSensorID [in]

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

ppSupportedDataFields [out]

Address of an IPortableDeviceKeyCollection pointer that receives the list of PROPERTYKEY values that represent the supported data fields.

Return value

If the operation succeeds, this method returns S_OK. Otherwise, this method returns one of the error codes that are defined in Winerror.h.

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.

All drivers must support SENSOR_DATA_TYPE_TIMESTAMP as a required data field.

IPortableDeviceKeyCollection is documented in Windows Portable Devices.

Examples

The following example code demonstrates how to return the list of supported data fields.


// Data fields supported by the time sensor.
const PROPERTYKEY g_SupportedDataFields[] =
{
    SAMPLE_SENSOR_DATA_TYPE_HOUR,
    SAMPLE_SENSOR_DATA_TYPE_MINUTE,
    SAMPLE_SENSOR_DATA_TYPE_SECOND,
    SENSOR_DATA_TYPE_TIMESTAMP 
};

HRESULT CSensorDdi:: OnGetSupportedDataFields(
        __in  LPWSTR SensorID,
        __out IPortableDeviceKeyCollection** ppKeys
        )
{
    if(NULL == ppKeys || 
       NULL == SensorID)
    {
        return E_POINTER;
    }

    HRESULT hr = S_OK;

    // This method is called by the class extension and
    // the event thread. We need a critical section to 
    // serialize access, here.
    Lock();

    CComPtr<IPortableDeviceKeyCollection> spKeys;
    hr = spKeys.CoCreateInstance(CLSID_PortableDeviceKeyCollection);

    if(SUCCEEDED(hr))
    {
        // Add the supported data fields to the collection.
        for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedDataFields); dwIndex++)
        {
            spKeys->Add(g_SupportedDataFields[dwIndex] );
        }
    }

    if(SUCCEEDED(hr))
    {
        *ppKeys = spKeys.Detach();
    }

    Unlock();

    return hr;
}

Requirements

Minimum supported client

Windows 7

Minimum supported server

None supported

Target platform

Desktop

Version

Available in Windows 7.

Header

Sensorsclassextension.h

Library

SensorsClassExtension.lib

See also

Constants
ISensorDriver::OnGetDataFields

 

 

Send comments about this topic to Microsoft

Show:
© 2015 Microsoft