IEnumPortableDeviceConnectors::Next method

The Next method retrieves the next one or more IPortableDeviceConnector objects in the enumeration sequence.

Syntax

HRESULT Next(
  [in]      UINT32                   cRequested,
  [out]     IPortableDeviceConnector **pConnectors,
  [in, out] UINT32                   *pcFetched
);

Parameters

cRequested [in]

The number of requested devices. This value also indicates the number of elements in the caller-allocated array specified by the pConnectors parameter.

pConnectors [out]

An array of IPortableDeviceConnector pointers, each specifying a paired MTP Bluetooth device. The caller must allocate an array of IPortableDeviceConnector pointers, with the array length specified by the cRequested parameter. On successful return, the caller must free both the array and the returned pointers. The IPortableDeviceConnector interfaces are freed by calling the IUnknown::Release method.

pcFetched [in, out]

The number of IPortableDeviceConnector interfaces that are actually retrieved. If no IPortableDeviceConnector interfaces are retrieved and the return value is S_FALSE, there are no more IPortableDeviceConnector interfaces to enumerate.

Return value

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return code Description
S_OK
The method succeeded.
S_FALSE
There are no more MTP Bluetooth devices to enumerate.

Examples

The following example demonstrates the use of this method to enumerate paired MTP/Bluetooth devices, and to send an asynchronous connection request to each.

IEnumPortableDeviceConnectors* pEnum = NULL;
    HRESULT hrEnum = S_OK;
 HRESULT hr = CoCreateInstance(CLSID_EnumBthMtpConnectors, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pEnum));
    if (SUCCEEDED(hr))
{
  while (S_OK == hrEnum)
    {
       UINT32  uFetched        = 0;
       LPWSTR  wszDevicePnPID  = NULL;
       IPortableDeviceConnector* pDevice = NULL;
       hrEnum = pEnum->Next(1, &spDevice, &uFetched);
       if (hrEnum == S_OK && uFetched == 1)
        {
          // Send an asynchronous connect request.  
          hr = pDevice ->Connect(NULL);
          // Release the device when done
          pDevice->Release();
          pDevice = NULL;
        }
     }  // while S_OK == hrEnum
  // Release the enumerator when done
    if (pEnum)
    {
     pEnum->Release();
     pEnum = NULL;
   }
    }
       

Requirements

Requirement Value
Minimum supported client
Windows 7 [desktop apps only]
Minimum supported server
None supported
Header
Devpkey.h;
Portabledeviceconnectapi.h
IDL
Portabledeviceconnectapi.idl
Library
PortableDeviceGuids.lib

See also

IEnumPortableDeviceConnectors