iWMDMStorage3::GetMetadata 方法 (mswmdm.h)
GetMetadata 方法會擷取與記憶體相關聯的元數據。
語法
HRESULT GetMetadata(
[out] IWMDMMetaData **ppMetadata
);
參數
[out] ppMetadata
與記憶體相關聯的 IWMDMMetaData 指標指標指標指標。 呼叫端負責在此介面上呼叫 Release ,並在完成時呼叫所有已配置的值,如 探索裝置格式功能中的「清除已配置的記憶體」所述。
傳回值
方法會傳回 HRESULT。 Windows Media 中的所有介面方法 裝置管理員 可以傳回下列任何錯誤碼類別:
- 標準 COM 錯誤碼
- 轉換成 HRESULT 值的 Windows 錯誤碼
- Windows Media 裝置管理員 錯誤碼
備註
這個方法會擷取與記憶體相關聯的所有元數據。 如果應用程式正在搜尋特定的元數據,呼叫 IWMDMStorage4::GetSpecifiedMetadata 可能會更有效率。
從 Windows 可攜式裝置 (WPD) 裝置擷取數據時,數據會以二進位格式傳回。 應用程式應該取消串行化此數據,以取得實際的屬性值。
範例
下列 C++ 函式會擷取與記憶體相關聯的所有元數據。
// Function to print out all the metadata associated with a storage.
HRESULT CWMDMController::GetMetadata(IWMDMStorage *pStorage)
{
HRESULT hr = S_OK;
// A dummy loop to handle unrecoverable errors. When we hit an error we
// can't handle or don't like, we just use a 'break' statement.
// The custom BREAK_HR macro checks for failed HRESULT values and does this.
do
{
CComPtr<IWMDMStorage3> pStorage3;
CComPtr<IWMDMMetaData> pMetadata;
hr = pStorage->QueryInterface(__uuidof(IWMDMStorage3), (void**)&pStorage3);
BREAK_HR(hr, "Got an IWMDMStorage3 interface in GetMetadata.", "Couldn't get an IWMDMStorage3 interface in GetMetadata.");
hr = pStorage3->GetMetadata(&pMetadata);
BREAK_HR(hr, "Got an IWMDMMetaData interface in GetMetadata.", "Couldn't get an IWMDMMetaData interface in GetMetadata.");
//
// 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 value.
}
break;
default:
// TODO: Display the message: "Could not understand the returned value type
}
}
else // Couldn't get the metadata property at index count - 1.
// TODO: Display the message:
// "Couldn't get a value for index "
// followed by the current index value.
}
// Now get a specific property by name.
// If this property isn't supported, the method returns E_INVALIDARG.
hr = pMetadata->QueryByName(g_wszWMDMFileName, &type, &value, &len);
if (hr == S_OK)
{
wstring wstr((wchar_t*)value, len / 2); // Create a string from the name.
// TODO: Display the file name.
CoTaskMemFree(value);
}
// See if file is DRM-protected.
hr = pMetadata->QueryByName(g_wszWMDMIsProtected, &type, &value, &len);
if (hr == S_OK)
{
// TODO: Display a message that the object is DRM protected.
}
}while(FALSE);// End of dummy loop.
// Clean up and return.
return hr;
}
規格需求
需求 | 值 |
---|---|
目標平台 | Windows |
標頭 | mswmdm.h |
程式庫 | Mssachlp.lib |