'How do I cleanup Media Foundation objects?

I am using CComPtr in an attempt to simplify cleanup when using Ms Media Foundation:

CComPtr<IMFActivate> pActivate;
// ...
IMFMediaSource* source;
pActivate->ActivateObject(__uuidof(IMFMediaSource), (VOID**)&source);
CComPtr<IMFMediaSource> pMediaSource = source;

My hope was that when pActivate and pMediaSource go out of scope they do a complete cleanup of the underlying COM objects. I have seen samples using this approach.

However then I read about these two methods:

 IMFActivate::ShutdownObject()

"If you create an object by calling IMFActivate::ActivateObject, call ShutdownObject when you are done using the object."

and

IMFMediaSource::Shutdown()

"If the application creates the media source, either directly or through the source resolver, the application is responsible for calling Shutdown to avoid memory or resource leaks."

So it seems that using CComPtr to call Release() on these COM objects when they go out of scope is not sufficient?

If so I am better of using a std::shared_ptr with a custom deleter for each of these classes? Like so:

IMFMediaSource* mediaSource;
std::shared_ptr<IMFMediaSource> pMediaSource(mediaSource, [](IMFMediaSource* p) { 
    p->Shutdown();
    p->Release();
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source