<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fooling Around &#187; spy</title>
	<atom:link href="http://alax.info/blog/tag/spy/feed" rel="self" type="application/rss+xml" />
	<link>http://alax.info/blog</link>
	<description>Software Production Line</description>
	<lastBuildDate>Tue, 03 Aug 2010 09:48:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DirectShow Spy: IAMFilterData interface</title>
		<link>http://alax.info/blog/1111</link>
		<comments>http://alax.info/blog/1111#comments</comments>
		<pubDate>Mon, 08 Feb 2010 18:47:28 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[mapper]]></category>
		<category><![CDATA[spy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1111</guid>
		<description><![CDATA[This quick update for DirectShow Filter Graph Spy adds tracing for (deprecated) IAMFilterData interface, and also fixes problem with Media Player Classic &#8211; Home Cinema, when the player crashes in External Filters windows.
Partial Visual C++ .NET 2008 source code is available  from SVN, release binary included (Win32,  x64);  installation instructions are in [...]]]></description>
			<content:encoded><![CDATA[<p>This quick update for <a href="http://alax.info/blog/777">DirectShow Filter Graph Spy</a> adds tracing for (deprecated) <a rel="nofollow" href="http://msdn.microsoft.com/en-us/library/dd389369%28VS.85%29.aspx">IAMFilterData</a> interface, and also fixes problem with <a href="http://www.xvidvideo.ru/media-player-classic-home-cinema-x86-x64/">Media Player Classic &#8211; Home Cinema</a>, when the player <a href="http://alax.info/blog/1100/comment-page-1#comment-5738">crashes in External Filters windows</a>.</p>
<p>Partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available  from SVN</a>, release binary included (<a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/Win32/DirectShowSpy.dll?format=raw">Win32</a>,  <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/x64/DirectShowSpy.dll?format=raw">x64</a>);  installation instructions are in <a href="http://alax.info/blog/777">another post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1111/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>DirectShow Spy: Filter Mapper Spy</title>
		<link>http://alax.info/blog/1100</link>
		<comments>http://alax.info/blog/1100#comments</comments>
		<pubDate>Thu, 24 Dec 2009 13:07:50 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[mapper]]></category>
		<category><![CDATA[spy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1100</guid>
		<description><![CDATA[DirectShow Filter Graph Spy was updated to add new functionality: spying over another DirectShow object &#8211; Filter Mapper. Filter Mapper object is used for filter registration purposes and also internally by DirectShow&#8217;s Intelligent Connect. IFilterMapper2 interface traces provide detailed description on steps DirectShow takes in order to connect  and/or render filter pins. For example when [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://alax.info/777">DirectShow Filter Graph Spy</a> was updated to add new functionality: spying over another DirectShow object &#8211; <a href="http://msdn.microsoft.com/en-us/library/dd375788%28VS.85%29.aspx">Filter Mapper</a>. Filter Mapper object is used for filter registration purposes and also internally by DirectShow&#8217;s <a href="http://msdn.microsoft.com/en-us/library/ms940065.aspx">Intelligent Connect</a>. <a href="http://msdn.microsoft.com/en-us/library/dd390033%28VS.85%29.aspx">IFilterMapper2</a> interface traces provide detailed description on steps DirectShow takes in order to connect  and/or render filter pins. For example when trying to render <em>MEDIATYPE_Audio</em> pin, Filter Mapper suggested &#8220;RDP DShow Redirection Filter&#8221; and, then, &#8220;Default DirectSound Device&#8221;:</p>
<pre>
<pre style="background: #ffffff none repeat scroll 0% 0%; color: #000000; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">FilterMapperSpy<span style="color: #008c00;">.</span>h<span style="color: #808030;">(</span><span style="color: #008c00;">186</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span> CFilterMapperSpy<span style="color: #808030;">:</span><span style="color: #808030;">:</span>EnumMatchingFilters<span style="color: #808030;">:</span> nFlags 0x0<span style="color: #808030;">,</span> bExactMatch <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> nMinimalMerit 0x00200001<span style="color: #808030;">,</span> bInputNeeded <span style="color: #008c00;">1</span><span style="color: #808030;">,</span> nInputTypeCount <span style="color: #008c00;">1</span><span style="color: #808030;">,</span> pInputPinCategory NULL<span style="color: #808030;">,</span> bRender <span style="color: #008c00;">1</span><span style="color: #808030;">,</span> bOutputNeeded <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> nOutputTypeCount <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> pOutputPinCategory NULL
FilterMapperSpy<span style="color: #008c00;">.</span>h<span style="color: #808030;">(</span><span style="color: #008c00;">191</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span> CFilterMapperSpy<span style="color: #808030;">:</span><span style="color: #808030;">:</span>EnumMatchingFilters<span style="color: #808030;">:</span> nInputTypeIndex <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> MajorType <span style="color: #808030;">{</span><span style="color: #008c00;">73647561</span><span style="color: #808030;">-</span><span style="color: #008c00;">0000</span><span style="color: #808030;">-</span><span style="color: #008c00;">0010</span><span style="color: #808030;">-</span><span style="color: #008c00;">8000</span><span style="color: #808030;">-</span>00AA00389B71<span style="color: #808030;">}</span><span style="color: #808030;">,</span> Subtype <span style="color: #808030;">{</span><span style="color: #008c00;">00000000</span><span style="color: #808030;">-</span><span style="color: #008c00;">0000</span><span style="color: #808030;">-</span><span style="color: #008c00;">0000</span><span style="color: #808030;">-</span><span style="color: #008c00;">0000</span><span style="color: #808030;">-</span><span style="color: #008c00;">000000000000</span><span style="color: #808030;">}</span>
FilterMapperSpy<span style="color: #008c00;">.</span>h<span style="color: #808030;">(</span><span style="color: #008c00;">212</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span> CFilterMapperSpy<span style="color: #808030;">:</span><span style="color: #808030;">:</span>EnumMatchingFilters<span style="color: #808030;">:</span> pMoniker @device<span style="color: #808030;">:</span>sw<span style="color: #808030;">:</span><span style="color: #808030;">{</span>083863F1<span style="color: #808030;">-</span>70DE<span style="color: #808030;">-</span>11D0<span style="color: #808030;">-</span>BD40<span style="color: #808030;">-</span>00A0C911CE86<span style="color: #808030;">}</span><span style="color: #808030;">\</span><span style="color: #808030;">{</span>AB9D6472<span style="color: #808030;">-</span>752F<span style="color: #808030;">-</span>43F6<span style="color: #808030;">-</span>B29E<span style="color: #808030;">-</span>61207BDA8E06<span style="color: #808030;">}</span>
FilterMapperSpy<span style="color: #008c00;">.</span>h<span style="color: #808030;">(</span><span style="color: #008c00;">220</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span> CFilterMapperSpy<span style="color: #808030;">:</span><span style="color: #808030;">:</span>EnumMatchingFilters<span style="color: #808030;">:</span> sFriendlyName <span style="color: #800000;">"</span><span style="color: #0000e6;">RDP DShow Redirection Filter</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> sDescription <span style="color: #800000;">"</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> sDevicePath <span style="color: #800000;">"</span><span style="color: #800000;">"</span>
FilterMapperSpy<span style="color: #008c00;">.</span>h<span style="color: #808030;">(</span><span style="color: #008c00;">212</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span> CFilterMapperSpy<span style="color: #808030;">:</span><span style="color: #808030;">:</span>EnumMatchingFilters<span style="color: #808030;">:</span> pMoniker @device<span style="color: #808030;">:</span>cm<span style="color: #808030;">:</span><span style="color: #808030;">{</span>E0F158E1<span style="color: #808030;">-</span>CB04<span style="color: #808030;">-</span>11D0<span style="color: #808030;">-</span>BD4E<span style="color: #808030;">-</span>00A0C911CE86<span style="color: #808030;">}</span><span style="color: #808030;">\</span>Default DirectSound Device
FilterMapperSpy<span style="color: #008c00;">.</span>h<span style="color: #808030;">(</span><span style="color: #008c00;">220</span><span style="color: #808030;">)</span><span style="color: #808030;">:</span> CFilterMapperSpy<span style="color: #808030;">:</span><span style="color: #808030;">:</span>EnumMatchingFilters<span style="color: #808030;">:</span> sFriendlyName <span style="color: #800000;">"</span><span style="color: #0000e6;">Default DirectSound Device</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> sDescription <span style="color: #800000;">"</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> sDevicePath <span style="color: #800000;">"</span><span style="color: #800000;">"</span></pre>
</pre>
<p>Important is that DirectShow&#8217;s internals are using the mapper through COM instantiation and this provides a safe method to override default behavior process wide in order to, for example, extend <a href="http://msdn.microsoft.com/en-us/library/ms940065.aspx">Intelligent Connect</a> functionality onto custom, unregistered globally, private filters.</p>
<p>Also, the binary is renamed from FilterGraphSpy.dll to DirectShowSpy.dll.</p>
<p>Partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary included (<a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/Win32/DirectShowSpy.dll?format=raw">Win32</a>, <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/x64/DirectShowSpy.dll?format=raw">x64</a>); installation instructions are in <a href="./777">another post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1100/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>DirectShow Filter Graph Spy: 64-bit version and hook API</title>
		<link>http://alax.info/blog/1094</link>
		<comments>http://alax.info/blog/1094#comments</comments>
		<pubDate>Sun, 01 Nov 2009 19:30:19 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[64-bit]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[spy]]></category>
		<category><![CDATA[x64]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1094</guid>
		<description><![CDATA[Today&#8217;s update for DirectShow Filter Graph Spy introduces 64-bit version (mind the beta state) and a mini-API for an external module to be involved into graph building process.
Filter Graph Spy is offering three new interfaces that provide extensibility of the spy:

IFilterGraphAddRemoveHook
IFilterGraphConnectHook
IFilterGraphStateControlHook

The interfaces are contained in the type library and can be imported using #import directive. [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s update for DirectShow Filter Graph Spy introduces 64-bit version (mind the beta state) and a mini-API for an external module to be involved into graph building process.</p>
<p>Filter Graph Spy is offering three new interfaces that provide extensibility of the spy:</p>
<ul>
<li>IFilterGraphAddRemoveHook</li>
<li>IFilterGraphConnectHook</li>
<li>IFilterGraphStateControlHook</li>
</ul>
<p>The interfaces are contained in the type library and can be imported using <a href="http://msdn.microsoft.com/en-us/library/8etzzkb6%28VS.71%29.aspx">#import</a> directive. An implementation of one or more of these interfaces will receive hook style calls corresponding to respective <a href="http://msdn.microsoft.com/en-us/library/dd375786%28VS.85%29.aspx">Filter Graph Manager</a> calls, system wide including in context of other applications.</p>
<p>A COM object may be registered as a hook object with <em>Spy</em> and <em>NoThreadSpy</em> COM classes under predefined registry keys:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/11/02-Image001.png"><img class="alignnone size-medium wp-image-1095" title="Registering a DirectShow Filter Graph Spy Hook" src="http://alax.info/blog/wp-content/uploads/2009/11/02-Image001-320x136.png" alt="Registering a DirectShow Filter Graph Spy Hook" width="320" height="136" /></a></p>
<p>Spy will instantiate the registered hook objects and forward them the calls it receive, before passing them to system Filter Graph Manager object. A hook object has an option to override default processing, including, for example, inserting its own filter in between. For example, <a href="http://msdn.microsoft.com/en-us/library/dd390021%28VS.85%29.aspx">IFilterGraph::Reconnect</a> call is implemented the following way:</p>
<pre>
<pre style="background: #ffffff none repeat scroll 0% 0%; color: #000000;">STDMETHOD<span style="color: #808030;">(</span>Reconnect<span style="color: #808030;">)</span><span style="color: #808030;">(</span>IPin<span style="color: #808030;">*</span> pPin<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    _Z4<span style="color: #808030;">(</span>atlTraceCOM<span style="color: #808030;">,</span> <span style="color: #008c00;">4</span><span style="color: #808030;">,</span> _T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">...</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    HOOK_PROLOG<span style="color: #808030;">(</span>CFilterGraphConnectHookHost<span style="color: #808030;">)</span>
        OnReconnect<span style="color: #808030;">(</span>pT<span style="color: #808030;">,</span> pPin<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>bDefault<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    HOOK_EPILOG<span style="color: #808030;">(</span><span style="color: #808030;">)</span>
    <span style="color: #800000; font-weight: bold;">return</span> m_pInnerFilterGraph2<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Reconnect<span style="color: #808030;">(</span>pPin<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span></pre>
</pre>
<p>Before passing the call to original Reconnect method, spy is iterating through associated hooks, passing them <em>IFilterGraphConnectHook::OnReconnect</em> call. Setting <em>bDefault</em> parameter to <em>FALSE</em> will prevent spy from passing the call to original method.</p>
<p>Included <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/BdaHooks">BdaHooks</a> project shows a sample implementation of the hooking COM classes (note <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/BdaHooks/ConnectHook.rgs">.rgs registration</a>).</p>
<p>Filter Graph Spy is compatible with all current Windows operating systems, 32-bit and 64-bit (<a href="http://en.wikipedia.org/wiki/X86-64">x64</a>), in particular including:</p>
<ul>
<li><a href="http://www.microsoft.com/windows/windows-7/">Windows 7</a></li>
<li>Windows Server 2008</li>
<li>Windows Vista</li>
<li>Windows Server 2003</li>
<li>Windows XP</li>
<li>Windows 2000</li>
</ul>
<p>NOTE: DirectShow Filter Graph Spy is <span style="text-decoration: underline;">NOT</span> suitable for production environment, it is <span style="text-decoration: underline;">NOT</span> licensed to be redistributed to be a part of production state software item.</p>
<p>Partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary included (<a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/Win32/DirectShowSpy.dll?format=raw">Win32</a>, <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/x64/DirectShowSpy.dll?format=raw">x64</a>); installation instructions are in <a href="http://alax.info/blog/777">another post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1094/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DirectShow Filter Graph Spy: Log Filters and Connection Media Types</title>
		<link>http://alax.info/blog/1078</link>
		<comments>http://alax.info/blog/1078#comments</comments>
		<pubDate>Tue, 06 Oct 2009 19:26:23 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[spy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1078</guid>
		<description><![CDATA[Having hard time to connect to remote filter graph on Windows 7 machine, I suspected that some of the filters do not like being connected through marshaling and freeze. Or, actually more likely, it is SDK&#8217;s proppage.dll which hosts proxy stub pairs behaves itself in a not quite expected way and freezes remote application (Graph [...]]]></description>
			<content:encoded><![CDATA[<p>Having hard time to connect to remote filter graph on Windows 7 machine, I suspected that some of the filters do not like being connected through marshaling and freeze. Or, actually more likely, it is SDK&#8217;s proppage.dll which hosts proxy stub pairs behaves itself in a not quite expected way and freezes remote application (Graph Edit or similar) during attempt to connect to remote graph.</p>
<p>As the goal was to find out details about connection media types between the filters being spied over, the spy received a new feature of logging graph details each time the graph is going to running state:</p>
<blockquote>
<pre>Filter 7: Name "[1BDADev]", Class {17CCA71B-ECD7-11D0-B908-00A0C9223196}, State 2
 Pin 1: Name "MPEG2 Transport", Direction "Input", Peer "[0BDATnr].MPEG2 Transport"
 Connection media type:
 majortype {E436EB83-524F-11CE-9F53-0020AF0BA770}, subtype {E06D8023-DB46-11CF-B4D1-00805F6CBBEA}, pUnk 0x00000000
 bFixedSizeSamples 0, bTemporalCompression 0, lSampleSize 1
 formattype {8DEDA6FD-AC5F-4334-8ECF-A4BA8FA7D0F0}, cbFormat 24, pbFormat 0x00350868
 [0x0000] BC 00 00 00 38 9A 00 00 00 00 00 00 00 00 00 00
 [0x0010] 00 00 00 00 00 00 00 00
 Pin 2: Name "MPEG2 Transport", Direction "Output", Peer "Infinite Pin Tee Filter[BDATsIft].Input"
 Connection media type:
 majortype {E436EB83-524F-11CE-9F53-0020AF0BA770}, subtype {F4AEB342-0329-4FDD-A8FD-4AFF4926C978}, pUnk 0x00000000
 bFixedSizeSamples 1, bTemporalCompression 0, lSampleSize 39480
 formattype {0F6417D6-C318-11D0-A43F-00A0C9223196}, cbFormat 0, pbFormat 0x00000000
Filter 8: Name "[0BDATnr]", Class {17CCA71B-ECD7-11D0-B908-00A0C9223196}, State 2
 Pin 1: Name "Input0", Direction "Input", Peer "Microsoft Network Provider[NwPvd].Antenna Out"
 Connection media type:
 majortype {71985F41-1CA1-11D3-9CC8-00C04F7971E0}, subtype {E436EB8E-524F-11CE-9F53-0020AF0BA770}, pUnk 0x00000000
 bFixedSizeSamples 0, bTemporalCompression 0, lSampleSize 1
 formattype {0F6417D6-C318-11D0-A43F-00A0C9223196}, cbFormat 0, pbFormat 0x00000000
 Pin 2: Name "MPEG2 Transport", Direction "Output", Peer "[1BDADev].MPEG2 Transport"
 Connection media type:
 majortype {E436EB83-524F-11CE-9F53-0020AF0BA770}, subtype {E06D8023-DB46-11CF-B4D1-00805F6CBBEA}, pUnk 0x00000000
 bFixedSizeSamples 0, bTemporalCompression 0, lSampleSize 1
 formattype {8DEDA6FD-AC5F-4334-8ECF-A4BA8FA7D0F0}, cbFormat 24, pbFormat 0x00350868
 [0x0000] BC 00 00 00 38 9A 00 00 00 00 00 00 00 00 00 00
 [0x0010] 00 00 00 00 00 00 00 00</pre>
</blockquote>
<p>Partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/FilterGraphSpy.dll?format=raw">included</a>; installation instructions are in <a href="http://alax.info/blog/777">another post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1078/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DirectShow Filter Graph Spy on Vista</title>
		<link>http://alax.info/blog/944</link>
		<comments>http://alax.info/blog/944#comments</comments>
		<pubDate>Mon, 22 Jun 2009 08:36:15 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[ATL]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[registry]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[spy]]></category>
		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=944</guid>
		<description><![CDATA[I have been receiving comments that Filter Graph Spy tool does not work with Microsoft Vista operating system. I never had a moment to check until recently, and this time I realized that it really does not work. I am definitely aware of dramatic changes introduced with this operating system, and in particular UAC feature, [...]]]></description>
			<content:encoded><![CDATA[<p>I have been receiving comments that <a href="http://alax.info/blog/777">Filter Graph Spy</a> tool does not work with Microsoft Vista operating system. I never had a moment to check until recently, and this time I realized that it really does not work. I am definitely aware of dramatic changes introduced with this operating system, and in particular UAC feature, virtualization and changes in security. No wonder this was the first guess that security was the cause, however the investigation showed there was a trail of issues underneath&#8230;</p>
<p>Investigation details deserve a separate post, while this one briefly outlines the issues and also accompany the repository update with a version compatible with Vista OS.</p>
<p>First of all, COM registration of the DLL (which definitely requires privilege elevation) succeeded on Vista. This means the registration procedure did not encounter any errors on the way, or poorly written code ignored the problem. It appeared that the source of the problem was <a href="http://msdn.microsoft.com/en-us/library/ms693452(VS.85).aspx">CoTreatAsClass</a> API, which failed to do the requested action, however returned status code indicating successful operation. This definitely looks like a bug and further comments on this particular behavior are expected to appear on <a href="http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/threads/">Windows Applications Security MSDN forum</a>, where I opened <a href="http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/583793b8-a73c-4cb5-ae8c-a3620203aed9">a topic on the matter</a>.</p>
<p>With a COM TreatAs feature activated, the class&#8217;s behavior to instantiate instead of DirectShow&#8217;s CLSID_FilterGraph is restored, and in particular the DLL generates <em>FilterGraphSpy.log</em> log file on filter graph activity. Note that log file location is OS dependent (due to Vista&#8217;s permissions and file system virtualization):</p>
<ul>
<li>pre-Vista OS: root of syste drive, typically <em>C:\</em></li>
<li>starting Vista, administrator with elevated privileges: <em>CSIDL_COMMON_APPDATA</em>, typically <em>C:\ProgramData</em> (note this directory is hidden by deafult)</li>
<li>starting Vista, without elevated administrator privileges: <em>CSIDL_LOCAL_APPDATA</em>, typically <em>C:\Users\$(UserName)\AppData\Local</em> (note that <em>AppData</em> directory is hidden by deafult)</li>
</ul>
<p>Still even with the log file generated and indicating activation of the spy, it was unable to connect to remote graph through the running object table (ROT). It appeared that the ROT entires are there where expected, it was OK to get an object from ROT and the problem came from QueryInterface code:</p>
<pre>CComPtr<span style="color: #800080;">&lt;</span>IUnknown<span style="color: #800080;">&gt;</span> pFilterGraphUnknown<span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pRunningObjectTable<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span><span style="color: #400000;">GetObject</span><span style="color: #808030;">(</span>pMoniker<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>pFilterGraphUnknown<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
CComQIPtr<span style="color: #800080;">&lt;</span>IMyFilterGraph<span style="color: #800080;">&gt;</span> pFilterGraph <span style="color: #808030;">=</span> pFilterGraphUnknown<span style="color: #800080;">;</span> <span style="color: #696969;">// <span style="color: #ff0000;">E_NOINTERFACE</span></span></pre>
<p>The call reached the original object but COM subsystem was unable to marshal the interface through apartments to enable interprocess communication on it. The reason for this is absence of <em>PSFactoryBuffer</em> class (CLSID {92A3A302-DA7C-4A1F-BA7E-1802BB5D2D02}), which provides proxy/stub pairs for marshaling well known DirectShow interfaces in the Vista&#8217;s version of <em>quartz.dll</em>. <a href="http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/5079f1c5-1275-4449-a11c-3cbb820e33eb">As mentioned by Microsoft&#8217;s Mike Wasson</a>, this class was moved from <em>quartz.dll</em> into Vista SDK&#8217;s <em>proppage.dll</em>, so in order to obtain connectivity to remote DirectShow graphs starting Vista, one needs to install this DLL with <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE331CDC&amp;displaylang=en">Windows SDK</a>, or otherwise have it registered with the operating system.</p>
<p>Also note that DirectShow-enabled applications that have their filter graphs published on ROT will need an utility application such as <a href="http://msdn.microsoft.com/en-us/library/ms787460(VS.85).aspx">GraphEdit</a> started with the same permissions (elevated or not) in order to be able to access ROT entires.</p>
<div style="background-color: #efa; border: 1px solid #ffc; padding: 2px; ">To sum everything up, to install Alax.Info DirectShow Filter Graph Spy on Vista:<br/></p>
<ul>
<li>get the latest <em>FilterGraphSpy.dll</em></li>
<li>regsvr32 <em>FilterGraphSpy.dll</em> on target system from administrative command prompt, with elevated privileges (note you should have a log file <em>FilterGraphSpy.log</em> generated in CSIDL_COMMON_APPDATA directory, with a few lines indicating registration success)</li>
<li>get <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE331CDC&amp;displaylang=en">Windows SDK</a> and make <em>$(WindowsSDK)\Bin\proppage.dll</em> file registered on target system (also administrative regsvr32), note that it is necessary to restart DirectShow-enabled applications and GraphEdit after DLL registration to get graphs visible through ROT</li>
<li>mind the log file directories with <em>FilterGraphSpy.log</em> file</li>
</ul>
</div>
<p>A partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/FilterGraphSpy.dll?format=raw">included</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/944/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hint on how to easily find your filter graph on running object table (ROT)</title>
		<link>http://alax.info/blog/930</link>
		<comments>http://alax.info/blog/930#comments</comments>
		<pubDate>Thu, 11 Jun 2009 13:14:21 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[graphedit]]></category>
		<category><![CDATA[graphstudio]]></category>
		<category><![CDATA[moniker]]></category>
		<category><![CDATA[rot]]></category>
		<category><![CDATA[spy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=930</guid>
		<description><![CDATA[With a lot of DirectShow Filter Graphs published on Running Object Table, especially those automatically published by Filter Graph Spy utility, it might be a bit tricky to locate your graph of interest in the list.
Filter graphs are published with a textual moniker item name of predefined format, which is recognized by GraphEdit or GraphStudio, [...]]]></description>
			<content:encoded><![CDATA[<p>With a lot of <a href="http://msdn.microsoft.com/en-us/library/dd407188(VS.85).aspx">DirectShow Filter Graphs</a> published on <a href="http://msdn.microsoft.com/en-us/library/ms684004(VS.85).aspx">Running Object Table</a>, especially those automatically published by <a href="http://alax.info/blog/793">Filter Graph Spy utility</a>, it might be a bit tricky to locate your graph of interest in the list.</p>
<p>Filter graphs are published with a textual <a href="http://msdn.microsoft.com/en-us/library/ms680140(VS.85).aspx">moniker item name</a> of predefined format, which is recognized by <a href="http://msdn.microsoft.com/en-us/library/ms787460(VS.85).aspx">GraphEdit</a> or <a href="http://blog.monogram.sk/janos/tools/monogram-graphstudio/">GraphStudio</a>, or similar utilities as an item corresponding to a filter graph. A template for such a string is &#8220;<em>FilterGraph %08x pid %08x</em>&#8220;, which obviously only contains raw pointer address and process identifier, which only help a bit in looking up for proper graph interactively. However, it is important how exactly applications are recognizing filter graph related names. For example, GraphStudio <a href="http://dev.monogram.sk/websvn/listing.php?repname=graphstudio">does it</a> the following way:</p>
<pre>rot<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>EnumRunning<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>emon<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
emon<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Reset<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">while</span> <span style="color: #808030;">(</span>emon<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Next<span style="color: #808030;">(</span><span style="color: #008c00;">1</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>moniker<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>f<span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> NOERROR<span style="color: #808030;">)</span> <span style="color: #800080;">{</span>

    <span style="color: #696969;">// is this a graph object ?</span>
    LPOLESTR    displayname<span style="color: #800080;">;</span>
    moniker<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>GetDisplayName<span style="color: #808030;">(</span>bindctx<span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>displayname<span style="color: #808030;">)</span><span style="color: #800080;">;</span>

    <span style="color: #603000;">CString</span>        name<span style="color: #808030;">(</span>displayname<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">if</span> <span style="color: #808030;">(</span>name<span style="color: #808030;">.</span>Find<span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">!FilterGraph</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span> <span style="color: #800080;">{</span></pre>
<p>The items that match are then listed in GUI with an original string, which means that it is possible to provide an informational suffix to be able to locate the graph in a more convenient way, e.g. with a process image name, not only identifier (&#8221;; process: &#8230;&#8221; was appended to the item name):</p>
<p><img class="alignnone size-full wp-image-932" title="GraphStudio's ROT Items" src="http://alax.info/blog/wp-content/uploads/2009/06/11-image001.png" alt="GraphStudio's ROT Items" width="400" height="249" /></p>
<p>GraphEdit is using another method and is more strict in selecting among available items. AFAIR earlier versions did not allow custom suffixes in item names, however the latest version still picks the items up from the global list. However, GraphEdit does not show graph&#8217;s original item name, so suffixes are merely useless with GraphEdit.</p>
<p><img class="alignnone size-full wp-image-933" title="GraphEdit ROT Items" src="http://alax.info/blog/wp-content/uploads/2009/06/11-image002.png" alt="GraphEdit ROT Items" width="314" height="215" /></p>
<p><a href="http://alax.info/blog/793">Filter Graph Spy utility</a> was updated to automatically append process name suffix, which should be OK for both GrapEdit and GraphStudio. Still, the feature can be disabled through registry DWORD value named &#8220;<em>Enable ROT Moniker Item Name Suffix</em>&#8221; under <em>HKEY_LOCAL_MACHINE\SOFTWARE\Alax.Info\Utilities</em>. The value of zero, or missing, is the default behavior to enable suffixes. The value of 1 disables the feature, the value of 2 makes sure it is enabled.</p>
<pre><span style="color: #800000; font-weight: bold;">static</span> CConstIntegerRegistryValue g_nEnableRotMonikerItemNameSuffix<span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enable ROT Moniker Item Name Suffix</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// 0 Default, 1 Disable, 2 Enable</span>
<span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>g_nEnableRotMonikerItemNameSuffix <span style="color: #808030;">!</span><span style="color: #808030;">=</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    <span style="color: #603000;">TCHAR</span> pszPath<span style="color: #808030;">[</span>MAX_PATH<span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> <span style="color: #008c00;">0</span> <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
    _W<span style="color: #808030;">(</span><span style="color: #400000;">GetModuleFileName</span><span style="color: #808030;">(</span><span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> pszPath<span style="color: #808030;">,</span> DIM<span style="color: #808030;">(</span>pszPath<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #603000;">CString</span> sItemName <span style="color: #808030;">=</span> AtlFormatString<span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%s</span><span style="color: #0000e6;">; process: </span><span style="color: #0f69ff;">%s</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> m_RunningFilterGraph<span style="color: #808030;">.</span>GetDefaultMonikerItemName<span style="color: #808030;">(</span>GetControllingUnknown<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> FindFileName<span style="color: #808030;">(</span>pszPath<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    m_RunningFilterGraph<span style="color: #808030;">.</span>SetFilterGraph<span style="color: #808030;">(</span>GetControllingUnknown<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> CStringW<span style="color: #808030;">(</span>sItemName<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span> <span style="color: #800000; font-weight: bold;">else</span>
    m_RunningFilterGraph<span style="color: #808030;">.</span>SetFilterGraph<span style="color: #808030;">(</span>GetControllingUnknown<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span></pre>
<p>A partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/FilterGraphSpy.dll?format=raw">included</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/930/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>More on DirectShow Filter Graph Spy</title>
		<link>http://alax.info/blog/793</link>
		<comments>http://alax.info/blog/793#comments</comments>
		<pubDate>Sat, 07 Feb 2009 09:55:30 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[spy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=793</guid>
		<description><![CDATA[Having DirectShow Filter Graph Spy installed in the system, I noticed a new and weird effect that when Media Player Classic plays a list of files and each MP3 file being currently decoded shows decoder&#8217;s system tray icon, a switch to a new file leaves an old icon in place and adds a new icon [...]]]></description>
			<content:encoded><![CDATA[<p>Having <a href="http://alax.info/blog/784">DirectShow Filter Graph Spy</a> installed in the system, I noticed a new and weird effect that when <a href="http://sourceforge.net/projects/guliverkli/">Media Player Classic</a> plays a list of files and each MP3 file being currently decoded shows decoder&#8217;s system tray icon, a switch to a new file leaves an old icon in place and adds a new icon for a new decoder.  I thought this might be also a decoder&#8217;s problem which I also recently updated to a new version, but then I noticed other artifacts, with other software and again with <a href="http://sourceforge.net/projects/guliverkli/">Media Player Classic</a>, that if I drop a new file onto the player and it starts playing it, old file is still being played as if player just releases all referenced to the graph and never calls <a href="http://msdn.microsoft.com/en-us/library/dd390178(VS.85).aspx">IMediaControl::Stop</a> to force stop of playback.</p>
<p>It was clear at that point that it is related to filter graph spy and the problem needs a fix. The problem definitely looked like the spy leave outstanding references to the filter graph and when the application releases graph and it is supposed to be automatically destroyed, it is still being alive and possibly, such as in case of <a href="http://sourceforge.net/projects/guliverkli/">Media Player Classic</a>, even running.</p>
<p>The first clue was that being published to running object table (ROT), the object gets more than one additional reference on it and as such it never gets removed from ROT until application terminates as ROT keeps a reference to the graph and there is noone to remove it. By original design spy published filter graph on ROT and removed one reference immediately after that to compensate the ROT&#8217;s reference (one only) making it a weak reference. So when all references are released from the filter graph but ROT reference, the graph gets destroyed and in <a href="http://msdn.microsoft.com/en-us/library/ea0ca499.aspx">FinalRelease</a> class on the COM object we re-add the reference back and automatically remove the object from ROT as well. The whole scheme works in assumption that ROT adds one reference only, if there are more then the object is referenced by the ROT forever.</p>
<p>Debugging however showed that ROT adds a single reference and there is no problem from this side. However I immediately noticed  another weird behavior in the same method <a href="http://msdn.microsoft.com/en-us/library/afkt56xx.aspx">FinalConstruct</a>. An underlying (real) filter graph object, i.e. CFilterGraph from quartz.dll, is adding a reference on the outer COM object when being queried for a private interface from <a href="http://msdn.microsoft.com/en-us/library/ms810016.aspx">implicit</a> (also known as main, raw) IUnknown when created as aggregated object. And it is not exactly the behavior one would expect from aggregated object because it basically break proper reference counting. I realize that aggregating is a rather rare technique and DirectShow COM base is one of the very first COM bases at all which then stopped being developed, so perhaps this problem was not identified on time and later left unfixed at all, so in present situation there should rather be a workaround.</p>
<p>It is also worth mentioning that there are two scenarios involved. My <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Spy.h">CSpy</a> object creates DirectShow <a href="http://msdn.microsoft.com/en-us/library/dd375786(VS.85).aspx">CFilterGraph</a> as an aggregated object. And CSpy in its turn may be created as aggregated too. For example, <a href="http://www.microsoft.com/windows/windowsmedia/players.aspx">Windows Media Player</a> creates (as most applications in this universe do) filter graph object the regular way, as a standalone COM object. However it appears that <a href="http://sourceforge.net/projects/guliverkli/">Media Player Classic</a> creates filter graph as aggregated, for whatever it needs it for. Because of the discovered problem inner CFilterGraph adds an outstanding reference on the top level &#8220;controlling IUnknown&#8221;, which is either CSpy&#8217;s private IUnkown in case of <a href="http://www.microsoft.com/windows/windowsmedia/players.aspx">Windows Media Player</a>, or higher level IUnknown in case of <a href="http://sourceforge.net/projects/guliverkli/">Media Player Classic</a>.</p>
<p>So the proper workaround is to release unwanted references from controlling unknown rather than self:</p>
<pre>CComPtr<span style="color: #800080;">&lt;</span>IUnknown<span style="color: #800080;">&gt;</span> pUnknown<span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pClassFactory<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>CreateInstance<span style="color: #808030;">(</span>pControllingUnknown<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>IUnknown<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">(</span><span style="color: #603000;">VOID</span><span style="color: #808030;">*</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #808030;">&amp;</span>pUnknown<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #696969;">// NOTE: DirectShow FilterGraph is incorrectly implementing COM aggregation adding outer reference to interfaces queried from private IUnknown</span>
CComQIPtr<span style="color: #800080;">&lt;</span>IFilterGraph2<span style="color: #800080;">&gt;</span> pFilterGraph2 <span style="color: #808030;">=</span> pUnknown<span style="color: #800080;">;</span>
ATLENSURE_THROW<span style="color: #808030;">(</span>pFilterGraph2<span style="color: #808030;">,</span> E_NOINTERFACE<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pFilterGraph2<span style="color: #808030;">.</span>p<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Release<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// &lt;&lt;--------------------------</span></pre>
<p>It looked like the problem is finally worked around but in aggregated creation scenario it brought another problem up. Since instantiation of inner CFilterGraph takes place in FinalConstruct and CSpy is also being instantiated as aggregated, it appears that outer COM object is sensible to manipulation with its reference counter. CFilterGraph added a reference it should not, CSpy released it in compensation but on this early stage the compensating Release might zero reference counter and might initiate unexpected object destruction. It is not necessarily this way as it depends on outer COM object base, but it seems that Media Player Classic does not do <a href="http://msdn.microsoft.com/en-us/library/97c868sh.aspx">DECLARE_PROTECT_FINAL_CONSTRUCT</a> or its equavalent and things go the worst scenario.</p>
<p>CSpy is an inner object and we don&#8217;t have any external instance to hold a temporary reference for us while outer COM object is being created, so a workround for this is to temporarily hold a circular reference to an outer object to let it complete its instanatiation and pass another reference higher up to the controlling application. At which point we are going to be safe to release the temporary reference and normalize reference counters.</p>
<pre><span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>m_bIsAggregated<span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    pControllingUnknown<span style="color: #808030;">.</span>p<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>AddRef<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">ULONG</span> nReferenceCount <span style="color: #808030;">=</span> pControllingUnknown<span style="color: #808030;">.</span>p<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Release<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>nReferenceCount <span style="color: #808030;">=</span><span style="color: #808030;">=</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span>
        m_pTemporaryUnknown <span style="color: #808030;">=</span> pControllingUnknown<span style="color: #800080;">;</span>
<span style="color: #800080;">}</span></pre>
<p>The only thing is left is to release the temporary reference early enough, but we have a filter graph, don&#8217;t we? What is typically done with a filter graph, adding a filter right? And it is a controlling application which has its own reference, who adds filters so we are safe to release temporary reference in <a href="http://msdn.microsoft.com/en-us/library/dd390016(VS.85).aspx">IFilterGraph::AddFilter</a> or <a href="http://msdn.microsoft.com/en-us/library/dd390087(VS.85).aspx">IGraphBuilder::AddSourceFilter</a> (actually it would not hurt to add this in other methods as well):</p>
<pre>STDMETHOD<span style="color: #808030;">(</span>AddFilter<span style="color: #808030;">)</span><span style="color: #808030;">(</span>IBaseFilter<span style="color: #808030;">*</span> pFilter<span style="color: #808030;">,</span> <span style="color: #603000;">LPCWSTR</span> pszName<span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    _Z4<span style="color: #808030;">(</span>atlTraceCOM<span style="color: #808030;">,</span> <span style="color: #008c00;">4</span><span style="color: #808030;">,</span> _T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">pszName </span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">%s</span><span style="color: #0f69ff;">\"</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #603000;">CString</span><span style="color: #808030;">(</span>pszName<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    ReleaseTemporaryUnknown<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// &lt;&lt;--------------------------</span>
    <span style="color: #800000; font-weight: bold;">return</span> m_pInnerFilterGraph2<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>AddFilter<span style="color: #808030;">(</span>pFilter<span style="color: #808030;">,</span> pszName<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span></pre>
<p>Additionally, the spy also implements now <a href="http://msdn.microsoft.com/en-us/library/dd390170(VS.85).aspx">IMediaControl</a> interface and traces calls to log file, it is convenient.</p>
<p>A partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/FilterGraphSpy.dll?format=raw">included</a>.</p>
<p>reg-FilterGraphSpy.dll.bat and unreg-FilterGraphSpy.dll.bat files <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace">in SVN</a> are convenient batch files to register and unregister the spy with the operating system.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/793/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DirectShow Filter Graph Spy &#8211; CLSID_FilterGraphNoThread</title>
		<link>http://alax.info/blog/784</link>
		<comments>http://alax.info/blog/784#comments</comments>
		<pubDate>Thu, 29 Jan 2009 21:11:45 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[spy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=784</guid>
		<description><![CDATA[At the time of original implementation I intentionally left off a variation of Filter Graph Manager that runs on application thread, CLSID_FilterGraphNoThread. MSDN says:
CLSID_FilterGraphNoThread creates the Filter Graph Manager on the application&#8217;s thread. If you use this CLSID, the thread that calls CoCreateInstance must have a message loop that dispatches messages; otherwise, deadlocks can occur. [...]]]></description>
			<content:encoded><![CDATA[<p>At the time of <a href="http://alax.info/blog/777">original implementation</a> I intentionally left off a variation of <a href="http://msdn.microsoft.com/en-us/library/dd375786(VS.85).aspx">Filter Graph Manager</a> that runs on application thread, CLSID_FilterGraphNoThread. MSDN says:</p>
<p style="padding-left: 30px;">CLSID_FilterGraphNoThread creates the Filter Graph Manager on the application&#8217;s thread. If you use this CLSID, the thread that calls CoCreateInstance must have a message loop that dispatches messages; otherwise, deadlocks can occur. Also, before the application thread exits, it must release the Filter Graph Manager and all graph objects (such as filters, pins, reference clocks, and so forth).</p>
<p>I have never needed to use this CLSID (by the way Windows SDK has one more CLSID &#8211; CLSID_FilterGraphPrivateThread &#8211; but it does not seem to be documented) and for this reason I left it for the time a need in it comes up. However it appeared that this CLSID was not created just for fun, there was a need in it. Filter graphs of Windows Media Player playing well known Windows&#8217; clock.avi appeared to be not published on <a href="http://msdn.microsoft.com/en-us/library/ms684004%28VS.85%29.aspx">Running Object Table</a>. Why?</p>
<p><a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx">Process Monitor</a> showed clearly that Windows Media Player created filter graph through CLSID_FilterGraphNoThread and quite obviously it was not intercepted by <a href="http://alax.info/blog/777">Filter Graph Spy</a> (still I wonder what made it different previous time when I could see WMP&#8217;s graph).</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/01/29-image001.png"><img class="alignnone size-medium wp-image-785" title="Another Windows Media Player Filter Graph" src="http://alax.info/blog/wp-content/uploads/2009/01/29-image001-300x119.png" alt="" width="300" height="119" /></a></p>
<p><span id="more-784"></span></p>
<p>In order to extend spy&#8217;s support to CLSID_FilterGraphNoThread I moved most of the code from CSpy COM class into CSpyT template class and derived two COM classes from it, CSpy and CNoThreadSpy, in order to cover and &#8220;COM Treat As&#8221; both DirectShow/Quartz COM classes.</p>
<pre><span style="color: #3f5fbf;">////////////////////////////////////////////////////////////</span>
<span style="color: #696969;">// CSpy</span>

<span style="color: #800000; font-weight: bold;">class</span> ATL_NO_VTABLE CSpy <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CSpyT<span style="color: #800080;">&lt;</span>CSpy<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>CLSID_FilterGraph<span style="color: #800080;">&gt;</span><span style="color: #808030;">,</span>
    <span style="color: #800000; font-weight: bold;">public</span> CComCoClass<span style="color: #800080;">&lt;</span>CSpy<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>CLSID_Spy<span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
    <span style="color: #800000; font-weight: bold;">enum</span> <span style="color: #800080;">{</span> IDR <span style="color: #808030;">=</span> IDR_SPY <span style="color: #800080;">}</span><span style="color: #800080;">;</span>

<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
<span style="color: #696969;">// CSpy</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span>

OBJECT_ENTRY_AUTO<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>Spy<span style="color: #808030;">)</span><span style="color: #808030;">,</span> CSpy<span style="color: #808030;">)</span>

<span style="color: #3f5fbf;">////////////////////////////////////////////////////////////</span>
<span style="color: #696969;">// CNoThreadSpy</span>

<span style="color: #800000; font-weight: bold;">class</span> ATL_NO_VTABLE CNoThreadSpy <span style="color: #800080;">:</span>
    <span style="color: #800000; font-weight: bold;">public</span> CSpyT<span style="color: #800080;">&lt;</span>CNoThreadSpy<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>CLSID_FilterGraphNoThread<span style="color: #800080;">&gt;</span><span style="color: #808030;">,</span>
    <span style="color: #800000; font-weight: bold;">public</span> CComCoClass<span style="color: #800080;">&lt;</span>CNoThreadSpy<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>CLSID_NoThreadSpy<span style="color: #800080;">&gt;</span>
<span style="color: #800080;">{</span>
<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
    <span style="color: #800000; font-weight: bold;">enum</span> <span style="color: #800080;">{</span> IDR <span style="color: #808030;">=</span> IDR_NOTHREADSPY <span style="color: #800080;">}</span><span style="color: #800080;">;</span>

<span style="color: #800000; font-weight: bold;">public</span><span style="color: #e34adc;">:</span>
<span style="color: #696969;">// CNoThreadSpy</span>
<span style="color: #800080;">}</span><span style="color: #800080;">;</span>

OBJECT_ENTRY_AUTO<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>NoThreadSpy<span style="color: #808030;">)</span><span style="color: #808030;">,</span> CNoThreadSpy<span style="color: #808030;">)</span></pre>
<p>A partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/FilterGraphSpy.dll?format=raw">included</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/784/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DirectShow Filter Graph Spy</title>
		<link>http://alax.info/blog/777</link>
		<comments>http://alax.info/blog/777#comments</comments>
		<pubDate>Wed, 28 Jan 2009 20:46:01 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[aggregation]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[DirectShow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[spy]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=777</guid>
		<description><![CDATA[Inspired by a post on DirectShow Development Forum, it is sometimes useful to find out how certain application is using DirectShow to capture live video and/or audio, or play certain file etc. Filter graph topology, details about media types on the pins, used interfaces and call order. There is quite an easy step for the [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/4a448884-9062-4e45-b73e-2c9ab681ade0">a post on DirectShow Development Forum</a>, it is sometimes useful to find out how certain application is using DirectShow to capture live video and/or audio, or play certain file etc. Filter graph topology, details about media types on the pins, used interfaces and call order. There is quite an easy step for the developer to spy over running filter graphs system wide by connecting <a href="http://msdn.microsoft.com/en-us/library/ms680573.aspx">Component Object Model</a> (COM) &#8220;Treat As&#8221; feature with filter graph remoting through <a href="http://msdn.microsoft.com/en-us/library/ms684004(VS.85).aspx">Running Object Table</a> and connecting to remote process graphs <a href="http://msdn.microsoft.com/en-us/library/dd390650(VS.85).aspx">using GraphEdit</a> utility.</p>
<p>Who could imagine Windows Media Player to build such a filter graph for a video and audio Windows Media file? SRS Wow DMO, equalizer, analyzer and stuff?</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2009/01/28-image001.png"><img class="alignnone size-medium wp-image-778" title="Windows Media Player Filter Graph" src="http://alax.info/blog/wp-content/uploads/2009/01/28-image001-300x146.png" alt="" width="300" height="146" /></a></p>
<p><span id="more-777"></span></p>
<p>There are many tricks to catch the created filter graph but the most legit is the mentioned above &#8220;Treat As&#8221; feature to emulate certain COM class identifier (CLSID) through another coclass. COM API offers <a href="http://msdn.microsoft.com/en-us/library/ms693452(VS.85).aspx">CoTreatAsClass</a> and <a href="http://msdn.microsoft.com/en-us/library/ms694494(VS.85).aspx">CoGetTreatAsClass</a> functions to manage the emulation. To emulate DirectShow&#8217;s <a href="http://msdn.microsoft.com/en-us/library/ms783670(VS.85).aspx">CLSID_FilterGraph</a> through my CSpy class, I am adding the following code to the default COM registration process for the utility DLL:</p>
<pre><span style="font-weight: bold; color: #800000;">static</span> HRESULT <span style="color: #603000;">WINAPI</span> UpdateRegistry<span style="color: #808030;">(</span><span style="color: #603000;">BOOL</span> bRegister<span style="color: #808030;">)</span> <span style="font-weight: bold; color: #800000;">throw</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    _Z2<span style="color: #808030;">(</span>atlTraceRegistrar<span style="color: #808030;">,</span> <span style="color: #008c00;">2</span><span style="color: #808030;">,</span> _T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">bRegister </span><span style="color: #0f69ff;">%d</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> bRegister<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    _ATLTRY
    <span style="color: #800080;">{</span>
        CLSID TreatAsClassIdentifier<span style="color: #800080;">;</span>
        HRESULT nCoGetTreatAsClassResult <span style="color: #808030;">=</span> CoGetTreatAsClass<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>TreatAsClassIdentifier<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        __C<span style="color: #808030;">(</span>nCoGetTreatAsClassResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        __D<span style="color: #808030;">(</span><span style="color: #808030;">!</span>bRegister <span style="color: #808030;">|</span><span style="color: #808030;">|</span> nCoGetTreatAsClassResult <span style="color: #808030;">!</span><span style="color: #808030;">=</span> S_OK <span style="color: #808030;">|</span><span style="color: #808030;">|</span> TreatAsClassIdentifier <span style="color: #808030;">=</span><span style="color: #808030;">=</span> GetObjectCLSID<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> E_UNNAMED<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        <span style="font-weight: bold; color: #800000;">if</span><span style="color: #808030;">(</span><span style="color: #808030;">!</span>bRegister <span style="color: #808030;">&amp;</span><span style="color: #808030;">&amp;</span> nCoGetTreatAsClassResult <span style="color: #808030;">=</span><span style="color: #808030;">=</span> S_OK<span style="color: #808030;">)</span>
            __C<span style="color: #808030;">(</span>CoTreatAsClass<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">,</span> CLSID_NULL<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        _A<span style="color: #808030;">(</span>_pAtlModule<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        UpdateRegistryFromResource<span style="color: #800080;">&lt;</span>CSpy<span style="color: #800080;">&gt;</span><span style="color: #808030;">(</span>bRegister<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
        <span style="font-weight: bold; color: #800000;">if</span><span style="color: #808030;">(</span>bRegister<span style="color: #808030;">)</span>
            __C<span style="color: #808030;">(</span>CoTreatAsClass<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">,</span> GetObjectCLSID<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800080;">}</span>
    _ATLCATCH<span style="color: #808030;">(</span>Exception<span style="color: #808030;">)</span>
    <span style="color: #800080;">{</span>
        _C<span style="color: #808030;">(</span>Exception<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    <span style="color: #800080;">}</span>
    <span style="font-weight: bold; color: #800000;">return</span> S_OK<span style="color: #800080;">;</span>
<span style="color: #800080;">}</span></pre>
<p>The idea is that the emulation is enabled in case it was not enabled before or it was already enabled through our coclass. Every time an application cocreates an instance of Filter Graph Manager (FGM), CSpy class will be created instead.</p>
<p>Still as we have no plans to reinvent one of the most important DirectShow objects, we have to embed the original FGM insde to forward the calls to. The proper place in the ATL C++ code is FinalConstruct and what we actually do there is instantiating an aggregated FGM from the original in-process server. The safest would be to query registry for the original host, but we know it&#8217;s hosted by quartz.dll and it seems to be safe to hardcode:</p>
<pre><span style="color: #603000;">HINSTANCE</span> hModule <span style="color: #808030;">=</span> CoLoadLibrary<span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">quartz.dll</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> TRUE<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
_ATLTRY
<span style="color: #800080;">{</span>
    <span style="color: #800000; font-weight: bold;">typedef</span> HRESULT <span style="color: #808030;">(</span><span style="color: #603000;">WINAPI</span> <span style="color: #808030;">*</span>DLLGETCLASSOBJECT<span style="color: #808030;">)</span><span style="color: #808030;">(</span>REFCLSID<span style="color: #808030;">,</span> REFIID<span style="color: #808030;">,</span> <span style="color: #603000;">VOID</span><span style="color: #808030;">*</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    DLLGETCLASSOBJECT DllGetClassObject <span style="color: #808030;">=</span> <span style="color: #808030;">(</span>DLLGETCLASSOBJECT<span style="color: #808030;">)</span> <span style="color: #400000;">GetProcAddress</span><span style="color: #808030;">(</span>hModule<span style="color: #808030;">,</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">DllGetClassObject</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    __E<span style="color: #808030;">(</span>DllGetClassObject<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    CComPtr<span style="color: #800080;">&lt;</span>IClassFactory<span style="color: #800080;">&gt;</span> pClassFactory<span style="color: #800080;">;</span>
    __C<span style="color: #808030;">(</span>DllGetClassObject<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>IClassFactory<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">(</span><span style="color: #603000;">VOID</span><span style="color: #808030;">*</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #808030;">&amp;</span>pClassFactory<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    _A<span style="color: #808030;">(</span>pClassFactory<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    CComPtr<span style="color: #800080;">&lt;</span>IUnknown<span style="color: #800080;">&gt;</span> pUnknown<span style="color: #800080;">;</span>
    __C<span style="color: #808030;">(</span>pClassFactory<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>CreateInstance<span style="color: #808030;">(</span>GetControllingUnknown<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">__uuidof</span><span style="color: #808030;">(</span>IUnknown<span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #808030;">(</span><span style="color: #603000;">VOID</span><span style="color: #808030;">*</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #808030;">&amp;</span>pUnknown<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
    CComQIPtr<span style="color: #800080;">&lt;</span>IFilterGraph2<span style="color: #800080;">&gt;</span> pFilterGraph2 <span style="color: #808030;">=</span> pUnknown<span style="color: #800080;">;</span>
    __D<span style="color: #808030;">(</span>pFilterGraph2<span style="color: #808030;">,</span> E_NOINTERFACE<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>What is remained at the point is to implement IFilterGraph2 (along with inherited IGraphBuilder and IFilterGraph) and forward all incoming calls to the inner aggregated object. It would also be helpful to trace calls to a log file C:\FilterGraphSpy.log:</p>
<pre>2009-01-28 22:07:51	4456	5656	dllmain.h(29): CFilterGraphSpyModule::CFilterGraphSpyModule: this 0x01cd327c
2009-01-28 22:07:51	4456	5656	Spy.h(75): CSpy::CSpy: this 0x01ce297c
2009-01-28 22:07:51	4456	5656	Spy.h(132): CSpy::AddFilter: pszName "C:\Documents and Settings\John Doe\Desktop\Melissa Cherry Interview.wmv"
2009-01-28 22:07:51	4456	5656	Spy.h(142): CSpy::EnumFilters: ...
2009-01-28 22:07:51	4456	5656	Spy.h(132): CSpy::AddFilter: pszName "ffdshow Audio Decoder"
2009-01-28 22:07:51	4456	5656	Spy.h(152): CSpy::ConnectDirect: ...
2009-01-28 22:07:51	4456	5656	Spy.h(137): CSpy::RemoveFilter: ...
2009-01-28 22:07:51	4456	5656	Spy.h(132): CSpy::AddFilter: pszName "WMAudio Decoder DMO"
2009-01-28 22:07:51	4456	5656	Spy.h(152): CSpy::ConnectDirect: ...
2009-01-28 22:07:51	4456	5656	Spy.h(142): CSpy::EnumFilters: ...</pre>
<p>And additionally, the filter graph is immediately published on the ROT and is accessible with <a href="http://msdn.microsoft.com/en-us/library/dd390650(VS.85).aspx">GraphEdit</a>. Feel free to spy over graphs system wide.</p>
<p>A partial Visual C++ .NET 2008 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy">available from SVN</a>, release binary <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/FilterGraphSpy.dll?format=raw">included</a>.</p>
<div style="background-color: #efa; border: 1px solid #ffc; padding: 2px; ">To install Filter Graph Spy:</p>
<ul>
<li>download the binary DLL from version control repository (<em>DirectShowSpy.dll</em> &#8211; <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/Win32/DirectShowSpy.dll?format=raw">Win32</a>, <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/Release%20Trace/x64/DirectShowSpy.dll?format=raw">x64</a>)</li>
<li>COM register the DLL on target system, for example from command line using <em>regsvr32</em> utility &#8220;<em>regsvr32 </em><em>DirectShowSpy</em><em>.dll</em>&#8221; (administrative privilege elevation required on Vista)</li>
<li>on some operating systems (MS Vista in particular) it is also required to have SDK&#8217;s <em>proppage.dll</em> available in the system, see <a href="http://alax.info/blog/944">Vista related post</a> for more details</li>
</ul>
<p>To uninstall:</p>
<ul>
<li>use &#8220;<em>regsvr32 /u&#8221;</em> utility to unregister the DLL, close all DirectShow based applications or reboot OS, and delete the file; see also a <a href="http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/20c7f4a1-b920-4420-9342-9534e5144769">related thread on MSDN Forums</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/777/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
