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(&amp;vtClientName, &amp;pFoundClientDispatch);
   if (FAILED(hr))
   {
      return hr;
   }

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

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

ISdoCollection::Item

Retrieving a Collection

SysAllocString

SysFreeString

VARIANT