Recupero di proprietà per un singolo oggetto
Dopo che l'applicazione recupera un identificatore di oggetto (vedere l'argomento Enumerating Content) per un determinato oggetto, può recuperare informazioni descrittive su tale oggetto chiamando i metodi nell'interfaccia IPortableDeviceProperties e l'interfaccia IPortableDeviceKeyCollection.
Il metodo IPortableDeviceProperties::GetValues recupera un elenco di proprietà specificate per un determinato oggetto. L'applicazione potrebbe anche chiamare il metodo GetValues e specificare un valore NULL per il parametro pKeys per recuperare tutte le proprietà per un determinato oggetto. Tuttavia, le prestazioni di questo metodo potrebbero risultare notevolmente più lente durante il recupero di tutte le proprietà.
Prima che l'applicazione chiami GetValues, tuttavia, deve identificare le proprietà da recuperare impostando le chiavi corrispondenti in un oggetto IPortableDeviceKeyCollection. L'applicazione identificherà le proprietà di interesse chiamando il metodo IPortableDeviceKeyCollection::Add e fornendo un valore PROPERTYKEY che identifica ogni proprietà recuperata.
La funzione ReadContentProperties nel modulo ContentProperties.cpp dell'applicazione di esempio illustra come sono state recuperate le cinque proprietà per un oggetto selezionato. Nella tabella seguente vengono descritte ognuna di queste proprietà e il valore REFPROPERTYKEY corrispondente.
Proprietà | Descrizione | PROPERTYKEY |
---|---|---|
Identificatore dell'oggetto padre | Stringa che specifica l'identificatore per l'elemento padre dell'oggetto specificato. | WPD_OBJECT_PARENT_ID |
Nome oggetto | Stringa che specifica il nome dell'oggetto specificato. | WPD_OBJECT_NAME |
Identificatore univoco permanente | Stringa che specifica un identificatore univoco per l'oggetto specificato. Questo identificatore è persistente tra le sessioni, a differenza dell'identificatore dell'oggetto. | WPD_OBJECT_PERSISTENT_UNIQUE_ID |
Formato oggetto | Identificatore univoco globale (GUID) che specifica il formato del file corrispondente a un determinato oggetto. | WPD_OBJECT_FORMAT |
Tipo di contenuto oggetto | GUID che specifica il tipo di contenuto associato a un determinato oggetto. | WPD_OBJECT_CONTENT_TYPE |
Nell'estratto seguente della funzione ReadContentProperties viene illustrato come l'applicazione di esempio ha usato l'interfaccia IPortableDeviceKeyCollection e il metodo IPortableDeviceKeyCollection::Add per identificare le proprietà recuperate.
hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pPropertiesToRead));
if (SUCCEEDED(hr))
{
// 4) Populate the IPortableDeviceKeyCollection with the keys we wish to read.
// NOTE: We are not handling any special error cases here so we can proceed with
// adding as many of the target properties as we can.
if (pPropertiesToRead != NULL)
{
HRESULT hrTemp = S_OK;
hrTemp = pPropertiesToRead->Add(WPD_OBJECT_PARENT_ID);
if (FAILED(hrTemp))
{
printf("! Failed to add WPD_OBJECT_PARENT_ID to IPortableDeviceKeyCollection, hr= 0x%lx\n", hrTemp);
}
hrTemp = pPropertiesToRead->Add(WPD_OBJECT_NAME);
if (FAILED(hrTemp))
{
printf("! Failed to add WPD_OBJECT_NAME to IPortableDeviceKeyCollection, hr= 0x%lx\n", hrTemp);
}
hrTemp = pPropertiesToRead->Add(WPD_OBJECT_PERSISTENT_UNIQUE_ID);
if (FAILED(hrTemp))
{
printf("! Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID to IPortableDeviceKeyCollection, hr= 0x%lx\n", hrTemp);
}
hrTemp = pPropertiesToRead->Add(WPD_OBJECT_FORMAT);
if (FAILED(hrTemp))
{
printf("! Failed to add WPD_OBJECT_FORMAT to IPortableDeviceKeyCollection, hr= 0x%lx\n", hrTemp);
}
hrTemp = pPropertiesToRead->Add(WPD_OBJECT_CONTENT_TYPE);
if (FAILED(hrTemp))
{
printf("! Failed to add WPD_OBJECT_CONTENT_TYPE to IPortableDeviceKeyCollection, hr= 0x%lx\n", hrTemp);
}
}
}
Dopo aver impostato le chiavi appropriate, l'applicazione di esempio ha chiamato il metodo IPortableDeviceProperties::GetValues per recuperare i valori specificati per l'oggetto specificato.
if (SUCCEEDED(hr))
{
hr = pProperties->GetValues(szSelection, // The object whose properties we are reading
pPropertiesToRead, // The properties we want to read
&pObjectProperties); // Driver supplied property values for the specified object
if (FAILED(hr))
{
printf("! Failed to get all properties for object '%ws', hr= 0x%lx\n", szSelection, hr);
}
}
Argomenti correlati
-
Interfaccia IPortableDeviceKeyCollection
-
Interfaccia IPortableDeviceProperties