ISensorDriver::OnGetSupportedProperties method

The ISensorDriver::OnGetSupportedProperties method retrieves the list of properties that the specified sensor provides.

Syntax


HRESULT OnGetSupportedProperties(
  [in]   LPWSTR pwszSensorID,
  [out]  IPortableDeviceKeyCollection **ppSupportedProperties
);

Parameters

pwszSensorID [in]

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

ppSupportedProperties [out]

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

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

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

Each IPortableDeviceKeyCollection object returned in this collection must contain PROPERTYKEYs for the required properties, as described in the Sensor Properties reference section.

IPortableDeviceKeyCollection is documented in Windows Portable Devices.

Examples

The following example code shows structures that list supported properties.


// Properties common to all sensors.
const PROPERTYKEY g_SupportedCommonProperties[] =
{
    WPD_OBJECT_ID,
    WPD_OBJECT_PERSISTENT_UNIQUE_ID,
    WPD_OBJECT_PARENT_ID,
    WPD_OBJECT_NAME,
    WPD_OBJECT_FORMAT,
    WPD_OBJECT_CONTENT_TYPE,
    WPD_OBJECT_CAN_DELETE,
    WPD_FUNCTIONAL_OBJECT_CATEGORY
};

// Properties supported by all devices.
const PROPERTYKEY g_SupportedDeviceProperties[] =
{
    WPD_DEVICE_FIRMWARE_VERSION,
    WPD_DEVICE_POWER_LEVEL,
    WPD_DEVICE_POWER_SOURCE,
    WPD_DEVICE_PROTOCOL,
    WPD_DEVICE_MODEL,
    WPD_DEVICE_SERIAL_NUMBER,
    WPD_DEVICE_SUPPORTS_NON_CONSUMABLE,
    WPD_DEVICE_MANUFACTURER,
    WPD_DEVICE_FRIENDLY_NAME,
    WPD_DEVICE_TYPE
};

// Properties supported by the sensor.
const PROPERTYKEY g_SupportedSensorProperties[] =
{
    SENSOR_PROPERTY_TYPE,
    SENSOR_PROPERTY_STATE,
    SENSOR_PROPERTY_MIN_REPORT_INTERVAL,
    SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL,
    SENSOR_PROPERTY_PERSISTENT_UNIQUE_ID,
    SENSOR_PROPERTY_MANUFACTURER,
    SENSOR_PROPERTY_MODEL,
    SENSOR_PROPERTY_SERIAL_NUMBER,
    SENSOR_PROPERTY_FRIENDLY_NAME,
    SENSOR_PROPERTY_DESCRIPTION,
    SENSOR_PROPERTY_CONNECTION_TYPE    
};

The following example code shows how to return the lists of supported properties.


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

    HRESULT hr = S_OK;

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

    if(SUCCEEDED(hr))
    {
        // Add the common properties.
        for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonProperties); dwIndex++)
        {
            spKeys->Add(g_SupportedCommonProperties[dwIndex]);
        }

        if(wcsncmp(SensorID, WPD_DEVICE_OBJECT_ID, wcsnlen(SensorID, g_iMaxStrLen)) == 0)
        {
            // Add the supported device properties.
            for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedDeviceProperties); dwIndex++)
            {
               spKeys->Add(g_SupportedDeviceProperties[dwIndex]);
            }
        }
        else if (wcsncmp(SensorID, g_wszSensorID, wcsnlen(SensorID, g_iMaxStrLen)) == 0)
        {
             // Add the supported sensor properties.
            for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedSensorProperties); dwIndex++)
            {
                spKeys->Add(g_SupportedSensorProperties[dwIndex]);
            }
        }
    }

    if(SUCCEEDED(hr))
    {
        // Copy the property keys.
        *ppKeys = spKeys.Detach();
    }

    return hr;
}

Requirements

Minimum supported client

Windows 7

Minimum supported server

None supported

Version

Available in Windows 7.

Header

Sensorsclassextension.h

Library

SensorsClassExtension.lib

See also

ISensorDriver::OnGetProperties
Sensor Properties

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft