Microsoft DirectX 8.1 (C++)

Enumerating a MetaPropertyTypes Collection (C++)

This topic applies to Windows XP Home Edition and Windows XP Professional only.

The following code example illustrates the process of enumerating a DirectShow MetaPropertyTypes collection. One sample-defined function, EnumMetaPropertyTypes, enumerates the MetaPropertyTypes collection and calls the second sample-defined function, ShowMetaPropertyType, for each enumerated MetaPropertyType object. The ShowMetaPropertyType function displays some information about the MetaPropertyType object.

// Enumerate the entire collection of a MetaPropertyTypes object.
HRESULT ::EnumMetaPropertyTypes(IMetaPropertyTypes* pPropTypes)
{
    HRESULT hr = 0;

    // Retrieve the number of objects in the collection.
    long lNumObjects = 0;

    hr = pPropTypes->get_Count(&lNumObjects);

    // Show each object.
    long i = 0;
    IMetaPropertyType* pPropType = 0;

    VARIANT index;
    VariantInit(&index);
    index.vt = VT_I4;

    // Enumerate the collection.
    while (i < lNumObjects)
    {
        index.lVal = i;
        pPropTypes->get_Item(index, &pPropType);
        hr = ShowMetaPropertyType(pPropType);
        i++;
    }

    VariantClear(&index);
    return hr;
}

// Displays a MetaPropertyType object.
HRESULT ::ShowMetaPropertyType(IMetaPropertyType* pPropType)
{
    // Get the ID.
    long id;
    pPropType->get_ID(&id);

    // Get the name.
    BSTR name = 0;
    pPropType->get_Name(&name);

    // Convert from BSTR to char for display.
    UINT length = SysStringLen(name);
    char* DisplayName = new char[length + 1];
    length = wcstombs(DisplayName, name, length);
    DisplayName[length] = '\0';

    cout << "ID: " << id << "  " << DisplayName << endl;

    SysFreeString(name);
    delete DisplayName;
    return S_OK;
}