Partager via


Méthode IPortableDeviceWebControl ::GetDeviceFromIdAsync (portabledeviceapi.h)

Instancie un objet d’appareil WPD Automation de façon asynchrone pour un identificateur d’appareil WPD donné.

Syntaxe

HRESULT GetDeviceFromIdAsync(
  [in] BSTR      deviceId,
  [in] IDispatch *pCompletionHandler,
  [in] IDispatch *pErrorHandler
);

Paramètres

[in] deviceId

BSTR utilisé par plug-and-play pour identifier un appareil WPD actuellement connecté. L’identificateur Plug-and-Play (PnP) d’un appareil particulier peut être obtenu à partir de la méthode IPortableDeviceManager ::GetDevices dans l’API C++/COM WPD.

Une application du Windows Store peut obtenir l’identificateur PnP d’un appareil WPD en utilisant Windows.Devices.Portable.ServiceDevice.GetDeviceSelector ou Windows.Devices.Portable.ServiceDevice.GetDeviceSelectorFromServiceId pour obtenir une chaîne de sélection à passer à Windows.Devices.Enumeration.DeviceInformation.FindAllAsync. FindAllAsync retourne une collection d’objets DeviceInformation qui représentent les appareils WPD actuellement connectés. La propriété Id d’un objet DeviceInformation est l’identificateur PnP de l’appareil.

[in] pCompletionHandler

Gestionnaire de saisie semi-automatique.

[in] pErrorHandler

Gestionnaire d’erreurs.

Valeur retournée

Les codes de retour possibles incluent, sans s’y limiter, les valeurs indiquées dans le tableau suivant.

Code de retour Description
S_OK
S_OK
E_ACCESSDENIED
Un appel à cette méthode en dehors d’une application du Windows Store s’exécutant sur Windows 8 retourne ce code d’erreur.

Remarques

Note Cette méthode ne peut être utilisée que dans les applications du Windows Store.
 

Exemples

Pour les appareils WPD qui utilisent un service d’appareil MTP, vous pouvez créer un objet COM Automation pour fonctionner avec l’appareil comme suit :


 
deviceFactory = new ActiveXObject("PortableDeviceAutomation.Factory");
 
// Get the first device object from the device factory
        deviceFactory.getDeviceFromIdAsync(deviceInfoElement.id,
            function (device) {
                // Get the first service on the device
                var deviceService = device.services[0];
                // Get the first storage on the device
                var deviceStorage = devices.storages[0];
                // …
            }
       }


Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows 8 [applications UWP uniquement]
Serveur minimal pris en charge Windows Server 2012 [applications UWP uniquement]
Plateforme cible Windows
En-tête portabledeviceapi.h

Voir aussi

IPortableDeviceWebControl

Exemple de service d’appareil portable