locked
Media Foundation and COM RRS feed

  • Question

  • I am new to Media Foundation development, and am using the book Developing Microsoft Media Foundation Applications from Microsoft Press as a guide.  My question revolves around MF and COM.

    The examples in the book make use of the ATL library and the CComPtr class.  For example:

    CComPtr<IMFTopology> pTopology = NULL;

    My question is this.  When writing my application, how do I determine which Media Foundation interfaces would require the use of the CComPtr class?  Do I just use it for any Media Foundation interfaces that implement IUnknown?



    Friday, January 11, 2013 2:55 AM

All replies

  • well, in fact its not necessary at all to use CComPtr, it just makes dealing with COM a lot easier. when you check the SDK samples, i haven´t seen any usage of CComPtr at all, so no MediaFoundation interface "requires" the use of CComPtr. 

    However, it just makes dealing with it a lot easier (ref counting and stuff)

    Friday, January 11, 2013 7:31 AM
  • Yes, the book is clear that CComPtr is simply a helper class to make things easier and perhaps avoid some COM leaks and errors.  So in a strict sense, no CComPtr is not required.  I get that.

    Media Foundation's MSDN documentation states, in part, that:
    "Although not all Media Foundation objects are COM objects, all Media Foundation interfaces derive from IUnknown. Therefore, all Media Foundation objects must implement IUnknown according to COM specifications, including the rules for reference counting and QueryInterface. All reference counted objects should also ensure that DllCanUnloadNow will not allow the module to be unloaded while the objects still persist."

    In the code examples I've seen in both the SDK and in the book, CComPtr (or AddRef/Release) is not used when creating an instance or pointer to every MF interface.  It's used in some cases and not others.  I will concede that I am new to COM, but why isn't CComPtr used in every case?  Are there some instances whereby calling the MF interface methods, reference counting is taken care of internally?  Based on the MDSN documentation, how do I know when it is necessary to use hold or release a reference pointer from my class code?  Strictly speaking, is reference counting mandatory when utilizing COM?




    Friday, January 11, 2013 3:32 PM