Share via


IWMDMMetaData::QueryByIndex

banner art

The QueryByIndex method retrieves the value of a property specified by index.

Syntax

HRESULT QueryByIndex(UINTiIndex,WCHAR**ppwszName,WMDM_TAG_DATATYPE*pType,BYTE**ppValue,UINT*pcbLength);

Parameters

iIndex

[in]  Integer specifying the zero-based index of the property. The number of items is obtained through the GetItemCount call.

ppwszName

[out]  Name of the property. Windows Media Device Manager allocates this memory, and the caller must free it using CoTaskMemFree.

pType

[out]  An WMDM_TAG_DATATYPE enumerated value describing the type of data returned in ppValue.

ppValue

[out]  Pointer to a pointer to a byte array that receives the content of the value if the method succeeds. This memory is allocated by Windows Media Device Manager, and the caller must free it using CoTaskMemFree.

pcbLength

[out]  Pointer to the size, in bytes, of the byte array ppValue. If the value is a string, this includes the termination character.

Return Values

The method returns an HRESULT. All the interface methods in Windows Media Device Manager can return any of the following classes of error codes:

  • Standard COM error codes
  • Windows error codes converted to HRESULT values
  • Windows Media Device Manager error codes

For an extenstive list of possible error codes, see Error Codes.

Possible values include, but are not limited to, those in the following table.

Value Description
S_OK The method succeeded.
E_OUTOFMEMORY There is not enough memory to allocate the item.
E_INVALIDARG One or more parameters are invalid.

Example Code

The following code retrieves the count of properties in an IWMDMMetaData interface (pMetadata) and tries to retrieve them all by index and print them.

        //
        // Loop through all metadata properties, and print out the value of each.
        //
        BYTE* value;
        WMDM_TAG_DATATYPE type;
        UINT len = 0;
        UINT count = 0;
        WCHAR* name;
        // Get the number of metadata items.
        hr = pMetadata->GetItemCount(&count);

        BREAK_HR(hr, "Got a metadata count in GetMetadata.", "Couldn't get a metadata count in GetMetadata.");
        for(;count > 0; count--)
        {
            // Get the metadata property by index.
            WCHAR* name;
            hr = pMetadata->QueryByIndex(count-1, &name, &type, &value, &len);
            if (SUCCEEDED(hr))
            {
                // TODO: Display the property name.
                CoTaskMemFree(name);

                // Print out the value of the property, according to the value type.
                switch (type)
                {
                case WMDM_TYPE_QWORD:
                case WMDM_TYPE_DWORD:
                case WMDM_TYPE_WORD:
                    // TODO: Display the value.
                    break;
                case WMDM_TYPE_STRING:
                    // TODO: Display the value.
                    break;
                case WMDM_TYPE_BOOL:
                    // TODO: Display the value.
                    break;
                case WMDM_TYPE_BINARY:
                    // TODO: Display the value.
                    break;
                case WMDM_TYPE_DATE:
                    {
                        WMDMDATETIME *val = (WMDMDATETIME*)value;
                        // Display the month, day, and year.
                    }
                    break;
                case WMDM_TYPE_GUID:
                    {
                        WCHAR strGuid[64];
                        StringFromGUID2(reinterpret_cast<GUID&>(value),(LPOLESTR)strGuid, 64);
                        // TODO: Display the GUID
                    }
                    break;
                default:
                    // TODO: Display a message indicating that the app could not understand the returned value type.
                }
            }
            else // Couldn't get the metadata property at index count - 1.
                // TODO: Display a message indicating that the application couldn't get a value for index in GetMetadata
        // Clear the WMDM-allocated memory.
        if (value)
            CoTaskMemFree(value);
        }

Requirements

Header: Defined in mswmdm.h.

Library: mssachlp.lib

See Also