Recuperar un objeto de una colección

El código siguiente recupera la dirección IP de un cliente de una colección de clientes. La variable pClientsCollection apunta a una interfaz ISdoCollection para la colección. Consulte Recuperación de una colección para obtener información sobre cómo recuperar el objeto de colección.

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

ISdoCollection::Item

Recuperar una colección

SysAllocString

SysFreeString

VARIANTE