Méthode IWMDMStorage3 ::GetMetadata (mswmdm.h)

La méthode GetMetadata récupère les métadonnées associées au stockage.

Syntaxe

HRESULT GetMetadata(
  [out] IWMDMMetaData **ppMetadata
);

Paramètres

[out] ppMetadata

Pointeur vers un pointeur IWMDMMetaData associé à un stockage. L’appelant est responsable de l’appel de Release sur cette interface et sur toutes les valeurs allouées lorsqu’elle a terminé, comme décrit sous « Effacement de la mémoire allouée » dans Découverte des fonctionnalités de format d’appareil.

Valeur retournée

Cette méthode retourne un code HRESULT. Toutes les méthodes d’interface dans Windows Media Gestionnaire de périphériques peuvent retourner l’une des classes de codes d’erreur suivantes :

  • Codes d’erreur COM standard
  • Codes d’erreur Windows convertis en valeurs HRESULT
  • Codes d’erreur Gestionnaire de périphériques Windows Media
Pour obtenir une liste complète des codes d’erreur possibles, consultez Codes d’erreur.

Remarques

Cette méthode récupère toutes les métadonnées associées au stockage. Si une application recherche des métadonnées spécifiques, il peut être plus efficace d’appeler IWMDMStorage4 ::GetSpecifiedMetadata.

Lors de la récupération de données à partir d’un appareil Windows Portable Devices (WPD), les données sont retournées sous forme binaire. L’application doit dé sérialiser ces données pour obtenir les valeurs de propriété réelles.

Exemples

La fonction C++ suivante récupère toutes les métadonnées associées à un stockage.


// 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;
}

Configuration requise

Condition requise Valeur
Plateforme cible Windows
En-tête mswmdm.h
Bibliothèque Mssachlp.lib

Voir aussi

IWMDMMetaData Interface

IWMDMStorage3 Interface

IWMDMStorage3 ::SetMetadata

IWMDMStorage4 ::GetSpecifiedMetadata