Método IEnumPortableDeviceObjectIDs::Next (portabledeviceapi.h)

El método Next recupera los identificadores de objeto siguientes de la secuencia de enumeración.

Sintaxis

HRESULT Next(
  [in]      ULONG  cObjects,
  [in, out] LPWSTR *pObjIDs,
  [in, out] ULONG  *pcFetched
);

Parámetros

[in] cObjects

Recuento de los objetos solicitados.

[in, out] pObjIDs

Matriz de punteros LPWSTR , cada una de las cuales especifica un identificador de objeto recuperado. El autor de la llamada debe asignar una matriz de elementos LPWSTR de cObjects . El llamador debe liberar la matriz y las cadenas devueltas. Las cadenas se liberan llamando a CoTaskMemFree.

[in, out] pcFetched

En la entrada, este parámetro se omite. En la salida, el número de identificadores recuperados realmente. Si no se libera ningún identificador de objeto y el valor devuelto es S_FALSE, no hay más objetos que enumerar.

Valor devuelto

El método devuelve un valor HRESULT. Entre los valores posibles se incluyen los que se indican en la tabla siguiente, entre otros.

Código devuelto Descripción
S_OK
El método se ha llevado a cabo de forma correcta.
S_FALSE
No hay más objetos que enumerar.

Comentarios

Si menos del número solicitado de elementos permanecen en la secuencia, este método recupera los elementos restantes. El número de elementos que se recuperan realmente se devuelve a través de pcFetched (a menos que el autor de la llamada pase null para ese parámetro). Los objetos enumerados son todos los elementos del mismo nivel; es decir, la enumeración de elementos secundarios de un objeto solo enumerará elementos secundarios directos, no secundarios ni objetos más profundos.

Ejemplos


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

Requisitos

Requisito Value
Plataforma de destino Windows
Encabezado portabledeviceapi.h
Library PortableDeviceGUIDs.lib

Consulte también

Enumerar contenido

IEnumPortableDeviceObjectIDs (Interfaz)