Enumeración de objetos en una colección
Nota
A partir de Windows Server 2008, se cambió el nombre del servicio de autenticación de Internet (IAS). El contenido de este tema se aplica tanto a IAS como a NPS. A lo largo del texto, NPS se usa para hacer referencia a todas las versiones del servicio, incluidas las versiones a las que se hace referencia originalmente como IAS.
El código siguiente enumera los protocolos de la colección de protocolos NPS.
HRESULT hr;
//
// Retrieve the protocols collection object
//
_variant_t vtIASProtocolsCollection;
hr = pSdo->GetProperty(
PROPERTY_IAS_PROTOCOLS_COLLECTION,
&vtIASProtocolsCollection
);
if (FAILED(hr))
{
return hr;
}
//
// Retrieve the ISdoCollection interface
// for the object.
//
CComPtr<ISdoCollection> pIASProtocolsCollection;
hr = vtIASProtocolsCollection.pdispVal->QueryInterface(
__uuidof(ISdoCollection),
(void **) &pIASProtocolsCollection
);
if (FAILED(hr))
{
return hr;
}
//
// Retrieve the enumeration interface, IEnumVARIANT
//
CComPtr<IUnknown> pUnknownProtocol;
hr = pIASProtocolsCollection->get__NewEnum(&pUnknownProtocol);
if (FAILED(hr))
{
return hr;
}
CComPtr<IEnumVARIANT> pEnumProtocols;
hr = pUnknownProtocol->QueryInterface(
__uuidof(IEnumVARIANT),
(void **) &pEnumProtocols
);
if (FAILED(hr))
{
return hr;
}
//
// Retrieve the first protocol from the collection
//
DWORD dwRetrieved = 1;
_variant_t vtProtocol;
hr = pEnumProtocols->Next(1, &vtProtocol, &dwRetrieved);
if (FAILED(hr))
{
return hr;
}
while (hr != S_FALSE) {
//
// Retrieve the name of the protocol
//
CComPtr<ISdo> pLocalSdo;
hr = vtProtocol.pdispVal->QueryInterface(
__uuidof(ISdo),
(void**)&pLocalSdo
);
if (FAILED(hr))
{
return hr;
}
_variant_t vtName;
hr = pLocalSdo->GetProperty(PROPERTY_SDO_NAME, &vtName);
if (FAILED(hr))
{
return hr;
}
vtProtocol.Clear();
vtName.Clear();
//
// Retrieve the next protocol from the collection
//
dwRetrieved = 1;
hr = pEnumProtocols->Next(1, &vtProtocol, &dwRetrieved);
if (FAILED(hr))
{
return hr;
}
}
Observaciones
Las variables vtName y vtProtocol son de tipo _variant_t. Un objeto _variant_t encapsula o incluye el tipo de datos VARIANT . La clase administra la asignación y desasignación de recursos, y realiza llamadas de función a VariantInit y VariantClear según corresponda.
Temas relacionados