<?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; C++</title>
	<atom:link href="http://alax.info/blog/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://alax.info/blog</link>
	<description>// Software Production Line</description>
	<lastBuildDate>Fri, 03 Feb 2012 22:49:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Common Controls: Versions, Compatibility, WTL</title>
		<link>http://alax.info/blog/1306</link>
		<comments>http://alax.info/blog/1306#comments</comments>
		<pubDate>Sun, 30 Oct 2011 19:55:52 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[WTL]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[compatibility]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1306</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1306" title="Common Controls: Versions, Compatibility, WTL"></a>An application appears to be not working in Windows XP in a weird way: rebar control appeared to fail showing up. Where the application is expected to look much nicer with rebar control as a container for menu (implemented as &#8230;<p class="read-more"><a href="http://alax.info/blog/1306">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1306" title="Common Controls: Versions, Compatibility, WTL"></a><p>An application appears to be not working in Windows XP in a weird way: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774373%28v=vs.85%29.aspx">rebar control</a> appeared to fail showing up.</p>
<p><img class="alignnone size-full wp-image-1310" title="Rebar Failed" src="http://alax.info/blog/wp-content/uploads/2011/10/Image003.png" alt="" width="640" height="238" /></p>
<p>Where the application is expected to look much nicer with rebar control as a container for menu (implemented as command bar WTL control) and toolbar with buttons:</p>
<p><img class="alignnone size-full wp-image-1309" title="Rebar Succeeded" src="http://alax.info/blog/wp-content/uploads/2011/10/Image0022.png" alt="" width="640" height="238" /></p>
<p>A WTL sample project generated by a Visual Studio wizard would never give such effect, and the bug was a combination of factors:</p>
<ol>
<li>An application built with a newer version of Windows SDK, which includes support for features (Windows Vista+ Common Controls) that are more recent than production environment (Windows XP); the application targets to Windows Vista+ environment too (<em>_WIN32_WINNT</em> &gt;= <em>0&#215;0600</em>)</li>
<li>Compatibility issues of Common Controls library</li>
<li>WTL version (7.5), which did not yet include a workaround for the problem</li>
</ol>
<p>The problem, which caused the bug directly was the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774393%28v=vs.85%29.aspx">REBARBANDINFO structure</a> and its use as an argument with Common Controls API. As MSDN shows, the structure was amended twice with additional fields.</p>
<p>One of the way to support multiple versions of the structure definition, and to resolve compatibility issues, is to embed structure size into structure payload. In fact, <em>REBARBANDINFO::cbSize</em> member is there exactly for this reason.</p>
<p>The application is normally filling <em>cbSize</em> with the maximal known structure size and fills the rest of the fields respectively. The API is expected to be checking <em>cbSize</em> member and be detecting API version compatibility scenarios:</p>
<ol>
<li><em>cbSize</em> holds exactly the value the API expects (that is, the maximal value known/defined to the API) &#8211; the simplest scenario where the API and the application are on the same page, both are using the same versions of the &#8220;protocol&#8221;/interface.</li>
<li><em>cbSize</em> is smaller than API can support &#8211; the API sees that it is dealing with a sort of legacy application which cannot utilize all available features, and the API acts respectively supporting the older part of the protocol, and keeping defaults or &#8220;old look&#8221; for the rest of implementation. This addresses backward compatibility: the newer API works with apps designed for older version of the API</li>
<li><em>cbSize</em> is greater then API can support &#8211; the API sees that the application is already aware of newer version API and is possibly requesting some of the missing features. The API might be ignoring the unsupported part in assumption that API evolution tool place keeping some compatibility in mind, and still do the best it can with the existing implementation. Or, the API might just fail to work.</li>
</ol>
<p>The latter item #3 is the scenario here with rebar control. The application is using Windows Vista version of <em>REBARBANDINFO</em> structure and Windows XP implementation choses to completely fail.</p>
<p>While it does not seem to be directly a bug, this attitude is definitely not developer friendly: there is no reason for the control to not work in its best and default way. Having API acting this way, each developer using the API needs to take care of the situation explicitly: whenever Windows Vista enabled application needs to be able to run in Windows XP system, the code around <em>REBARBANDINFO</em> would look like this:</p>
<pre style="color: #000000; background: #ffffff;">REBARBANDINFO BandInformation <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> <span style="color: #800000; font-weight: bold;">sizeof</span> BandInformation<span style="color: #808030;">,</span> RBBIM_LPARAM <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">if</span><span style="color: #004a43;"> _WIN32_WINNT </span><span style="color: #808030;">&gt;</span><span style="color: #808030;">=</span><span style="color: #004a43;"> 0x0600</span>
<span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>GetOsVersion<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #808030;">&lt;</span> <span style="color: #008000;">0x00060000</span> <span style="color: #808030;">|</span><span style="color: #808030;">|</span> GetCommCtrlVersion<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #808030;">&lt;</span> <span style="color: #008000;">0x00060000</span><span style="color: #808030;">)</span> <span style="color: #696969;">// pre-Vista, Common Controls pre-6.0</span>
    BandInformation<span style="color: #808030;">.</span>cbSize <span style="color: #808030;">=</span> REBARBANDINFO_V6_SIZE<span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">endif</span><span style="color: #696969;">// _WIN32_WINNT &gt;= 0x0600</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BOOL</span> bGetBandInfoResult <span style="color: #808030;">=</span> Rebar<span style="color: #808030;">.</span>GetBandInfo<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>BandInformation<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>If the API was nicer to developers, the code would be plain and simple:</p>
<pre style="color: #000000; background: #ffffff;">REBARBANDINFO BandInformation <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> <span style="color: #800000; font-weight: bold;">sizeof</span> BandInformation<span style="color: #808030;">,</span> RBBIM_LPARAM <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BOOL</span> bGetBandInfoResult <span style="color: #808030;">=</span> Rebar<span style="color: #808030;">.</span>GetBandInfo<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>BandInformation<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>To address this problem, <a href="http://wtl.sourceforge.net/">WTL</a> 8.0 comes up with <em>RunTimeHelper</em> namespace and its <em>SizeOf_REBARBANDINFO</em> function. It takes care of details for the developer choosing the proper size of the structure on runtime. The code is being taken back to a simpler shape:</p>
<pre style="color: #000000; background: #ffffff;">REBARBANDINFO BandInformation <span style="color: #808030;">=</span> <span style="color: #800080;">{</span> RunTimeHelper<span style="color: #800080;">::</span>SizeOf_REBARBANDINFO<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> RBBIM_LPARAM <span style="color: #800080;">}</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">const</span> <span style="color: #603000;">BOOL</span> bGetBandInfoResult <span style="color: #808030;">=</span> Rebar<span style="color: #808030;">.</span>GetBandInfo<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>BandInformation<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>All in all:</p>
<ul>
<li>be aware of compatibility issues (same scenario exists with other SDK structures: <em>LVGROUP</em>, <em>LVTILEINFO</em>, <em>MCHITTESTINFO</em>, <em>NONCLIENTMETRICS</em> and other).</li>
<li>use latest version of WTL to have things worked around for you where Microsoft developers were not kid enough to provide perfect API</li>
<li>be aware and take advantage of WTL&#8217;s <em>RunTimeHelper</em> class</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1306/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample: Simultaneous Audio Playback via Waveform Audio (waveOut) API</title>
		<link>http://alax.info/blog/1291</link>
		<comments>http://alax.info/blog/1291#comments</comments>
		<pubDate>Wed, 12 Oct 2011 17:15:50 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[playback]]></category>
		<category><![CDATA[waveOut]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1291</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1291" title="Sample: Simultaneous Audio Playback via Waveform Audio (waveOut) API"></a>The minimalistic sample demonstrates support of [deprecated] Waveform Audio API for multiple playback streams. Depending on command line parameters, the application starts threads to open audio hardware using separate waveOutOpen call and stream one or more generated sine waves: 1,000 &#8230;<p class="read-more"><a href="http://alax.info/blog/1291">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1291" title="Sample: Simultaneous Audio Playback via Waveform Audio (waveOut) API"></a><p>The minimalistic sample demonstrates support of [deprecated] <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd757715%28v=VS.85%29.aspx">Waveform Audio API</a> for multiple playback streams.</p>
<p>Depending on command line parameters, the application starts threads to open audio hardware using separate <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd743866%28v=VS.85%29.aspx">waveOutOpen</a> call and stream one or more generated sine waves:</p>
<ul>
<li>1,000 Hz sine wave as 22,050 Hz, Mono, 16-bit PCM (command line parameter &#8220;a&#8221;)</li>
<li>5,000 Hz sine wave as 32,000 Hz, Mono, 16-bit PCM (command line parameter &#8220;b&#8221;)</li>
<li>15,000 Hz sine wave as 44,100 Hz, Mono, 16-bit PCM (command line parameter &#8220;c&#8221;)</li>
</ul>
<pre style="color: #000000; background: #ffffff;">Check<span style="color: #808030;">(</span><span style="color: #400000;">waveOutOpen</span><span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>hWaveOut<span style="color: #808030;">,</span> WAVE_MAPPER<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>WaveFormatEx<span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">,</span> CALLBACK_NULL<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLASSERT<span style="color: #808030;">(</span>hWaveOut<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
WAVEHDR<span style="color: #808030;">*</span> pWaveHeader<span style="color: #800080;">;</span>
<span style="color: #603000;">HGLOBAL</span> hWaveHeader <span style="color: #808030;">=</span> <span style="color: #808030;">(</span>WAVEHDR<span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #400000;">GlobalAlloc</span><span style="color: #808030;">(</span>GMEM_MOVEABLE <span style="color: #808030;">|</span> GMEM_SHARE<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pWaveHeader <span style="color: #808030;">+</span> WaveFormatEx<span style="color: #808030;">.</span>nAvgBytesPerSec <span style="color: #808030;">*</span> <span style="color: #008c00;">10</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pWaveHeader <span style="color: #808030;">=</span> <span style="color: #808030;">(</span>WAVEHDR<span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #400000;">GlobalLock</span><span style="color: #808030;">(</span>hWaveHeader<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_THROW<span style="color: #808030;">(</span>pWaveHeader<span style="color: #808030;">,</span> E_OUTOFMEMORY<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>lpData <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">LPSTR</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #603000;">BYTE</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span>pWaveHeader <span style="color: #808030;">+</span> <span style="color: #008c00;">1</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwBufferLength <span style="color: #808030;">=</span> WaveFormatEx<span style="color: #808030;">.</span>nAvgBytesPerSec <span style="color: #808030;">*</span> <span style="color: #008c00;">10</span><span style="color: #800080;">;</span>
<span style="color: #696969;">//pWaveHeader-&gt;dwUser = </span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwFlags <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span>
pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwLoops <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">region Generate Actual Data</span>
<span style="color: #800080;">{</span>
    <span style="color: #603000;">SHORT</span><span style="color: #808030;">*</span> pnData <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">SHORT</span><span style="color: #808030;">*</span><span style="color: #808030;">)</span> pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>lpData<span style="color: #800080;">;</span>
    SIZE_T nDataCount <span style="color: #808030;">=</span> pWaveHeader<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>dwBufferLength <span style="color: #808030;">/</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pnData<span style="color: #800080;">;</span>
    <span style="color: #800000; font-weight: bold;">for</span><span style="color: #808030;">(</span>SIZE_T nIndex <span style="color: #808030;">=</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span> nIndex <span style="color: #808030;">&lt;</span> nDataCount<span style="color: #800080;">;</span> nIndex<span style="color: #808030;">+</span><span style="color: #808030;">+</span><span style="color: #808030;">)</span>
    pnData<span style="color: #808030;">[</span>nIndex<span style="color: #808030;">]</span> <span style="color: #808030;">=</span> <span style="color: #808030;">(</span><span style="color: #603000;">SHORT</span><span style="color: #808030;">)</span> <span style="color: #808030;">(</span><span style="color: #008c00;">32000</span> <span style="color: #808030;">*</span> <span style="color: #603000;">sin</span><span style="color: #808030;">(</span><span style="color: #008000;">1.0</span> <span style="color: #808030;">*</span> nIndex <span style="color: #808030;">/</span> WaveFormatEx<span style="color: #808030;">.</span>nSamplesPerSec <span style="color: #808030;">*</span> nFrequency <span style="color: #808030;">*</span> <span style="color: #008c00;">2</span> <span style="color: #808030;">*</span> M_PI<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">endregion </span>
Check<span style="color: #808030;">(</span>waveOutPrepareHeader<span style="color: #808030;">(</span>hWaveOut<span style="color: #808030;">,</span> pWaveHeader<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pWaveHeader<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
Check<span style="color: #808030;">(</span>waveOutWrite<span style="color: #808030;">(</span>hWaveOut<span style="color: #808030;">,</span> pWaveHeader<span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">sizeof</span> <span style="color: #808030;">*</span>pWaveHeader<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #400000;">GlobalUnlock</span><span style="color: #808030;">(</span>hWaveHeader<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>The operating system is supposed to mix the waves, which can be easily perceived taking place. It is possible to run the application with multiple waveforms within a process, e.g. &#8220;abc&#8221; command line parameter, and/or start multiple instances of the application.</p>
<p>A binary [<a href="http://www.alax.info/svn/public/trunk/Utilities/WaveOutMultiPlay/Release/WaveOutMultiPlay.exe">Win32</a>] and partial Visual C++ .NET 2010 <a href="http://www.alax.info/trac/public/browser/trunk/Utilities/WaveOutMultiPlay">source code</a> are available from SVN.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1291/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Utility Clearance: Generate PCM .WAV File</title>
		<link>http://alax.info/blog/1274</link>
		<comments>http://alax.info/blog/1274#comments</comments>
		<pubDate>Thu, 25 Aug 2011 20:48:13 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[.WAV]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[dB]]></category>
		<category><![CDATA[generation]]></category>
		<category><![CDATA[Loudness]]></category>
		<category><![CDATA[PCM]]></category>
		<category><![CDATA[sine]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[wavdest]]></category>
		<category><![CDATA[waveform]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1274</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1274" title="Utility Clearance: Generate PCM .WAV File"></a>GeneratePcmWavFile tool is generating PCM .WAV files with requested parameters, silent or with a sine wave data. The utility uses WavDest SDK Sample as a multiplexer, so it is expected to be available. It is possible to define the following &#8230;<p class="read-more"><a href="http://alax.info/blog/1274">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1274" title="Utility Clearance: Generate PCM .WAV File"></a><p>GeneratePcmWavFile tool is generating PCM .WAV files with requested parameters, silent or with a sine wave data. The utility uses <a href="http://msdn.microsoft.com/en-us/library/dd390969%28v=vs.85%29.aspx">WavDest SDK Sample</a> as a multiplexer, so it is expected to be available.</p>
<p>It is possible to define the following audio data parameters:</p>
<ul>
<li>sampling frequency, number of samples per second, such as 44100 or 48000</li>
<li>number of channels; the utility does not constrain this to be stereo or 5.1, it will be able to create 64 or 128 channel audio data as well</li>
<li>8 or 16 bit audio samples</li>
<ul>
<li>16-bit PCM only: sine wave signal parameters, frequency in Hz and amplitude/loudness relative to full scale, that is 0 dB is maximal loudness, and an argument of 23 will result in -23 dB loud audio (such as -23 dbFS, also see <a href="http://tech.ebu.ch/loudness">EBU R128 Specification</a>, the signal depending on frequency may be used a reference source for normalized -23 LUFS audio)</li>
</ul>
<li>file duration in seconds</li>
</ul>
<pre>Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\&gt;GeneratePcmWavFile.exe
Syntax: GeneratePcmWavFile &lt;options&gt; &lt;output-path&gt;
  /s:N: Sampling Rate N, Hz
  /c:N: Channel Count N
  /b:N: Sample Bit Count N, 8 or 16
  /t:N: Length N, seconds
  /f:N: Sine Signal Frequency N, Hz
  /l:N: Sine Signal Loudness N, dB below full scale
  /n:N: Noise Signal Loudness N, dB below full scale</pre>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/08/Image0011.png"><img class="alignnone size-medium wp-image-1275" title="-23 dBFS Generated Audio Playback" src="http://alax.info/blog/wp-content/uploads/2011/08/Image0011-320x248.png" alt="" width="320" height="248" /></a></p>
<p>A binary [<a href="http://alax.info/trac/public/browser/trunk/Utilities/GeneratePcmWavFile/Win32/Release/GeneratePcmWavFile.exe?format=raw">Win32</a>] and partial Visual C++ .NET 2010 <a href="http://alax.info/trac/public/browser/trunk/Utilities/GeneratePcmWavFile">source code</a> are available from SVN.</p>
<p>UPDATE: An extra /n parameter lets the application add random noise within provided loudness parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1274/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Utility Clearance: Artificial CPU Load</title>
		<link>http://alax.info/blog/1271</link>
		<comments>http://alax.info/blog/1271#comments</comments>
		<pubDate>Thu, 25 Aug 2011 20:20:44 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1271</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1271" title="Utility Clearance: Artificial CPU Load"></a>The LoadCpu tool creates one or more threads to waste CPU cycles and emulate slower environment, such as for testing and troubleshooting. There has been a great deal of similar tools out there, and this one in particular is convenient/special &#8230;<p class="read-more"><a href="http://alax.info/blog/1271">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1271" title="Utility Clearance: Artificial CPU Load"></a><p>The <em>LoadCpu</em> tool creates one or more threads to waste CPU cycles and emulate slower environment, such as for testing and troubleshooting. There has been a great deal of similar tools out there, and this one in particular is convenient/special as it takes process affinity mask as a parameter.</p>
<p>That is, /a:NN defines affinity mask, e.g. 5 for 1st and 3rd CPU (two threads), and /r:MM defines [roughly] CPU load time in percent.</p>
<pre>Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\&gt;loadcpu /a:5 /r:25
System Affinity Mask: 0xff
Process Affinity Mask: 0x05
Rate: 25%</pre>
<p><img class="alignnone size-full wp-image-1272" title="Utility's CPU Load" src="http://alax.info/blog/wp-content/uploads/2011/08/Image001.png" alt="" width="566" height="391" /></p>
<p>A binary [<a href="http://alax.info/trac/public/browser/trunk/Utilities/LoadCpu/Win32/Release/LoadCpu.exe?format=raw">Win32</a>] and partial Visual C++ .NET 2010 <a href="http://alax.info/trac/public/browser/trunk/Utilities/LoadCpu">source code</a> are available from SVN.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1271/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ATLENSURE_SUCCEEDED double failure</title>
		<link>http://alax.info/blog/1244</link>
		<comments>http://alax.info/blog/1244#comments</comments>
		<pubDate>Tue, 19 Jul 2011 17:18:13 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[inline]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1244</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1244" title="ATLENSURE_SUCCEEDED double failure"></a>A colleague pointed out that code snippet in previous post is misusing ATL&#8217;s ATLENSURE_SUCCEEDED macro making it [possibly] evaluate its argument twice in case of failure, that is evaluating into failure HRESULT code. As it is defined like this: #define &#8230;<p class="read-more"><a href="http://alax.info/blog/1244">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1244" title="ATLENSURE_SUCCEEDED double failure"></a><p>A colleague pointed out that code snippet in <a href="http://alax.info/blog/1241">previous post</a> is misusing ATL&#8217;s ATLENSURE_SUCCEEDED macro making it [possibly] evaluate its argument twice in case of failure, that is evaluating into failure HRESULT code. As it is defined like this:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">define</span><span style="color: #004a43;"> ATLENSURE_SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">hr</span><span style="color: #808030;">)</span><span style="color: #004a43;"> ATLENSURE_THROW</span><span style="color: #808030;">(</span><span style="color: #004a43;">SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">hr</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #004a43;"> hr</span><span style="color: #808030;">)</span></pre>
<p>It does things in a straightforward way, for a code line</p>
<pre style="color: #000000; background: #ffffff;">ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>pFilterGraph<span style="color: #808030;">.</span>CoCreateInstance<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>It is doing &#8220;let&#8217;s CoCreateInstance the thing and if it fails, let&#8217;s CoCreateInstance it again to find out error code&#8221;. Disassembly shows this clearly:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/07/Image0031.png"><img class="alignnone size-full wp-image-1245" title="ATLENSURE_SUCCEEDED evaluates the argument twice" src="http://alax.info/blog/wp-content/uploads/2011/07/Image0031.png" alt="" width="640" height="458" /></a></p>
<p>This is exactly another spin of the story previously happened with <a href="http://msdn.microsoft.com/en-us/library/ms680746%28VS.85%29.aspx">HRESULT_FROM_WIN32</a> macro and possibly a number of others. With it being originally a macro, SDK offered an option to override the definition by pre-defining INLINE_HRESULT_FROM_WIN32. This way a user might be explicitly requesting a safer definition while still leaving legacy code live with macro. See <a href="http://blogs.msdn.com/b/matthew_van_eerde/archive/2007/12/28/the-evolution-of-hresult-from-win32.aspx">more detailed story on this in Matthew&#8217;s blog</a>.</p>
<p>A tricky thing is that with successful execution the problem does not come up. In case of failure, it depends on the functions called, some with just repeat the error code, some will return a different code on second run, some might create less desired and expected consequences. So you can find yourself having written quite some code before you even suspect a problem.</p>
<p>Having identified the issue, there are a few solutions.</p>
<p>1. First of all, the original ATLENSURE_SUCCEEDED macro can still be used, provided that you don&#8217;t put expressions as arguments.</p>
<p>This is going to do just fine:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">const</span> HRESULT nCoCreateInstanceResult <span style="color: #808030;">=</span> pFilterGraph<span style="color: #808030;">.</span>CoCreateInstance<span style="color: #808030;">(</span>CLSID_FilterGraph<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>nCoCreateInstanceResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
<p>2. Second straightforward way is to replace the original ATL definition in ATL code (boo, woodenly)</p>
<p>3. As ATL code is checking for the macros to be already defined, and skipping its own definition in such case, it is possible to inject a safer private definition before including ATL headers (which would typically need one to do the define in stdafx.h):</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">define</span><span style="color: #004a43;"> ATLENSURE_SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">x</span><span style="color: #808030;">)</span><span style="color: #808030;">{</span><span style="color: #004a43;"> const HRESULT nResult </span><span style="color: #808030;">=</span><span style="color: #808030;">(</span><span style="color: #004a43;">x</span><span style="color: #808030;">)</span><span style="color: #808030;">;</span><span style="color: #004a43;"> ATLENSURE_THROW</span><span style="color: #808030;">(</span><span style="color: #004a43;">SUCCEEDED</span><span style="color: #808030;">(</span><span style="color: #004a43;">nResult</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #004a43;"> nResult</span><span style="color: #808030;">)</span><span style="color: #808030;">; </span><span style="color: #808030;">}</span>

<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">atlbase.h</span><span style="color: #800000;">&gt;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">atlstr.h</span><span style="color: #800000;">&gt;</span></pre>
<p>Pre-evaluating the argument into local variable is going to resolve the original multi-evaluation problem.</p>
<p>4. There might be a new inline function defined on top of the original macro, which will be used instead and which is free from the problem:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">inline</span> <span style="color: #603000;">VOID</span> ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>HRESULT nResult<span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>nResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span></pre>
<p>Either way, the correct code compiles into single argument evaluation and throws an exception with failure code immediately:</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/07/Image0041.png"><img class="alignnone size-full wp-image-1246" title="Corrected ATLENSURE_SUCCEEDED code" src="http://alax.info/blog/wp-content/uploads/2011/07/Image0041.png" alt="" width="640" height="333" /></a></p>
<p>Also, <del datetime="2011-07-20T05:21:51+00:00"><a href="https://connect.microsoft.com/VisualStudio/feedback/details/679899/atlensure-succeeded-macro-is-unsafe-for-use-with-evaluatable-arguments#details">vote for the suggestion on Microsoft Connect</a></del>. The issue is marked as fixed in future version of Visual Studio.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1244/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LogProcessExceptions: Minidumps on User Request</title>
		<link>http://alax.info/blog/1248</link>
		<comments>http://alax.info/blog/1248#comments</comments>
		<pubDate>Tue, 19 Jul 2011 14:20:57 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[.DMP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[minidump]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1248</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1248" title="LogProcessExceptions: Minidumps on User Request"></a>An updated version of LogProcessExceptions utility is given an additional option to create minidump .DMP files for debugged process on user request. This is in particular useful in conjunction with flag choices (on the previous page of the wizard). Partial &#8230;<p class="read-more"><a href="http://alax.info/blog/1248">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1248" title="LogProcessExceptions: Minidumps on User Request"></a><p>An updated version of <a href="http://alax.info/blog/1211">LogProcessExceptions</a> utility is given an additional option to create <a href="http://msdn.microsoft.com/en-us/library/d5zhxt22.aspx">minidump .DMP files</a> for debugged process on user request. This is in particular useful in conjunction with flag choices (on the previous page of the wizard).</p>
<p><a href="http://alax.info/blog/wp-content/uploads/2011/07/Image0032.png"><img class="alignnone size-full wp-image-1249" title="Minidump Creation Link" src="http://alax.info/blog/wp-content/uploads/2011/07/Image0032.png" alt="" width="513" height="400" /></a></p>
<p>Partial Visual C++ .NET 2010 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/LogProcessExceptions">available from SVN</a>, release binary included (<a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/LogProcessExceptions/_Bin/Win32/Release/LogProcessExceptions.exe?format=raw">Win32</a>, <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/LogProcessExceptions/_Bin/x64/Release/LogProcessExceptions.exe?format=raw">x64</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1248/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using IP Video Source programmatically as a standalone DirectShow Video Source Filter for JPEG and M-JPEG IP Cameras</title>
		<link>http://alax.info/blog/1241</link>
		<comments>http://alax.info/blog/1241#comments</comments>
		<pubDate>Sun, 17 Jul 2011 18:22:04 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[JPEG]]></category>
		<category><![CDATA[M-JPEG]]></category>
		<category><![CDATA[panasonic]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1241</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1241" title="Using IP Video Source programmatically as a standalone DirectShow Video Source Filter for JPEG and M-JPEG IP Cameras"></a>Recent IP Video Source class/module is not limited to use via registration as a video input/capture/source device. The filter is also registered as a regular filter and can be used programmatically in a regular way: CoCreateInstance, AddFilter etc. A C++ &#8230;<p class="read-more"><a href="http://alax.info/blog/1241">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1241" title="Using IP Video Source programmatically as a standalone DirectShow Video Source Filter for JPEG and M-JPEG IP Cameras"></a><p>Recent <a href="http://alax.info/blog/1216">IP Video Source</a> class/module is not limited to use via registration as a video input/capture/source device. The filter is also registered as a regular filter and can be used programmatically in a regular way: <a href="http://msdn.microsoft.com/en-us/library/ms686615%28VS.85%29.aspx">CoCreateInstance</a>, <a href="http://msdn.microsoft.com/en-us/library/dd390016%28VS.85%29.aspx">AddFilter</a> etc.</p>
<p>A C++ code snippet below shows how to import interface definition, create an instance of the filter, set it up and start video from a camera:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">dshow.h</span><span style="color: #800000;">&gt;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">comment(lib, </span><span style="color: #0000e6; font-weight: bold;">"strmiids.lib"</span><span style="color: #bb7977; font-weight: bold;">)</span>

<span style="color: #004a43;">#import </span><span style="color: #800000;">"</span><span style="color: #0000e6;">libid:BDCE8B49-8895-4605-8278-E9A1FBC889AC</span><span style="color: #800000;">"</span><span style="color: #004a43;"> no_namespace raw_interfaces_only raw_dispinterfaces named_guids </span><span style="color: #696969;">// IpVideoSource</span>

<span style="color: #696969;">// [...]</span>

<span style="color: #800000; font-weight: bold;">inline</span> <span style="color: #603000;">VOID</span> ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>HRESULT nResult<span style="color: #808030;">)</span>
<span style="color: #800080;">{</span>
    ATLENSURE_SUCCEEDED<span style="color: #808030;">(</span>nResult<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #800080;">}</span>

<span style="color: #696969;">// [...]</span>

CComPtr<span style="color: #800080;">&lt;</span>IBaseFilter<span style="color: #800080;">&gt;</span> pBaseFilter<span style="color: #800080;">;</span>
ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>pBaseFilter<span style="color: #808030;">.</span>CoCreateInstance<span style="color: #808030;">(</span>CLSID_JpegVideoSourceFilter<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
CComQIPtr<span style="color: #800080;">&lt;</span>IJpegVideoSourceFilter<span style="color: #800080;">&gt;</span> pJpegVideoSourceFilter <span style="color: #808030;">=</span> pBaseFilter<span style="color: #800080;">;</span>
ATLENSURE_THROW<span style="color: #808030;">(</span>pJpegVideoSourceFilter<span style="color: #808030;">,</span> E_NOINTERFACE<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>pFilterGraph<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>AddFilter<span style="color: #808030;">(</span>pBaseFilter<span style="color: #808030;">,</span> <span style="color: #800000;">L"</span><span style="color: #0000e6;">Source</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>

ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>pJpegVideoSourceFilter<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>put_Location<span style="color: #808030;">(</span>CComBSTR<span style="color: #808030;">(</span>_T<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">http://p.viewnetcam.com:60001/nphMotionJpeg?Resolution=640x480&amp;Quality=Standard</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: #800080;">;</span>
ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>pJpegVideoSourceFilter<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>put_Width<span style="color: #808030;">(</span><span style="color: #008c00;">640</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>pJpegVideoSourceFilter<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>put_Height<span style="color: #808030;">(</span><span style="color: #008c00;">480</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>

<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">region Render Output Pin</span>
CComPtr<span style="color: #800080;">&lt;</span>IEnumPins<span style="color: #800080;">&gt;</span> pEnumPins<span style="color: #800080;">;</span>
ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>pBaseFilter<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>EnumPins<span style="color: #808030;">(</span><span style="color: #808030;">&amp;</span>pEnumPins<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
CComPtr<span style="color: #800080;">&lt;</span>IPin<span style="color: #800080;">&gt;</span> pPin<span style="color: #800080;">;</span>
ATLENSURE_THROW<span style="color: #808030;">(</span>pEnumPins<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>pPin<span style="color: #808030;">,</span> <span style="color: #7d0045;">NULL</span><span style="color: #808030;">)</span> <span style="color: #808030;">=</span><span style="color: #808030;">=</span> S_OK<span style="color: #808030;">,</span> E_FAIL<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLASSERT<span style="color: #808030;">(</span>pPin<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
ATLENSURE_INLINE_SUCCEEDED<span style="color: #808030;">(</span>pFilterGraph<span style="color: #808030;">-</span><span style="color: #808030;">&gt;</span>Render<span style="color: #808030;">(</span>pPin<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43; font-weight: bold;">pragma </span><span style="color: #bb7977; font-weight: bold;">endregion</span></pre>
<p>This starts M-JPEG video from Panasonic BB-HCM381A camera available to public online at http://p.viewnetcam.com:60001/nphMotionJpeg?Resolution=640&#215;480&amp;Quality=Standard</p>
<p>UPDATE: ATLENSURE_SUCCEEDED macro in the snippet replaced with ATLENSURE_INLINE_SUCCEEDED &#8211; see additional post on this.</p>
<p>C#.NET code snippet will look like this (using <a href="http://directshownet.sourceforge.net/">DirectShowLib</a>):</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #800000; font-weight: bold;">using</span> DirectShowLib<span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">using</span> AlaxInfoIpVideoSource<span style="color: #800080;">;</span>

<span style="color: #696969;">// [...]</span>

FilterGraph filterGraph <span style="color: #808030;">=</span> <span style="color: #800000; font-weight: bold;">new</span> FilterGraph<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
IJpegVideoSourceFilter sourceFilter <span style="color: #808030;">=</span> Activator<span style="color: #808030;">.</span>CreateInstance<span style="color: #808030;">(</span>Type<span style="color: #808030;">.</span>GetTypeFromCLSID<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">new</span> Guid<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">{A8DA2ECB-DEF6-414D-8CE2-E651640DBA4F}</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span> <span style="color: #800000; font-weight: bold;">as</span> IJpegVideoSourceFilter<span style="color: #800080;">;</span>
IBaseFilter sourceBaseFilter <span style="color: #808030;">=</span> sourceFilter <span style="color: #800000; font-weight: bold;">as</span> IBaseFilter<span style="color: #800080;">;</span>
<span style="color: #808030;">(</span>filterGraph <span style="color: #800000; font-weight: bold;">as</span> IFilterGraph2<span style="color: #808030;">)</span><span style="color: #808030;">.</span>AddFilter<span style="color: #808030;">(</span>sourceBaseFilter<span style="color: #808030;">,</span> <span style="color: #800000;">"</span><span style="color: #0000e6;">Source</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
sourceFilter<span style="color: #808030;">.</span>Location <span style="color: #808030;">=</span> @<span style="color: #800000;">"</span><span style="color: #0000e6;">http://p.viewnetcam.com:60001/nphMotionJpeg?Resolution=640x480&amp;Quality=Standard</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span>
sourceFilter<span style="color: #808030;">.</span>Width <span style="color: #808030;">=</span> <span style="color: #008c00;">640</span><span style="color: #800080;">;</span>
sourceFilter<span style="color: #808030;">.</span>Height <span style="color: #808030;">=</span> <span style="color: #008c00;">480</span><span style="color: #800080;">;</span>
IPin pin <span style="color: #808030;">=</span> DsFindPin<span style="color: #808030;">.</span>ByDirection<span style="color: #808030;">(</span>sourceBaseFilter<span style="color: #808030;">,</span> PinDirection<span style="color: #808030;">.</span>Output<span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #808030;">(</span>filterGraph <span style="color: #800000; font-weight: bold;">as</span> IFilterGraph2<span style="color: #808030;">)</span><span style="color: #808030;">.</span>Render<span style="color: #808030;">(</span>pin<span style="color: #808030;">)</span><span style="color: #800080;">;</span>
<span style="color: #808030;">(</span>filterGraph <span style="color: #800000; font-weight: bold;">as</span> IMediaControl<span style="color: #808030;">)</span><span style="color: #808030;">.</span>Run<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
EventCode eventCode<span style="color: #800080;">;</span>
<span style="color: #808030;">(</span>filterGraph <span style="color: #800000; font-weight: bold;">as</span> IMediaEvent<span style="color: #808030;">)</span><span style="color: #808030;">.</span>WaitForCompletion<span style="color: #808030;">(</span><span style="color: #808030;">-</span><span style="color: #008c00;">1</span><span style="color: #808030;">,</span> <span style="color: #800000; font-weight: bold;">out</span> eventCode<span style="color: #808030;">)</span><span style="color: #800080;">;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1241/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LogProcessExceptions: Automatically Create Minidump Files on C++ Exception in Monitored Process</title>
		<link>http://alax.info/blog/1211</link>
		<comments>http://alax.info/blog/1211#comments</comments>
		<pubDate>Wed, 18 May 2011 16:47:41 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[.DMP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[minidump]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1211</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1211" title="LogProcessExceptions: Automatically Create Minidump Files on C++ Exception in Monitored Process"></a>LogProcessExceptions utility implements a very basic debugger which attaches (see DebugActiveProcess on MSDN) to a running process and monitors its exceptions. Once exception takes place the utility creates a minidump file for the process (see MiniDumpWriteDump on MSDN) so that &#8230;<p class="read-more"><a href="http://alax.info/blog/1211">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1211" title="LogProcessExceptions: Automatically Create Minidump Files on C++ Exception in Monitored Process"></a><p>LogProcessExceptions utility implements a very basic debugger which attaches (see <a href="http://msdn.microsoft.com/en-us/library/ms679295%28VS.85%29.aspx">DebugActiveProcess</a> on MSDN) to a running process and monitors its exceptions. Once exception takes place the utility creates a minidump file for the process (see <a href="http://msdn.microsoft.com/en-us/library/ms680360%28VS.85%29.aspx">MiniDumpWriteDump</a> on MSDN) so that exception condition could be investigated off-site using debugger.</p>
<p>If you throw C++ exceptions in your C++ code in exceptional cases which indicate necessity to log the condition and possibly check it later, the utility will get the vital information for the application running at production location in environment without fully featured debugger (note that the utility is a simple download-and-run &#8220;wizard&#8221; style application, with no installation required), or will simply track the error letting the application continue execution without pretty much of an interruption.</p>
<p>The tool will prompt for debuggee process, and follow with minidump type choices and the debugging operation.</p>
<p><img class="alignnone size-full wp-image-1212" title="Log Process Exceptions - Processes" src="http://alax.info/blog/wp-content/uploads/2011/05/Image001.png" alt="" width="513" height="400" /></p>
<p><span id="more-1211"></span></p>
<p><img class="alignnone size-full wp-image-1213" title="Log Process Exceptions - Minidupm Type" src="http://alax.info/blog/wp-content/uploads/2011/05/Image0031.png" alt="" width="513" height="400" /> <img class="alignnone size-full wp-image-1214" title="Log Process Exceptions - Operation" src="http://alax.info/blog/wp-content/uploads/2011/05/Image0041.png" alt="" width="513" height="400" /></p>
<p>Minidump files are created automatically with the name file including:</p>
<ul>
<li>Excecutable Name</li>
<li>Process Identifier</li>
<li>Ordinal Number</li>
<li>Exception Code</li>
<li>C++/ATL Exception HRESULT Code (esp. for <a href="http://msdn.microsoft.com/en-us/library/9b1a94tx%28VS.80%29.aspx">CAtlException</a> exceptions)</li>
</ul>
<p>The utility is expected to work with Windows XP operating system and more recent.</p>
<p>Partial Visual C++ .NET 2010 source code is <a href="http://code.assembla.com/roatl-utilities/subversion/nodes/trunk/LogProcessExceptions">available  from SVN</a>, release binary included (<a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/LogProcessExceptions/_Bin/Win32/Release/LogProcessExceptions.exe?format=raw">Win32</a>,  <a href="http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/LogProcessExceptions/_Bin/x64/Release/LogProcessExceptions.exe?format=raw">x64</a>).</p>
<p>Artwork credits: <a href="http://cristoildiablo.deviantart.com/">http://cristoildiablo.deviantart.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1211/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utility Clearance: Automatic Snapshots</title>
		<link>http://alax.info/blog/1200</link>
		<comments>http://alax.info/blog/1200#comments</comments>
		<pubDate>Fri, 13 May 2011 16:17:43 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[ATL]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[WTL]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[snapshot]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1200</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1200" title="Utility Clearance: Automatic Snapshots"></a>Automatic Snapshots runs as a background application monitors clipboard. Should a new image be copied there, the utility automatically writes the image into a file. The process does not require any user interaction and is completely automatic so that &#8211; &#8230;<p class="read-more"><a href="http://alax.info/blog/1200">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1200" title="Utility Clearance: Automatic Snapshots"></a><p>Automatic Snapshots runs as a background application monitors clipboard. Should a new image be copied there, the utility automatically writes the image into a file. The process does not require any user interaction and is completely automatic so that &#8211; per <a href="http://en.wikipedia.org/wiki/Michael_Westen">Mike Westen</a>&#8216;s request &#8211; user could quickly and easily create snapshots of a multitude of windows (Alt+Print Screen) or full screen images (Print Screen) using standard hotkeys.</p>
<p><img class="alignnone size-full wp-image-1201" title="Automatic Snapshots" src="http://alax.info/blog/wp-content/uploads/2011/05/2011-05-12-23-31-36-0001-Automatic-Snapshots.png" alt="" width="522" height="397" /></p>
<p>Features:</p>
<ul>
<li>Automatic PNG compression (can be disabled via registry and enable BMP mode)</li>
<li>Reduction of color depth to create smaller PNG files</li>
<li>Asynchronous processing, the compression and file writes are on background thread to not slow foreground application</li>
<li>Application window flashes on application bar while busy and indicates the status via window caption</li>
<li>Application appends current foreground window caption to the image file name</li>
</ul>
<p>A binary [<a href="http://trac2.assembla.com/roatl-utilities/browser/trunk/AutomaticSnapshots/_Bin/Win32/Release/AutomaticSnapshots.exe?format=raw">Win32</a>, <a href="http://trac2.assembla.com/roatl-utilities/browser/trunk/AutomaticSnapshots/_Bin/x64/Release/AutomaticSnapshots.exe?format=raw">x64</a>] and Visual C++ .NET 2010 source code <a href="http://trac2.assembla.com/roatl-utilities/browser/trunk/AutomaticSnapshots/">are  available from SVN</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1200/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If your application is looking for network adapters, it may be blind to see</title>
		<link>http://alax.info/blog/1195</link>
		<comments>http://alax.info/blog/1195#comments</comments>
		<pubDate>Thu, 28 Apr 2011 17:17:41 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Seriously]]></category>
		<category><![CDATA[Source]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[network]]></category>

		<guid isPermaLink="false">http://alax.info/blog/?p=1195</guid>
		<description><![CDATA[<a href="http://alax.info/blog/1195" title="If your application is looking for network adapters, it may be blind to see"></a>A really long and annoying troubleshooting of a problem finally ended with a bug found in GetAdaptersInfo/GetAdaptersAddresses API. It may unexpectedly fail under the following conditions: 32-bit application 64-bit operating system or /3GB feature enabled on 32-bit operating system hosting &#8230;<p class="read-more"><a href="http://alax.info/blog/1195">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://alax.info/blog/1195" title="If your application is looking for network adapters, it may be blind to see"></a><p>A really long and annoying troubleshooting of a problem finally ended with a bug found in <a href="http://msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx">GetAdaptersInfo</a>/<a href="http://msdn.microsoft.com/en-us/library/aa365915%28VS.85%29.aspx">GetAdaptersAddresses</a> API.</p>
<p>It may unexpectedly fail under the following conditions:</p>
<ul>
<li>32-bit application</li>
<li>64-bit operating system or /3GB feature enabled on 32-bit operating system</li>
<li>hosting process is linked with /LARGEADDRESSAWARE flag or has otherwise set it in binary header</li>
<li>over 2GB of RAM (in terms of Private Bytes/Virtual Size performance counters) consumed by the hosting process</li>
</ul>
<p>The application might unexpectedly start getting ERROR_NO_DATA (232) or ERROR_NOACCESS (998) error codes instead of list of adapters. Supposedly, the responsible Microsoft component iplhlpapi.dll or one of the underlying components/APIs are incompatible with such environments (such as for example, treating 32-bit pointer with the most significant bit set as invalid or compares such pointers as signed values).</p>
<p><img class="alignnone size-full wp-image-1196" title="GetAdaptersInfo Failure" src="http://alax.info/blog/wp-content/uploads/2011/04/Image0011.png" alt="" width="301" height="214" /></p>
<p>A test Visual C++ .NET 2010 application <a href="http://trac2.assembla.com/roatl-utilities/browser/trunk/GetAdaptersAddressesTest">is  available from SVN</a>. More bug details on <a href="http://connect.microsoft.com/VisualStudio/feedback/details/665383/getadaptersaddresses-api-incorrectly-returns-no-adapters-for-a-process-with-high-memory-consumption">Microsoft Connect</a>.</p>
<p>NOTE 1: You need to run &#8220;GetAdaptersAddressesTest /regserver&#8221; once to register the app before running it for the test.</p>
<p>NOTE 2: The problem does not seem to take place with 32-bit operating systems with /3GB tuning enabled.</p>
]]></content:encoded>
			<wfw:commentRss>http://alax.info/blog/1195/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

