Compartir a través de


Descripción de dispositivos

Hay dos maneras de obtener objetos de dispositivo:

Ambos métodos devuelven colecciones Devices. A continuación, las aplicaciones usan los métodos Device para recuperar propiedades sobre los dispositivos.

Las aplicaciones pueden recuperar los siguientes tipos de información:

  • Información de jerarquía de dispositivos, incluidos los dispositivos raíz, los dispositivos primarios y los dispositivos secundarios.
  • Propiedades del dispositivo, incluidos los UDN, los identificadores uniformes de recursos (URI) y los nombres legibles por el usuario.
  • Información del fabricante, incluidos los nombres y las páginas web relacionadas.
  • Información del modelo, incluido el nombre, el número, LA CPU, los números de serie y las descripciones del dispositivo.
  • Mostrar información, incluida la dirección URL para controlar el dispositivo y las direcciones URL desde las que se descargan los iconos.
  • Servicios proporcionados por un dispositivo determinado.

Las aplicaciones también obtienen la dirección URL del documento de descripción del dispositivo mediante la interfaz IUPnPDeviceDocumentAccess . A continuación, la aplicación carga el documento de descripción y funciona con las propiedades de dispositivo y servicio que la interfaz IUPnPDevice no expone. Esta interfaz no se puede usar en el scripting, ya que no es la interfaz predeterminada.

Ejemplo de Visual Basic

En el código de ejemplo siguiente se muestra el uso de IUPnPDeviceDocumentAccess::GetDocumentURL.

Sub GetDocumentURL()
Dim pDescDoc As IUPnPDeviceDocumentAccess
Dim strDescDocURL As String

'currentDevice is UPnPDevice object containing the current UPnP Device 
'We are trying to get IUPnPDeviceDocumentAccess interface in the UPnP Device object
Set pDescDoc = currentDevice

If Not (pDescDoc is Nothing) Then
  'Description Document URL is got from device
  strDescDocURL = pDescDoc.GetDocumentURL 
End If

Ejemplo de C++

En el código de ejemplo siguiente se muestra el uso de IUPnPDeviceDocumentAccess::GetDocumentURL.

#include <windows.h>
#include <upnp.h>
#include <stdio.h>

#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")

int GetDeviceDocumentUrl () 
{
  HRESULT hr = S_OK;
  // List of interfaces needed
  IUPnPDeviceFinder *pDevFinder=NULL;
  IUPnPDevice *pDevice =NULL;
  IUPnPDeviceDocumentAccess* pDeviceDocument=NULL;
  BSTR bstrDeviceUDN =NULL;
  BSTR bstrDeviceDocumentURL = NULL; 

  bstrDeviceUDN = SysAllocString(L"uuid:234324234324");
  if(bstrDeviceUDN == NULL){
    printf("ERROR: Could not allocate memory\n");
    return -1;
  }  

  //CoInitialize the program so that we can create COM objects
  CoInitializeEx(NULL, COINIT_MULTITHREADED);

  //now try to instantiate the DeviceFinder object
  hr = CoCreateInstance(  CLSID_UPnPDeviceFinder, 
              NULL,
              CLSCTX_INPROC_SERVER,
              IID_IUPnPDeviceFinder,
              (LPVOID *) &pDevFinder); 

  if(!SUCCEEDED(hr)){
    printf("\nERROR: CoCreateInstance on IUPnPDeviceFinder returned HRESULT %x",hr);
    goto cleanup;
  }

  printf("\nGot a pointer to the IUPnPDeviceFinder Interface");

  printf("\n Finding the device of given UDN\n");
  hr =pDevFinder->FindByUDN(bstrDeviceUDN, &pDevice);
  if(hr!=S_OK)
  {
    printf("\nERROR: FindByUDN for %S returned HRESULT %x", bstrDeviceUDN, hr);
    goto cleanup;
  }

  printf("\n\tFindByUDN for device of UDN %S succeeded", bstrDeviceUDN);
  //Now query pDevice for IUPnPDeviceDocumentAccess
  hr = pDevice->QueryInterface(IID_IUPnPDeviceDocumentAccess, (VOID **)&pDeviceDocument);
  if(SUCCEEDED(hr)){
    // We have got a pointer to the IUPnPDeviceDocumentAccess interface.
    // GetDocumentURL is available only in Windows XP. 
    hr = pDeviceDocument->GetDocumentURL(&bstrDeviceDocumentURL);
    if(SUCCEEDED(hr))
      printf("\nThe Device Document URL is %S \n", bstrDeviceDocumentURL);
  }
    
cleanup:
  //release references to all interfaces 
  if(pDevFinder)
    pDevFinder->Release();
  if(pDevice)
    pDevice->Release();
  if(pDeviceDocument)
    pDeviceDocument->Release();
  
  // Free the bstr strings
  if(bstrDeviceDocumentURL)
    SysFreeString(bstrDeviceDocumentURL);
  if(bstrDeviceUDN)
    SysFreeString(bstrDeviceUDN);
  CoUninitialize();
  return 0;
}