IMFSourceResolver::CreateObjectFromURL method

Creates a media source or a byte stream from a URL. This method is synchronous.


HRESULT CreateObjectFromURL(
  LPCWSTR        pwszURL,
  DWORD          dwFlags,
  IPropertyStore *pProps,
  MF_OBJECT_TYPE *pObjectType,
  IUnknown       **ppObject



Null-terminated string that contains the URL to resolve.


Bitwise OR of one or more flags. See Source Resolver Flags. See remarks below.


Pointer to the IPropertyStore interface of a property store. The method passes the property store to the scheme handler or byte-stream handler that creates the object. The handler can use the property store to configure the object. This parameter can be NULL. For more information, see Configuring a Media Source.


Receives a member of the MF_OBJECT_TYPE enumeration, specifying the type of object that was created.


Receives a pointer to the object's IUnknown interface. The caller must release the interface.

Return Value

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

Return code Description
The method succeeded.
The dwFlags parameter contains mutually exclusive flags.
The URL scheme is not supported.


The dwFlags parameter must contain either the MF_RESOLUTION_MEDIASOURCE flag or the MF_RESOLUTION_BYTESTREAM flag, but should not contain both.

It is recommended that you do not set MF_RESOLUTION_WRITE on the input argument dwFlags unless it is necessary for your scenario. For most use-cases, media sources do not need to be created with write capability. Creating a media source with write capability may have a lower probability of success than creating a media source without write capability. This is because there can be stricter checks on the content represented by the URL when creating a media source with write capability.

For local files, you can pass the file name in the pwszURL parameter; the file: scheme is not required.

Note  This method cannot be called remotely.


//  Create a media source from a URL.
HRESULT CreateMediaSource(PCWSTR sURL, IMFMediaSource **ppSource)

    IMFSourceResolver* pSourceResolver = NULL;
    IUnknown* pSource = NULL;

    // Create the source resolver.
    HRESULT hr = MFCreateSourceResolver(&pSourceResolver);
    if (FAILED(hr))
        goto done;

    // Use the source resolver to create the media source.

    // Note: For simplicity this sample uses the synchronous method to create 
    // the media source. However, creating a media source can take a noticeable
    // amount of time, especially for a network source. For a more responsive 
    // UI, use the asynchronous BeginCreateObjectFromURL method.

    hr = pSourceResolver->CreateObjectFromURL(
        sURL,                       // URL of the source.
        MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
        NULL,                       // Optional property store.
        &ObjectType,        // Receives the created object type. 
        &pSource            // Receives a pointer to the media source.
    if (FAILED(hr))
        goto done;

    // Get the IMFMediaSource interface from the media source.
    hr = pSource->QueryInterface(IID_PPV_ARGS(ppSource));

    return hr;


Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header mfidl.h
Library Mfuuid.lib

See Also


Source Resolver