Metodo IEnumPortableDeviceObjectIDs::Next (portabledeviceapi.h)
Il metodo Next recupera gli ID oggetto successivi nella sequenza di enumerazione.
Sintassi
HRESULT Next(
[in] ULONG cObjects,
[in, out] LPWSTR *pObjIDs,
[in, out] ULONG *pcFetched
);
Parametri
[in] cObjects
Conteggio degli oggetti richiesti.
[in, out] pObjIDs
Matrice di puntatori LPWSTR , ognuna che specifica un ID oggetto recuperato. Il chiamante deve allocare una matrice di elementi CObjects LPWSTR. Il chiamante deve liberare sia la matrice che le stringhe restituite. Le stringhe vengono liberate chiamando CoTaskMemFree.
[in, out] pcFetched
In input, questo parametro viene ignorato. Nell'output il numero di ID effettivamente recuperati. Se non vengono rilasciati ID oggetto e il valore restituito è S_FALSE, non sono presenti più oggetti da enumerare.
Valore restituito
Il metodo restituisce un HRESULT. I valori possibili includono, ma non sono limitati a, quelli indicati nella tabella seguente.
Codice restituito | Descrizione |
---|---|
|
Il metodo è riuscito. |
|
Non sono presenti più oggetti da enumerare. |
Commenti
Se meno del numero richiesto di elementi rimangono nella sequenza, questo metodo recupera gli elementi rimanenti. Il numero di elementi effettivamente recuperati viene restituito tramite pcFetched (a meno che il chiamante non sia passato in NULL per tale parametro). Gli oggetti enumerati sono tutti i peer, ovvero l'enumerazione dei figli di un oggetto enumera solo elementi figlio diretti, non nipoti o oggetti più profondi.
Esempio
// This number controls how many object identifiers are requested during each call
// to IEnumPortableDeviceObjectIDs::Next()
#define NUM_OBJECTS_TO_REQUEST 10
// Recursively called function which enumerates using the specified
// object identifier as the parent.
void RecursiveEnumerate(LPCWSTR wszParentObjectID, IPortableDeviceContent* pContent)
{
HRESULT hr = S_OK;
IEnumPortableDeviceObjectIDs* pEnumObjectIDs = NULL;
if ((wszParentObjectID == NULL) ||
(pContent == NULL))
{
return;
}
// wszParentObjectID is the object identifier of the parent being used for enumeration
// Get an IEnumPortableDeviceObjectIDs interface by calling EnumObjects with the
// specified parent object identifier.
hr = pContent->EnumObjects(0, wszParentObjectID, NULL, &pEnumObjectIDs);
if (FAILED(hr))
{
// Failed to get IEnumPortableDeviceObjectIDs from IPortableDeviceContent
}
// Loop calling Next() while S_OK is being returned.
while(hr == S_OK)
{
DWORD cFetched = 0;
LPWSTR szObjectIDArray[NUM_OBJECTS_TO_REQUEST] = {0};
hr = pEnumObjectIDs->Next(NUM_OBJECTS_TO_REQUEST, // Number of objects to request on each NEXT call
szObjectIDArray, // Array of LPWSTR array which will be populated on each NEXT call
&cFetched); // Number of objects written to the LPWSTR array
if (SUCCEEDED(hr))
{
// Traverse the results of the Next() operation and recursively enumerate
// Remember to free all returned object identifiers using CoTaskMemFree()
for (DWORD dwIndex = 0; dwIndex < cFetched; dwIndex++)
{
RecursiveEnumerate(szObjectIDArray[dwIndex],pContent);
// Free allocated LPWSTRs after the recursive enumeration call has completed.
CoTaskMemFree(szObjectIDArray[dwIndex]);
szObjectIDArray[dwIndex] = NULL;
}
}
}
// Release the IEnumPortableDeviceObjectIDs when finished
if (pEnumObjectIDs != NULL)
{
pEnumObjectIDs->Release();
pEnumObjectIDs = NULL;
}
}
Requisiti
Requisito | Valore |
---|---|
Piattaforma di destinazione | Windows |
Intestazione | portabledeviceapi.h |
Libreria | PortableDeviceGUIDs.lib |