Partilhar via


The source of property types

I mentioned that one of the property system layers coerces values to be of the correct type. But how does the system know the expected type?

The property system maintains a data structure describing each property on the machine. Each property description contains information such as the key, the canonical name, the type, and the label for the property. A collection of property descriptions is called a property schema

By dealing with properties abstractly, applications can create and register new properties and have them seamlessly work with existing properties. The schema is also what drives the coercion layer. Finally, I personally think it's incredibly neat to have this meta-metadata available programmatically.

Here's a quick example of how to retrieve a type and label for a property:

IPropertyDescription *ppropdesc;
HRESULT hr = PSGetPropertyDescription(PKEY_Size, IID_PPV_ARGS(&ppropdesc));
if (SUCCEEDED(hr))
{
VARTYPE vt;
hr = ppropdesc->GetPropertyType(&vt);
...
PWSTR pszLabel;
hr = ppropdesc->GetDisplayName(&pszLabel);
if (SUCCEEDED(hr))
{
...
CoTaskMemFree(pszLabel);
}
ppropdesc->Release();
}

To close, I just wanted to mention that PSGetPropertyDescription and related APIs are very fast. Once the property system has initialized, obtaining the IPropertyDescription interface usually requires zero allocations and is very light weight.

Comments

  • Anonymous
    September 14, 2006
    Values in the property system are stored in PROPVARIANT structures.  Originally constructed for...