Retrieving Vector Types

Some properties and data fields contain arrays of information. For example, the SENSOR_PROPERTY_LIGHT_RESPONSE_CURVE property contains an array of 4-byte unsigned integers. However, when you receive such arrays through the Sensor API, they are always represented as type VT_VECTOR|UI1, an array of single-byte characters, regardless of the actual type of the data in the array. For these types, you must be careful to cast array variables to the correct data type for the property or data field.

For information about properties, data fields, and their types, see Constants.

The following example code shows how to cast the data retrieved in SENSOR_PROPERTY_LIGHT_RESPONSE_CURVE to the correct type.

PROPVARIANT pvCurve;
PropVariantInit(&pvCurve);

// Retrieve the property value.
hr = pSensor->GetProperty(SENSOR_PROPERTY_LIGHT_RESPONSE_CURVE, &pvCurve);
if (SUCCEEDED(hr))
{
    if ((VT_UI1|VT_VECTOR) == V_VT(pvCurve)) // Note actual type of UI1
    {
        // Cast the array to UINT, a 4-byte unsigned integer.

        // Item count for the array.
        UINT  cElement = pvCurve.caub.cElems/sizeof(UINT);
        // Array pointer.
        UINT* pElement = (UINT*)(pvCurve.caub.pElems);

        // Use the array.
    }
}

// Remember to free the PROPVARIANT when done.
PropVariantClear(&pvCurve);