Enumerating Objects in a Collection
Note
Internet Authentication Service (IAS) was renamed Network Policy Server (NPS) starting with Windows Server 2008. The content of this topic applies to both IAS and NPS. Throughout the text, NPS is used to refer to all versions of the service, including the versions originally referred to as IAS.
The following code enumerates the protocols in the NPS protocols collection.
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;
}
}
Remarks
The vtName and vtProtocol variables are of type _variant_t. A _variant_t object encapsulates, or encloses, the VARIANT data type. The class manages resource allocation and deallocation, and makes function calls to VariantInit and VariantClear as appropriate.
Related topics