MFEnumDeviceSources function

Enumerates a list of audio or video capture devices.


HRESULT MFEnumDeviceSources(
  IMFAttributes *pAttributes,
  IMFActivate   ***pppSourceActivate,
  UINT32        *pcSourceActivate



Pointer to an attribute store that contains search criteria. To create the attribute store, call MFCreateAttributes. Set one or more of the following attributes on the attribute store:

Value Meaning
Specifies whether to enumerate audio or video devices. (Required.)
For audio capture devices, specifies the device role. (Optional.)
For video capture devices, specifies the device category. (Optional.)


Receives an array of IMFActivate interface pointers. Each pointer represents an activation object for a media source. The function allocates the memory for the array. The caller must release the pointers in the array and call CoTaskMemFree to free the memory for the array.


Receives the number of elements in the pppSourceActivate array. If no capture devices match the search criteria, this parameter receives the value 0.

Return Value

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.


Each returned IMFActivate pointer represents a capture device, and can be used to create a media source for that device. You can also use the IMFActivate pointer to query for attributes that describe the device. The following attributes might be set:

Attribute Description
MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME The display name of the device.
MF_DEVSOURCE_ATTRIBUTE_MEDIA_TYPE The major type and subtype GUIDs that describe the device's output format.
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE The type of capture device (audio or video).
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_ENDPOINT_ID The audio endpoint ID string. (Audio devices only.)
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_CATEGORY The device category. (Video devices only.)
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_HW_SOURCE Whether a device is a hardware or software device. (Video devices only.)
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK The symbolic link for the device driver. (Video devices only.)

To create a media source from an IMFActivate pointer, call the IMFActivate::ActivateObject method.


The following example enumerates the video capture devices on the system and creates a media source for the first device on the list.

HRESULT CreateVideoDeviceSource(IMFMediaSource **ppSource)
    *ppSource = NULL;
IMFMediaSource *pSource = NULL;
IMFAttributes *pAttributes = NULL;
IMFActivate **ppDevices = NULL;

// Create an attribute store to specify the enumeration parameters.
HRESULT hr = MFCreateAttributes(&pAttributes, 1);
if (FAILED(hr))
    goto done;

// Source type: video capture devices
hr = pAttributes->SetGUID(
if (FAILED(hr))
    goto done;

// Enumerate devices.
UINT32 count;
hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count);
if (FAILED(hr))
    goto done;

if (count == 0)
    hr = E_FAIL;
    goto done;

// Create the media source object.
hr = ppDevices[0]->ActivateObject(IID_PPV_ARGS(&pSource));
if (FAILED(hr))
    goto done;

*ppSource = pSource;

done: SafeRelease(&pAttributes);

for (DWORD i = 0; i < count; i++)
return hr;



Windows version Windows 7 [desktop apps only] Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header mfidl.h
Library Mf.lib
DLL Mf.dll

See Also

Audio/Video Capture in Media Foundation

Media Foundation Functions