Hardware Dev Center

ISensorDriver::OnGetProperties method

The ISensorDriver::OnGetProperties method retrieves values for the specified properties from the specified sensor.

Syntax


HRESULT OnGetProperties(
  [in]  IWDFFile                     *pClientFile,
        __in_string LPWSTR           pwszSensorID,
  [in]  IPortableDeviceKeyCollection *pProperties,
  [out] IPortableDeviceValues        **ppPropertyValues
);

Parameters

pClientFile [in]

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

pwszSensorID

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

pProperties [in]

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

ppPropertyValues [out]

Address of an IPortableDeviceValues pointer that receives the requested property values.

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.

Applications can access some sensor property information before the user grants permission for the sensor. These items are limited to the following IDs defined in sensors.h:

  • Any PROPERTYKEY that starts with "SENSOR_PROPERTY_".

  • Any category GUID that starts with "SENSOR_CATEGORY_".

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

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

Sensor properties must not contain information that can be used to identify the user. For more information about user privacy, see Privacy and Security in the Sensor and Location Platform.

IPortableDeviceKeyCollection and IPortableDeviceValues are documented in Windows Portable Devices.

Examples

The following example code retrieves the properties for a temperature sensor. The variable named m_pTemperatureSensorPropertyValues is a pointer to an instance of IPortableDeviceValues that contains the property values for the sensor.


HRESULT CSensorDDI:: OnGetProperties(
        __in  IWDFFile* pClientFile,
        __in  LPWSTR pwszObjectID,
        __in  IPortableDeviceKeyCollection* pKeys,
        __out IPortableDeviceValues** ppValues
        )
{   
    UNREFERENCED_PARAMETER(pClientFile);
    BOOL fError = FALSE;

    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_pTemperatureSensorPropertyValues) ? E_UNEXPECTED : S_OK;
                        if (SUCCEEDED(hr))
                        {
                            HRESULT hrTemp = m_pTemperatureSensorPropertyValues->GetValue(Key, &value);
 
                            if (SUCCEEDED(hrTemp))
                            {
                                spValues->SetValue(Key, &value);
                            }
                            else
                            {
                                // Failed to find the requested property, convey the hr back to the caller
                                spValues->SetErrorValue(Key, hrTemp);
                                fError = TRUE;
                            }
                        }

                        PropVariantClear(&value);
                    }
                } // end of for loop
             }
             else
             {
                  hr = E_UNEXPECTED;
             }

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

    return (FALSE == fError) ? hr : S_FALSE;
}

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

ISensorDriver::OnGetSupportedProperties
Sensor Properties

 

 

Send comments about this topic to Microsoft

Show:
© 2015 Microsoft