<?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>voyce &#187; Uncategorized</title>
	<atom:link href="http://www.voyce.com/index.php/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Sun, 15 Jan 2012 13:10:46 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Holiday</title>
		<link>http://www.voyce.com/index.php/2010/08/10/holiday/</link>
		<comments>http://www.voyce.com/index.php/2010/08/10/holiday/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:11:26 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=978</guid>
		<description><![CDATA[Normal service will be resumed shortly...]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been wondering where I&#8217;ve got to over the past few weeks, rest assured I&#8217;ve not given it all up, but I&#8217;m taking 6 weeks out to travel round the west coast of the USA with my family in an RV (a motorhome). If you need any more detail than that (really?), head over to <a href="http://bigtrip.voyce.com">bigtrip.voyce.com</a>.</p>
<p><div class="wp-caption alignleft" style="width: 250px"><a href="http://www.flickr.com/photos/ianvoyce/4870616004/""><img alt="Fanboy, moi?" src="http://farm5.static.flickr.com/4123/4870616004_b7b4840831_m.jpg" title="fanboy" width="240" height="160" /></a><p class="wp-caption-text">Fanboy? Moi...?</p></div>Of course, being an oft-accused Apple fanboy, I took the opportunity to stop at the Cupertino mothership on the way through.</p>
<p>See you back here in September!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/08/10/holiday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Too busy to blog&#8230;!?</title>
		<link>http://www.voyce.com/index.php/2010/03/05/too-busy-to-blog/</link>
		<comments>http://www.voyce.com/index.php/2010/03/05/too-busy-to-blog/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 22:42:41 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=694</guid>
		<description><![CDATA[Live has been getting in the way of blogging.]]></description>
			<content:encoded><![CDATA[<p>Yes I know, shocking isn&#8217;t it? Too busy doing work that pays the bills to blog about random things I find interesting or amusing. </p>
<p>So what&#8217;s been keeping me away from WordPress?</p>
<ul>
<li>Spending too much time in WinDbg tracking down .NET and COM memory issues.</li>
<li>Wanting to have a good look at Visual Studio 2010 and .NET 4.0 (though not as much as I&#8217;d like, yet)</li>
<li>Playing lots of <a href="http://www.amazon.com/gp/product/B002JTX5SO?ie=UTF8&#038;tag=wwwvoycecom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B002JTX5SO">Bayonetta</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwvoycecom-20&#038;l=as2&#038;o=1&#038;a=B002JTX5SO" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />, and some <a href="http://www.amazon.com/gp/product/B002CZ38KA?ie=UTF8&#038;tag=wwwvoycecom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B002CZ38KA">Heavy Rain</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwvoycecom-20&#038;l=as2&#038;o=1&#038;a=B002CZ38KA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />.</li>
<li>Doing lots of internal demos of the WPF\F# GUI-building toolset we&#8217;ve been working on. Should be interesting, specially now <a href="http://blogs.msdn.com/lucabol/archive/2010/02/19/luca-bolognese-leaves-microsoft.aspx">Luca&#8217;s coming on board</a>.</li>
<li>Experimenting with iPad development</li>
</ul>
<p>Hopefully I&#8217;ll get the chance to write something about all of this soon. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/03/05/too-busy-to-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t do anything in DllMain&#8230; Please</title>
		<link>http://www.voyce.com/index.php/2009/12/03/dont-do-anything-in-dllmain-please/</link>
		<comments>http://www.voyce.com/index.php/2009/12/03/dont-do-anything-in-dllmain-please/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 23:27:13 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=554</guid>
		<description><![CDATA[Thinking of adding some code to your DLLs DllMain function? STOP!]]></description>
			<content:encoded><![CDATA[<p>Novice Windows programmers can often think that <code>DllMain</code> is a good place to get that one-time set-up and tear-down work done. It seems to offer an ideal opportunity to know when your DLL has just been loaded, and when it&#8217;s about to be unloaded. What better place to add all that expensive, complicated initialisation&#8230;? STOP! WAIT! Before you add anything in <code>DllMain</code>, make sure you understand what state the process will be in when it gets called. Once you know that, you may well change your mind&#8230;<br />
<span id="more-554"></span><br />
Firstly, take a look at <a href="http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx">this page</a>. It does a pretty good job of ramming home the point that there&#8217;s very little that it&#8217;s safe to do in <code>DllMain</code>. Essentially this is because while the function&#8217;s being called, the OS is holding a process-wide lock that isn&#8217;t re-entrant. As such, if you do anything that causes a DLL to be loaded, a deadlock may occur. There are many, many things that may have a side-effect of loading a DLL; calling COM functions, creating threads etc.</p>
<p>This is such a common source of bugs, and such an important requirement, that from Vista onwards Microsoft introduced a new set of functions in the Windows API explicitly to support it: <a href="http://msdn.microsoft.com/en-us/library/aa363808(VS.85).aspx">One-Time Initialization</a>.</p>
<p>And even if you get away with doing naughty things in <code>DllMain</code> now, don&#8217;t think that it&#8217;ll stay that way forever. We got away with it for years, then when .NET came along it introduced all sorts of additional correctness checks. For instance, the Managed Debugging Assistant (MDA) in Visual Studio will shout loudly should you attempt to run managed code during <code>DllMain</code>.<br />
<code><br />
Managed Debugging Assistant 'LoaderLock' has detected a problem in 'C:\YourApp.vshost.exe'.<br />
Additional Information: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.<br />
</code><br />
And it&#8217;s easier than you think to do so. For example, calling something as innocuous as <code>GetWindowText</code> can result in managed code being run. </p>
<p>How can you get around this?</p>
<p>One of the approaches I&#8217;ve used has been to make use of Win32 asynchronous procedure calls. Specifically you can call <a href="http://msdn.microsoft.com/en-us/library/ms684954(VS.85).aspx">QueueUserAPC</a> to add a function to the queue, and this can contain the initialisation you would&#8217;ve otherwise done in <code>DllMain</code>. </p>
<p>However there is significant gotcha regarding use of APCs: your function will not be called until the thread is in an &#8220;alertable wait state&#8221;. This means you (or some other code on the thread) need to call an alertable wait function such as <a href="http://msdn.microsoft.com/en-us/library/ms686307(VS.85).aspx"><code>SleepEx</code></a>, <a href="http://msdn.microsoft.com/en-us/library/ms687036(VS.85).aspx"><code>WaitForSingleObjectEx</code></a> and specify TRUE for the alertable parameter. </p>
<p>Once your APC is getting called successfully you&#8217;ll be in much better place; your code will be executed outside of the scope of the dreaded OS loader lock and you&#8217;ll be doing things by the book, hopefully avoiding all the potential pitfalls that lie in wait within <code>DllMain</code>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/12/03/dont-do-anything-in-dllmain-please/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FormatException in WPF DataBinding</title>
		<link>http://www.voyce.com/index.php/2009/10/14/formatexception-in-wpf-databinding/</link>
		<comments>http://www.voyce.com/index.php/2009/10/14/formatexception-in-wpf-databinding/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 11:09:26 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[FormatException]]></category>
		<category><![CDATA[visualstudio]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=446</guid>
		<description><![CDATA[A FormatException is generated by the WPF DataBinding diagnostics if the original exception text contains curly brackets.]]></description>
			<content:encoded><![CDATA[<p>While working on some F#/C# WPF code the other day, I kept hitting a fatal FormatException when running under the debugger. Annoyingly, the app would quit with:<br />
<code><br />
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll<br />
Additional information: Input string was not in a correct format.<br />
</code><br />
But it worked fine when started from Expression Blend, or when run using Start Without Debugging in Visual Studio. Let&#8217;s take a closer look&#8230;<br />
<span id="more-446"></span><br />
Looking at the output window, there seemed to be an intial exception before the FormatException, and from the stack trace the second one seemed to be generated as WPF was trying to log the first one:</p>
<p><a href="http://72.47.193.211/wp-content/uploads/2009/10/callstack.png"><img src="http://www.voyce.com/wp-content/uploads/2009/10/callstack-300x113.png" alt="callstack" title="callstack" width="300" height="113" class="size-medium wp-image-449" /></a></p>
<p>I had a look at the text of the first exception, and from that it was obvious:</p>
<p><code><br />
Unable to cast COM object of type 'System.__ComObject' to interface type 'IWhatever'. This operation failed because the QueryInterface call on the COM component for the interface with IID '<b>{</b>CAD939D0-5E5D-11D7-AA0B-0002B33FE9DX<b>}</b>' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).<br />
</code></p>
<p>The message contains curly brackets around the IID, and they&#8217;re being intrepreted as insertion points by a call to String.Format!</p>
<h2>Workaround</h2>
<p>So that explained why it only happens in debugger runs; as <a href="http://blogs.msdn.com/mikehillberg/archive/2006/09/14/WpfTraceSources.aspx">this post</a> helpfully points out the WPF databinding is enabled by default in that case. To workaround it, you can disable logging programmatically or using the App.config file to only display <code>Critical</code> output. So if your app is named foo.exe, create a file foo.exe.config that contains:</p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<pre style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &lt;</span><span style="color: #a31515;">system.diagnostics</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;</span><span style="color: #a31515;">sources</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &nbsp; &lt;</span><span style="color: #a31515;">source</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">System.Windows.Data</span>"<span style="color: blue;"> </span><span style="color: red;">switchName</span><span style="color: blue;">=</span>"<span style="color: blue;">SourceSwitch</span>"<span style="color: blue;">/&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;/</span><span style="color: #a31515;">sources</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;</span><span style="color: #a31515;">switches</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &nbsp; &lt;</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">SourceSwitch</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Critical</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &nbsp; &lt;/</span><span style="color: #a31515;">switches</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: blue;">&nbsp; &lt;/</span><span style="color: #a31515;">system.diagnostics</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;</span></pre>
</div>
<h2>Fix&#8230;?</h2>
<p>Hopefully there&#8217;ll be a fix for this at some point soon, as disabling the logging is a pretty large hammer to crack this small nut.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/10/14/formatexception-in-wpf-databinding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What a response!</title>
		<link>http://www.voyce.com/index.php/2009/09/23/what-a-response/</link>
		<comments>http://www.voyce.com/index.php/2009/09/23/what-a-response/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 20:24:48 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www2.voyce.com/?p=381</guid>
		<description><![CDATA[Some comments on the massive response to the "7 signs" blog post, and a couple of snivelling apologies.]]></description>
			<content:encoded><![CDATA[<p>Wow. I&#8217;ve been totally overwhelmed by the response to <a href="/index.php/2009/09/14/the-7-signs-your-ui-was-created-by-a-programmer">the 7 signs your UI was created by a programmer</a>: 40,000 readers and counting, and that was just over a couple of days! I&#8217;m expecting some seriously good programmer-created user interfaces after this. And if I spot one more typo in a dialog box, I promise I&#8217;ll raise an army of UI pedants to hunt you down and put your users out of their misery.</p>
<p>A couple of apologies are in order. Firstly, sorry if you tried to hit the site and found it down. I totally wasn&#8217;t prepared for the traffic; my bad. Secondly, sorry if you&#8217;ve posted a comment on the article here or elsewhere and I haven&#8217;t responded. I&#8217;m been swamped and the day job always seems to get in the way, dammit.</p>
<p>Anyway, thanks for reading, keep in touch, and I&#8217;ll try and get over that &#8216;difficult second album&#8217; period I seem to be having.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/09/23/what-a-response/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Missing content in long Wordpress posts</title>
		<link>http://www.voyce.com/index.php/2009/08/28/missing-content-in-long-wordpress-posts/</link>
		<comments>http://www.voyce.com/index.php/2009/08/28/missing-content-in-long-wordpress-posts/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 23:44:25 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=321</guid>
		<description><![CDATA[I&#8217;ve just spent several hours struggling with an annoying Wordpress problem: when I edited a post to make some additions, it suddenly stopped displaying any content. The title, header and footer were still visible, only the post body itself was missing.
After a bit of poking around, I came across this post. It points out the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://72.47.193.211/wp-content/uploads/2009/09/wordpress_icon.jpg"><img src="http://72.47.193.211/wp-content/uploads/2009/09/wordpress_icon.jpg" alt="wordpress_icon" title="wordpress_icon" width="125" height="112" class="alignleft size-full wp-image-341" /></a>I&#8217;ve just spent several hours struggling with an annoying Wordpress problem: when I edited a post to make some additions, it suddenly stopped displaying any content. The title, header and footer were still visible, only the post body itself was missing.</p>
<p>After a bit of poking around, I came across <a href="http://www.undermyhat.org/blog/2009/07/sudden-empty-blank-page-for-large-posts-with-wordpress/">this post</a>. It points out the root cause of the problem is the PHP regular expression engine (PCRE) that Wordpress uses.</p>
<p>The easiest way to fix the problem is to ignore the advice in that post about modifying formatting.php, and instead make the fix to PHP.INI which is mentioned in the comments. I edited my copy to include the following line, which increases the backtracking limit from the default of 100000:</p>
<pre>
pcre.backtrack_limit = 1000000
</pre>
<p>After getting IIS to pick up the changes (iisreset) my missing content appeared again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/08/28/missing-content-in-long-wordpress-posts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Twitter</title>
		<link>http://www.voyce.com/index.php/2009/01/26/twitter/</link>
		<comments>http://www.voyce.com/index.php/2009/01/26/twitter/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 16:00:36 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=69</guid>
		<description><![CDATA[I&#8217;m on twitter! Expect some random thoughts on software development and the like: http://twitter.com/voyce
I&#8217;ve added a widget to the sidebar to give you a flavour.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m on twitter! Expect some random thoughts on software development and the like: <a href="http://twitter.com/voyce">http://twitter.com/voyce</a></p>
<p>I&#8217;ve added a widget to the sidebar to give you a flavour.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/01/26/twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So it really works&#8230;</title>
		<link>http://www.voyce.com/index.php/2008/07/22/so-it-really-works/</link>
		<comments>http://www.voyce.com/index.php/2008/07/22/so-it-really-works/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 19:22:34 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=34</guid>
		<description><![CDATA[&#8230;this blogging from your iPhone thang. There&#8217;s a new (free!) app available from the AppStore that gives you &#8220;native&#8221; WordPress access direct from the iPhone, and it seems to work quite nicely.
Now, where&#8217;s that copy and paste&#8230;
]]></description>
			<content:encoded><![CDATA[<p>&#8230;this blogging from your iPhone thang. There&#8217;s a new (free!) app available from the AppStore that gives you &#8220;native&#8221; WordPress access direct from the iPhone, and it seems to work quite nicely.</p>
<p>Now, where&#8217;s that copy and paste&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2008/07/22/so-it-really-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpD2d Update</title>
		<link>http://www.voyce.com/index.php/2007/04/12/opd2d-update/</link>
		<comments>http://www.voyce.com/index.php/2007/04/12/opd2d-update/#comments</comments>
		<pubDate>Thu, 12 Apr 2007 22:48:00 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=11</guid>
		<description><![CDATA[I finally got around to building and packaging a new version of OpD2d. Major new features are:

Preview window so you can easily check volume levels before recording
Ability to pass recording settings on command line so you can use Windows Scheduler to record automatically at a certain time

It’s available here: http://www.opcode.co.uk/opd2d/default.asp
OpD2d has been downloaded about 5000 [...]]]></description>
			<content:encoded><![CDATA[<p class="postentry">I finally got around to building and packaging a new version of OpD2d. Major new features are:</p>
<ul>
<li>Preview window so you can easily check volume levels before recording</li>
<li>Ability to pass recording settings on command line so you can use Windows Scheduler to record automatically at a certain time</li>
</ul>
<p>It’s available here: <a href="http://www.opcode.co.uk/opd2d/default.asp">http://www.opcode.co.uk/opd2d/default.asp</a></p>
<p>OpD2d has been downloaded about 5000 times a month for the past few years, and I’d like to take this opportunity to thank the people who’ve been generous enough to paypal me a few quid as thanks. This is much appreciated, and helps to keep me in <a href="http://www.i-manifest.com/">t-shirts</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2007/04/12/opd2d-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

