title: Which MF Play sample code shows proper COM techniques in Media Foundation?
body: <p>I’m now crawling up the steep learning curve of Windows Media Foundation and I’m focusing on two very similar code samples to help me understand the technology. Even though both use Media Session for a very simple “Play” program that plays video from a file, there are important subtle differences. </p>
  
  <p>The first sample is Microsoft’s MF Play located at: </p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd979592(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/dd979592(v=vs.85).aspx</a></p>
  
  <p>It does not initialize COM and does not perform any critical section locks yet it plays video very well. Will the lack of using COM restrict it’s use in other ways such as when processing multiple video streams to separate windows by multithreading? Since this code is online, I may be naively assuming this code is more current.</p>
  
  <p>The second sample is from the book “Developing Microsoft Media Foundation Applications - By Anton Polinger”. I downloaded sample code from here:
  <a href="https://www.microsoftpressstore.com/content/images/9780735656598/downloads/9780735656598_files.zip" rel="nofollow noreferrer">https://www.microsoftpressstore.com/content/images/9780735656598/downloads/9780735656598_files.zip</a></p>
  
  <p>This Play program in the Chapter 3 folder is slightly more complex due to the use of these COM initialization functions:</p>
  
  <pre><code>// initialize COM
  hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  ...
  // uninitialize COM
  CoUninitialize();
  </code></pre>
  
  <p>It also uses several critical section locks using:</p>
  
  <pre><code>CComCritSecLock&lt;CComAutoCriticalSection&gt; lock(m_critSec);
  </code></pre>
  
  <p>But mysteriously there are no corresponding unlocks(). So can someone please explain these potential important differences between these two code samples and which ones I should use? I’m concerned that if I don’t use the COM methods I may have problems later when I attempt to stream multiple videos to multiple windows, or worse I could have reliability problems.</p>
  
  <p>On a side note, the Polinger code works but does not handle window resizing while playing video. I attempted to add in the code similar to the way the MS code does by using this code after a window resizing event:</p>
  
  <pre><code>m_pVideoDisplay-&gt;SetVideoPosition(NULL, &amp;rcDest)
  </code></pre>
  
  <p>Using this just caused the program to freeze.</p>
  
  <p>Any help would be greatly appreciated!</p>