Freigeben über


Retrieving an Object from a Collection

The following code retrieves the IP address of a client from a collection of clients. The variable pClientsCollection points to an ISdoCollection interface for the collection. See Retrieving a Collection for information on how to retrieve the collection object.

   HRESULT hr
   _variant_t vtClientName = L"Test Client";
   
   //
   // Get the client "Test Client" from the collection of clients
   //
   CComPtr<IDispatch> pFoundClientDispatch;
   hr = pClientsCollection->Item(&vtClientName, &pFoundClientDispatch);
   if (FAILED(hr))
   {
      return hr;
   }

   CComPtr<ISdo> pFoundClientSdo;
   hr = pFoundClientDispatch->QueryInterface(
      __uuidof(ISdo),
      (void **) &pFoundClientSdo
   );
   if (FAILED(hr))
   {
      return hr;
   }

   //
   // Get the IP address of that client 
   //
   _variant_t vtAddress;
   hr = pFoundClientSdo->GetProperty(PROPERTY_CLIENT_ADDRESS ,&vtAddress);
   if (FAILED(hr))
   {
      return hr;
   }

See Also

ISdoCollection::Item
Retrieving a Collection
SysAllocString
SysFreeString
VARIANT

Send comments about this topic to Microsoft

Build date: 10/15/2007