IWMDMMetaData::GetItemCount 方法 (mswmdm.h)
GetItemCount 方法检索接口保留的属性总数。
语法
HRESULT GetItemCount(
[out] UINT *iCount
);
参数
[out] iCount
指向一个整数的指针,该整数接收接口存储的元数据属性的总数。
返回值
该方法返回 HRESULT。 Windows Media 设备管理器 中的所有接口方法都可以返回以下任一类错误代码:
- 标准 COM 错误代码
- 转换为 HRESULT 值的 Windows 错误代码
- Windows Media 设备管理器错误代码
注解
此方法可与 QueryByIndex 一起使用,以枚举存储或设备上的所有属性。
示例
以下代码检索 IWMDMMetaData 接口中的属性计数 (pMetadata) ,并尝试通过索引检索这些属性并打印它们。 它使用自定义错误处理宏BREAK_HR。
//
// 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.
// Release the method-allocated property value memory.
if (SUCCEEDED(hr))
CoTaskMemFree(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;
/ /TODO: 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
// application 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 retrieve a value for the index.
// Clear the WMDM-allocated memory.
if (value)
CoTaskMemFree(value);
}
要求
要求 | 值 |
---|---|
目标平台 | Windows |
标头 | mswmdm.h |
Library | Mssachlp.lib |