<?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>lapthorn.net</title>
	<atom:link href="http://www.lapthorn.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lapthorn.net</link>
	<description>(*this).that(&#38;theOther);</description>
	<lastBuildDate>Sat, 04 Sep 2010 16:18:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>More Mercurial &#8211; Remote Repositories</title>
		<link>http://www.lapthorn.net/archives/110</link>
		<comments>http://www.lapthorn.net/archives/110#comments</comments>
		<pubDate>Sat, 04 Sep 2010 15:44:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DVCS]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[DVCS Mercurial]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=110</guid>
		<description><![CDATA[I&#8217;ve spent some more time tinkering with Mercurial, and essentially wanted to the master repository to behave a bit more like Subversion. I know this is a Bad Thing, but I want to be able to effectively commit, i.e. push, my changes back to the master repository without having to manually update it and commit [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent some more time tinkering with Mercurial, and essentially wanted to the master repository to behave a bit more like Subversion.  I know this is a Bad Thing, but I want to be able to effectively commit, i.e. push, my changes back to the master repository without having to manually update it and commit it.  The answer is rather simple but does seem to be that well publicised, probably because either everyone knows how to do this (e.g. hosted services), or no-one does this.</p>
<p>The solution is simply to add some hooks to your Mercurial set up as described <a href="http://mercurial.selenic.com/wiki/Hook#The_changegroup_hook">here</a> and <a href="http://mercurial.selenic.com/wiki/FAQ#FAQ.2BAC8-CommonProblems.Any_way_to_.27hg_push.27_and_have_an_automatic_.27hg_update.27_on_the_remote_server.3F">here</a>.</p>
<p>To summarise:</p>
<blockquote><p>To act on changesets of a push/pull/unbundle, put this in .hg/hgrc:</p>
<p><code>[hooks]<br />
changegroup = hg update &gt;&amp;2</code></p>
<p>This goes in .hg/hgrc on the remote repository. Output has to be redirected to stderr (or /dev/null), because stdout is used for the data stream.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/110/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Less is more</title>
		<link>http://www.lapthorn.net/archives/99</link>
		<comments>http://www.lapthorn.net/archives/99#comments</comments>
		<pubDate>Fri, 30 Jul 2010 11:44:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=99</guid>
		<description><![CDATA[As I&#8217;ve spent much of my career using Visual Studio and its various incarnations, I&#8217;ve become quite used to using all the keyboard shortcuts to reduce the time I spend using the mouse. As result of keyboard shortcuts, there are a lot of menu bars and windows on the screen that I just don&#8217;t need.  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lapthorn.net/wp-content/uploads/ie7_menu_bar_top_small.jpg"><img class="alignright size-medium wp-image-98" title="ie7_menu_bar_top_small" src="http://www.lapthorn.net/wp-content/uploads/ie7_menu_bar_top_small-300x182.jpg" alt="" width="300" height="182" /></a></p>
<p>As I&#8217;ve spent much of my career using Visual Studio and its various  incarnations, I&#8217;ve become quite used to using all the keyboard shortcuts  to reduce the time I spend using the mouse.</p>
<p>As result of keyboard shortcuts, there are a lot of menu bars and windows on the screen that I just don&#8217;t need.  The image in this post is of Internet Explorer.  Web browsers have suffered from this problem for a long time as well:  if you look at the image, you will see that almost a third of the image is taken up by search bars and menus that are practically unused.</p>
<p>The same is true in Visual Studio.  The default settings are to give you just about every window possible (Output, Solution Explorer, etc.), in addition to lots of menu bars:  &#8216;Edit&#8217; &#8211; is there a developer out there that <strong>doesn&#8217;t</strong> know Ctrl+C, Ctrl+V, Ctrl+X, Ctrl+Y, Ctrl+Z?  The amount of area for <strong>writing code</strong> seems to be 50% or less of the IDE window.</p>
<p>My settings are now:</p>
<ul>
<li>No menu bars except for a custom one that changes build configuration (release/debug), and has &#8216;build&#8217; and &#8216;rebuild&#8217; solution.</li>
<li>One docked vertical window that contains the &#8216;Solution Explorer&#8217;.</li>
<li>One minimized docked horizontal window with tabs for Output and Find.</li>
<li>And one large window for editing code, as nature intended.</li>
</ul>
<p>It isn&#8217;t just Visual Studio that suffers from this, take a look at Eclipse:</p>
<p style="text-align: center;"><a href="http://www.lapthorn.net/wp-content/uploads/eclipse.png"><img class="aligncenter size-full wp-image-101" title="eclipse" src="http://www.lapthorn.net/wp-content/uploads/eclipse.png" alt="" width="614" height="440" /></a></p>
<p>Once again, the code editor takes up about 50% of the available space.</p>
<p>There are benefits and drawbacks to increasing your editor size.  The drawbacks are that, perhaps, some of the windows and menu bars you are doing without, you need more than you realise. With more screen real estate for your editor you can view more of your code with less scrolling.  The other choice is that you can now increase the font size, making the coding easier on the eye (quite literally less strain whilst looking at your monitor).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/99/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Auto-Updates</title>
		<link>http://www.lapthorn.net/archives/85</link>
		<comments>http://www.lapthorn.net/archives/85#comments</comments>
		<pubDate>Mon, 19 Jul 2010 17:45:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=85</guid>
		<description><![CDATA[Despite my best googling efforts, I&#8217;ve yet to find any posting on designing an auto-update feature for my code, so in the traditions of NIH, I rolled my own.  It seems, ultimately, that the simplest solution is, well, the simplest solution. Since I work on Windows, it is easy to get the current application&#8217;s name [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lapthorn.net/wp-content/uploads/windows_update.gif"><img class="alignright size-medium wp-image-93" title="windows_update" src="http://www.lapthorn.net/wp-content/uploads/windows_update-300x212.gif" alt="" width="300" height="212" /></a>Despite my best googling efforts, I&#8217;ve yet to find any posting on designing an auto-update feature for my code, so in the traditions of <a href="http://en.wikipedia.org/wiki/Not_Invented_Here">NIH</a>, I rolled my own.  It seems, ultimately, that the simplest solution is, well, the simplest solution.</p>
<p>Since I work on Windows, it is easy to get the current application&#8217;s name and version (provided you have set it and maintain it) from the resource file, either in .NET or Win32.  So straight away you have your application name, and your current application version.   The next thing is to store the new version away somewhere.  Going back to my comment about the simplest solution, parsing HTML is, to say the least, <a href="http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html">difficult</a>.  Putting updates on the web demand a web page, and hence HTML.</p>
<p>HTML can be tackled in a variety of ways, the worst of which is probably a regular expression, up to using something like <a href="http://htmlagilitypack.codeplex.com/">http://htmlagilitypack.codeplex.com/</a>.  Either way, in HTML, you end up with a solution not dissimilar to:</p>
<pre name='code' class="html">&lt;span class='name'&gt; My App &lt;/span&gt;
&lt;span class='version'&gt; My Version &lt;/span&gt;
</pre>
<p>and parsing it relies on you trusting whoever edits the HTML to preserve the tags, classes and/or ids.</p>
<p>So back once again to &#8216;simple&#8217;.  My solution is this:  a text file containing comma separated values.  Why?  It is easy, it is human readable, and it is pretty near impossible to get wrong.  When scanning it, you can just skip everything in there except your application information.  It could contain a header, plus the information:</p>
<pre>Name,Version,Installer
My App, 1.0, http://localhost/my_installer_1.0.msi</pre>
<p>At this point someone reading this (yes, you!) will say:  &#8220;but what about the web page?&#8221;  Well, that is now fairly trivial with modern Javascript libraries.  A little bit of <a href="http://jquery.com/">jquery</a>, and a <a href="http://plugins.jquery.com/project/csv2table">little bit more</a>, and you&#8217;re most of the way there.  Making the installer a hyperlink is left as an exercise.  Or you could simply then just maintain a static HTML page to go with the text file.</p>
<p>For C#, the code to get the file is remarkably trivial.  For a blocking<a href="http://msdn.microsoft.com/en-US/library/ms144194%28v=VS.80%29.aspx"> single-threaded web request</a>:</p>
<pre name='code' class="csharp">System.Net.WebClient webClient = new System.Net.WebClient();
//  blocking...
webClient.DownloadFile(new System.Uri("http://localhost/updates.csv"), @"C:\updates.csv"));</pre>
<p>Put this into the appropriate try catch block, and download to a file of your choosing.</p>
<h3>On Version Naming.</h3>
<p>What&#8217;s the difference between version 3.2 and version 3.12?  For one thing, you might think 3.12 is later than version 3.2, but you would be wrong.  A naive implementation of an auto-update system that checks versions would do this:</p>
<pre name='code' class="csharp">if (new_version &gt; old_version) {  run_installer(); }</pre>
<p>Except for two things:</p>
<p>1.  You might have chosen new_version and old_version to be doubles.  Then 3.2 is actually 3.20 which IS greater than 3.12 and your installer never gets run.</p>
<p>2.  You might have been smarter and chosen new_version and old_version to be strings, so you could have 3.2a and 3.12b, but you would still be in trouble because a string comparison compares characters at a time, and once it gets to the &#8217;1&#8242; in 3.12, and the &#8217;2&#8242; in 3.2, it once again decides that 3.2 is greater that 3.12, and once again your installer doesn&#8217;t start.</p>
<p>So your run_installer clause ends up being:</p>
<pre name='code' class="csharp">if (new_version != old_version) { run_installer(); }</pre>
<p>which has the side effect of allowing rollbacks to prior versions if you so choose (assuming of course that the MSI installers don&#8217;t prevent you from doing that).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/85/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Graph Plotting</title>
		<link>http://www.lapthorn.net/archives/73</link>
		<comments>http://www.lapthorn.net/archives/73#comments</comments>
		<pubDate>Tue, 29 Jun 2010 17:58:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=73</guid>
		<description><![CDATA[I needed to plot some dates and values and embed them in an HTML email.  The result for the plotting part was this little Python script.  The script is fairly trivial, with some comments inline.  The gist is as follows: Get a dictionary of keys and values, where the keys are dates that are parsable [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lapthorn.net/wp-content/uploads/test.png"><img class="alignright size-medium wp-image-81" title="A Python graph." src="http://www.lapthorn.net/wp-content/uploads/test-300x201.png" alt="" width="300" height="201" /></a>I needed to plot some dates and values and embed them in an HTML email.  The result for the plotting part was this little Python script.  The script is fairly trivial, with some comments inline.  The gist is as follows:</p>
<ul>
<li>Get a dictionary of keys and values, where the keys are dates that are parsable by dateutil.parser.</li>
<li>Turn the dictionary into two arrays; one containing dates sorted into order, the other containing the matching values (put into appropriate order for the dates).</li>
<li>Pass the two arrays into the plotting function that calls matplotlib, which then saves the graph.</li>
<li>Lastly, use the system verb &#8216;open&#8217; to open the graph image in the default image viewer.</li>
</ul>
<p>You&#8217;ll need Python 2.6, <a title="Matplotlib" href="http://matplotlib.sourceforge.net/">http://matplotlib.sourceforge.net/</a> and <a title="Numpy" href="http://numpy.scipy.org/">http://numpy.scipy.org/</a></p>
<pre class="python">import matplotlib
import matplotlib.pyplot as plt
import pylab
import dateutil
import os

#  Install matplotlib and numpy to get this to work      

def dict_to_dates_and_values(data):
    dates = []
    values = []   

    #  ensure the data is sorted by date, i.e. dict key
    sorted_keys = data.keys()
    sorted_keys.sort()
    for key in sorted_keys:
        #  parse date to system date object
        dates.append(dateutil.parser.parse(key))
        values.append(int(data[key]))

    return (dates, values)

def plot_graph(xtitle, ytitle, dates, values, filename):
    plt.plot_date(pylab.date2num(dates), values, linestyle = '-')
    plt.ylabel(ytitle, fontsize='xx-small')
    plt.xlabel(xtitle, fontsize='xx-small')
    plt.xticks(fontsize='xx-small')
    plt.yticks(fontsize='xx-small')
    current_figure = plt.gcf()
    current_axes = plt.gca()
    #  Set number of x axis ticks
    current_axes.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(4))
    #  Set figure size
    current_figure.set_size_inches(5,3)
    #  Save a png
    current_figure.savefig(filename, bbox_inches='tight')

data = dict()
data["2010-01-01"] = 1
data["2010-01-02"] = 2
data["2010-01-03"] = 4
data["2010-01-04"] = 8
data["2010-01-05"] = 16
data["2010-01-06"] = 32

(dates, values) = dict_to_dates_and_values(data)

xtitle = "Dates"
ytitle = "Values"
filename = "test.png"

plot_graph(xtitle, ytitle, dates, values, filename)

#  Use system verb and open the png in the default viewer.
os.startfile(filename, 'open')</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/73/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geotagging map of London</title>
		<link>http://www.lapthorn.net/archives/65</link>
		<comments>http://www.lapthorn.net/archives/65#comments</comments>
		<pubDate>Mon, 31 May 2010 14:14:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[random]]></category>
		<category><![CDATA[geotagging]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=65</guid>
		<description><![CDATA[Found this great site which has a series of geotagged maps of major cities, by the photos taken on flickr.   Interesting to see the usual hotspots around London are popular:  the West End, the City, Docklands, Greenwich, and then the few in the periphery, such as Wimbledon and Croydon.]]></description>
			<content:encoded><![CDATA[<div id="attachment_64" class="wp-caption alignright" style="width: 260px"><a href="http://www.flickr.com/photos/walkingsf/4621770253/in/set-72157623971287575/"><img class="size-full wp-image-64 " title="london geotagged" src="http://www.lapthorn.net/wp-content/uploads/london_geotag1.jpg" alt="" width="250" height="250" /></a><p class="wp-caption-text">London, as geotagged on flickr</p></div>
<p>Found this <a title="flickr" href="http://www.flickr.com/photos/walkingsf/sets/72157623971287575/"><span style="color: #888888;">great site</span></a> which has a series of geotagged maps of major cities, by the photos taken on <a href="http://www.flickr.com">flickr</a>.   Interesting to see the usual hotspots around London are popular:  the West End, the City, Docklands, Greenwich, and then the few in the periphery, such as Wimbledon and Croydon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/65/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Distributed and Normal Version Control Systems</title>
		<link>http://www.lapthorn.net/archives/51</link>
		<comments>http://www.lapthorn.net/archives/51#comments</comments>
		<pubDate>Sun, 30 May 2010 10:47:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DVCS]]></category>
		<category><![CDATA[VCS]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=51</guid>
		<description><![CDATA[Distributed version control systems (DVCS) have been around for quite a while, and I came across  Joel&#8217;s post and thought I ought to investigate. I had never looked at any DVCS before, but I have to admit, the article had the desired effect, and I finally bothered to download a DVCS tool, in this case, [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_69" class="wp-caption alignright" style="width: 132px"><a href="http://en.wikipedia.org/wiki/File:Revision_controlled_project_visualization-2010-24-02.svg"><img class="size-medium wp-image-69" title="vcs" src="http://www.lapthorn.net/wp-content/uploads/vcs-122x300.png" alt="" width="122" height="300" /></a><p class="wp-caption-text">Version Control</p></div>
<p>Distributed version control systems (DVCS) have been around for quite a while, and I came across  <a title="Joel On Software" href="http://www.joelonsoftware.com/items/2010/03/17.html">Joel&#8217;s post</a> and thought I ought to investigate.</p>
<p>I had never looked at any DVCS before, but I have to admit, the article had the desired effect, and I finally bothered to download a DVCS tool, in this case, <a title="Mercurial" href="http://mercurial.selenic.com/">mercurial</a>.  Since mercurial is written on top of <a title="Python" href="http://www.python.org/">python</a> it is nicely portable across platforms, and seems to present the same feature set on all platforms (Windows and <a title="Wubi" href="https://help.ubuntu.com/community/Wubi">linux</a>), including the built-in websever (with <a title="Mercurial repository" href="http://selenic.com/repo/hg/graph/ebc90fd4ebc0">nice branching graphs</a>).</p>
<p>So what is the fuss all about?  If you are used to &#8216;normal&#8217; version control systems such as <a title="Subversion" href="http://subversion.tigris.org/">subversion</a> then the most interesting difference is best explained in VCS terms:  when you &#8216;checkout&#8217; from the (main DVCS) repository you are always checking out a new branch.  That&#8217;s it really.</p>
<p>In normal VCS you would check out a copy of the repository, and your commits would go back onto the trunk/head of that repository, unless you created a branch, and checked that out.</p>
<p>In DVCS you always clone the entire repository onto your machine, and your commits go against your own clone of repository (that you cloned).  In effect, this is forced branching for the old VCS crowd.  Consequently, <a title="hg merge" href="http://hginit.com/04.html">merging</a> in DVCS systems is faster and better than in normal VCS systems (especially the older ones) as it is a core feature of DVCS.</p>
<p>The DVCS approach is great for most projects, e.g. linux (which famously uses <a title="Git" href="http://en.wikipedia.org/wiki/Git_%28software%29">git</a>).  However in large businesses <strong>control</strong> is key, and they still like to have a centrally hosted and administered repository, where all manner of control is applied to all manner of things (commit, branch, tagging rights, browsing etc.).   Branches are (generally) publicly viewable to anybody with access to the repository.</p>
<p>Any repository clones that you make (and branches off of the clone) are entirely private to your local machine, and do not pollute the main/master repository with dead-end branches.</p>
<p>One minor drawback of DVCS is that until you <a title="hg push" href="http://mercurial.selenic.com/wiki/Push">push</a> your changes back to the remote repository your changes are entirely local to your machine.  This is a drawback in the sense that in some businesses you have</p>
<ul>
<li>high turn over of staff
<ul>
<li>the developer doesn&#8217;t push back to the remote repository before they leave and their work is lost</li>
</ul>
</li>
<li>or, and it does happen, unstable developer machines (e.g. user allowed to install software, old hardware that fails etc.).
<ul>
<li>machine dies and work is lost</li>
</ul>
</li>
</ul>
<p>These are, frankly, <strong>minor</strong> issues.  If you push and pull frequently enough, you can always get your repository back from another developer.</p>
<p>One other minor issue with DVCS is that you are always cloning an <strong>entire</strong> repository.  For large repositories you are going to start getting performance issues based on, in no particular order:  bandwidth, main repository speed, and local disc performance.  This is equally true of VCS repositories.  However you can do <a title="Sparse checkouts" href="http://svnbook.red-bean.com/en/1.5/svn.advanced.sparsedirs.html">sparse checkouts</a>, which can help.</p>
<p>The general lesson to learn here for any type of VCS is to be quite ruthless with your repository management:  is it too large, are there too many projects (KDE is a classic example)?   If you use a <a title="Continuous integration" href="http://en.wikipedia.org/wiki/Continuous_integration">CI tool</a> as part of your build process (and you should), you are probably aware that the CI tool will often check out your entire repository (depending on set up), and therefore the repository size becomes a time issue for rebuilds.  For DVCS the overall main repository size (<strong>not </strong>the checked out repository) is going to be considerably smaller than a standard VCS repository as it will have had less commits made to it (and a higher percentage of useful ones).</p>
<p>DVCS have the benefit of being built from scratch based on several  decades of experience and usage of previous version control systems and <a title="Linus Torvalds" href="http://www.youtube.com/watch?v=4XpnKHJAok8">where they went  wrong</a>.  You can commit whenever you like, without having to worry  about meeting &#8216;commit requirements&#8217; such as test suites passing (until you commit to the master repository).  The performance is invariably much better than traditional VCS.  As mentioned by Linus Torvalds <a title="Linus Torvalds" href="http://www.youtube.com/watch?v=4XpnKHJAok8">here</a> (if you get the chance, watch the full one hour talk, but be objective about what is said), KDE imported  into git takes about 1.3Gb, in Subversion it takes over 4Gb, in other words DVCS efficiently stores data.</p>
<p>There seems to be a slight amount of <a title="Git is better?" href="http://whygitisbetterthanx.com">mania regarding DVCS</a>.  If you use an existing VCS and works for you, <a title="Eric Sink" href="http://www.ericsink.com/entries/dvcs_dag_2.html"><span style="color: #888888;">don&#8217;t worry!</span></a> If you&#8217;re starting a new project, consider DVCS.  If you&#8217;re starting a new project that is cross platform, consider Mercurial first.</p>
<p>Update: 05 June 2010:  Git also produces the same graphs that mercurial does via &#8216;hg server&#8217;, but from the command line.  See <a title="Git tree display" href="http://blog.kfish.org/2010/04/git-lola.html">here for details</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/51/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Release build issues</title>
		<link>http://www.lapthorn.net/archives/46</link>
		<comments>http://www.lapthorn.net/archives/46#comments</comments>
		<pubDate>Thu, 15 Apr 2010 15:30:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[release build]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=46</guid>
		<description><![CDATA[I&#8217;m sure I&#8217;m not the only person to come across this:  release builds that die in the middle of STL somewhere at runtime after being built by Visual Studio (2005 onwards I expect).  The short answer to this is that if you have put _SECURE_SCL=0 as a preprocessor define in one project, you need to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure I&#8217;m not the only person to come across this:  release builds that die in the middle of STL somewhere at runtime after being built by Visual Studio (2005 onwards I expect).  The short answer to this is that if you have put _SECURE_SCL=0 as a preprocessor define in one project, you need to ensure that it is in all projects.  Otherwise the compiler gets confused when optimising your code because of two more slightly differing template expansions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/46/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manifest Madness</title>
		<link>http://www.lapthorn.net/archives/28</link>
		<comments>http://www.lapthorn.net/archives/28#comments</comments>
		<pubDate>Fri, 24 Oct 2008 19:38:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows XP]]></category>

		<guid isPermaLink="false">http://www.lapthorn.net/?p=28</guid>
		<description><![CDATA[It seems that manifests were supposed to reduce the amount of dll hell that the average Windows developer experiences.  Whilst I am sure this is true, there seems to be a paucity of information on the web.  Finding information on manifests on the web seems to be a difficult task. I came across a manifest [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that manifests were supposed to reduce the amount of dll hell that the average Windows developer experiences.  Whilst I am sure this is true, there seems to be a paucity of information on the web.  Finding information on manifests on the web seems to be a difficult task.</p>
<p>I came across a manifest issue recently that I think is worth describing here precisely due to the lack of information elsewhere.</p>
<p>Disclaimer:  most of the opinions on OS behaviour are based on non-exhaustive observations of our particular problem, especially in the absence of any particularly obvious documentation.  They may not necessarily be correct.</p>
<p><strong>The Technical Problem.</strong></p>
<p>Quite simply, we have a C++/native comand line process (an exe and lots of dlls) built under Visual Studio 2005 on XP and Vista.  The release build works correctly as expected.  However, on a machine that does not have VS2005 installed the application fails to work:  it fails silently on the command line.  We ship the VC runtime redistributable dlls in the same folder as our exe along with their manifests.</p>
<p>Common wisdom on the web, which is basically solving the problem without actually understanding what the problem is, is to &#8220;just install the VC8 redistributable runtime on your machine&#8221;.  Personally, I cannot abide &#8216;fixing&#8217; something, without understanding what I&#8217;ve fixed and why it needed fixing, and you almost always find you reuse the knowledge you have learnt again in the future.</p>
<p><strong>The Non-Technical Problem.</strong></p>
<p>This is a work problem.  At my company, applications are automatically distributed to locked down machines that have no admin access.  Rolling out the redistrbutable patch, for purely bureaucractic reasons, is not a solution.  Also, I only have one test machine, and have to therefore be very careful with what I install on it, otherwise I have to wait for a long time for the machine to be rebuilt.</p>
<p><strong>Preamble</strong></p>
<p>Since it is obvious that installing VS2005 would solve the problem, and most likely the redistributable package, in order to start diagnosing the problem, we need to put the minimal set of tools on a machine, in this case Windows XP.</p>
<p>At this point, I wasn&#8217;t aware of what the problem actually was, so the first stop was our good old friend depends.exe (<a href="http://www.dependencywalker.com">http://www.dependencywalker.com</a>).</p>
<p>Hint 1:  I would suggest to anyone working in a corporate or otherwise locked down environment to either ship a set of tools with your application or making them available on an internal network drive.</p>
<p>Once I had loaded the application into depends, it appeared that everything was fine.  Later, however, it was obvious that this was not the case.  Buried in one of the collapsed nodes was a problem that I did not see.</p>
<p>The next step was to fire up the venerable DrWatson.  Straight away it was clear that the application was doing the Windows equivalent of a core dump.  The dump itself was apparently pointing to a empty (non-pure) virtual function that returned a void.  At this point I was still under the misguided idea that the problem was caused by a problem that could be diagnosed by a debug or core dump analysis.</p>
<p>After some head scratching, I decided to get windbg installed on the test machine.  This would have a low impact on the machine configuration as it would not install lots of unnecessary junk in order to work.  It did, of course, require admin rights:  exactly what you don&#8217;t need in a corporate environment.</p>
<p>Firing up the Windows debugger and attaching it to our process, it was clear on the very first run that the problem lay after a particular dll load event.  In this instance the debugger was also pointing to a different dll and a different part of the code.</p>
<p>Hint 2:  ship .map and .pdb files with your release build, and keep a copy of the build available: source code, pdb, objects etc.</p>
<p>I now started to investigate the loading of the dlls.  Next stop was psmon from the sysinsternals/Microsoft website.  Running this against my process then confirmed the loading that I saw in the Windows debugger with a little bit more interesting, including the attempted load of &#8216;our.dll.2.manifest&#8217;.  Whilst this would not appear to be an error, it is what first attracted my attention back to manifest files.</p>
<p>Back to depends.exe;  I now tried to load &#8216;our.dll&#8217; into depends.exe and received the message:</p>
<p>&#8220;The side-by-side configuration information for &#8216;our.dll&#8217; contains errors.  This application has failed to start because the application configuration is incorrect.  Reinstalling the application may fix the problem.&#8221;</p>
<p>How is that for a helpful message?  At least it is a start.  So the problem with the silent failure of our application is now firmly identified to lie withing &#8216;our.dll&#8217;.  There were also additional system log messages in the event viewer, including the usual &#8216;the command completed successfully&#8217; in a reported error.<br />
<strong><br />
Debugging manifests</strong></p>
<p>The next stop was google.  What does the error mean, and how do I debug it for more information?  I then found this &#8220;<a href="http://blogs.msdn.com/junfeng/archive/2006/04/14/576314.aspx">classic</a>&#8221; (for all the wrong reasons).</p>
<p>The summary is that you can debug the manifest/sxs but only on Vista.</p>
<p>Yes, that&#8217;s right, Windows XP has manifests, but you can&#8217;t get a dump of the manifest files.  If you know otherwise, leave a comment below.</p>
<p>As luck would have it, I have a Vista box.  Unfortunately, it has Visual Studio 2005 installed, and therefore, the offending application works on that machine.  Giving sxstrace a go, doesn&#8217;t reveal anything I didn&#8217;t already expect to see.  Running it was a little strange:  start a console window, and run<br />
<code>sxstrace trace -logfile:sxstrace.etl</code></p>
<p>In a second console:<br />
<code>myapp.exe</code></p>
<p>Wait for it to finish, back to console 1, hit enter to stop the trace, then:<br />
<code>sxstrace parse -logfile:sxstrace.etl -outfile:sxstrace.txt</code></p>
<p>to make it human readable.  This then gives you a summary of the manifests that the dll depends on.  As this gave no information as it was running on a machine where the app worked, I went back to depends.exe.</p>
<p>Hint 3:  In depends.exe expand all nodes, and switch on the full path option for the dlls.</p>
<p>At this point I noticed that part of the dll in question was referencing another dll that was in turn referencing an out of date VC8 runtime.</p>
<p>This is where the manifest madness begins.  As far as I am aware, under Windows 2000 onwards, the <a href="http://msdn.microsoft.com/en-us/library/ms682586.aspx">search behaviour for a dll</a> named &#8216;widget.dll&#8217; (for example), is to search the local folder first, except in the presence of manifests or redirection.  The behaviour with manifests is to load dlls via their manifest descriptions first.</p>
<p>Hint 4:  One way to see the manifest of a dll is to just drag into Visual Studio, and look at the second resource ordinal.</p>
<p>Consequently our app appeared to be loading two versions of the VC80 runtime.  There are two workarounds to this.  The first is to rebuild the offending dll against a newer version of the VC runtime.</p>
<p>If you cannot do that, for example, it is a third party dll, then you can <a href="http://blogs.msdn.com/nikolad/archive/2007/03/29/a-solution-to-two-references-to-different-versions-of-crt-mfc-atl-in-one-application-manifest-file.aspx">redirect the loading</a> by creating an &#8216;ourapp.exe.config&#8217; file.  Of course, this didn&#8217;t work for us, but we were lucky in that we could recompile the dll.  However, the extra manifest entry still appeared to be there.</p>
<p>The reason why the app.exe.config doesn&#8217;t work is also interesting.  As far as I can find there is no documentation that states this explicitly:  application config files can only do binding redirects if the dlls they are redirecting are installed in the WinSxS folder.  The behaviour I was hoping for (which may not be correct, since this mechanism covers the .NET world as well), is that the redirect occurs on and to a manifest file and dll in the current working directory of your application.</p>
<p>Back to the problem;  the recompiled dll still showed that the second version of the vc runtime was in the manifest.  At this point depends was telling us that nothing directly depended on the oldest vc runtime.</p>
<p>So the question then was &#8220;where is this extra manifest entry coming from?&#8221;  In the land of Unix:<br />
<code>find . | xargs grep 50608</code></p>
<p>will find all files that contain the string &#8217;50608&#8242; which is part of the version number of the offending vc runtime.  Without using such a scatter gun approach, we know that the value can only be coming from a limited number of places, the source code, or something that is linked in.  We knew it wasn&#8217;t the source code, so that left some static libs.</p>
<p>Dragging each one into notepad finally revealed that on of the static libs that we use was referencing the old vc runtime.  This therefore meant that that particular static lib was built at some point by VS2005 RTM, and not VS2005 SP1 which the rest of the application was being built with.  By some good fortune it was our (not my!) source code, and we resurrected it, rebuilt it, and guess what?</p>
<p>Problem solved!</p>
<p><strong>Summary</strong></p>
<p>After this somewhat lengthy article, the summary is brief:  I located the problem to be in &#8216;our.dll&#8217;, and that the problem was in turn due to an old lib built by an older compiler that was being linked in.</p>
<p>It is really disappointing that on Windows XP, at least, there does not appear to be a tool for further diagnosing dll problems such as this, other than a random scattering of blog postings, and poor documentation.</p>
<p>At the very least there should be a tool that list the manifests of each dll, and where they were found.  The manifest tool, in verbose mode, does not do this.</p>
<p>Final note:  if you choose to leave a comment, please be helpful and polite.  If you have questions about manifests, it&#8217;s unlikely I&#8217;ll be able to help beyond what I learnt whilst writing this article.</p>
<p><strong>Troubleshooting manifests</strong></p>
<p>These are a list of links that I gradually worked through to figure out what on earth was going on:</p>
<p><a href="http://channel9.msdn.com/forums/TechOff/22266-Side-by-side-screwup/?CommentID=272900">http://channel9.msdn.com/forums/TechOff/22266-Side-by-side-screwup/?CommentID=272900</a></p>
<p><a href="http://blogs.msdn.com/jreddy/archive/2005/12/23/troubleshooting-c-c-isolated-applications-and-side-by-side-assemblies-scenario-based-with-solutions.aspx">http://blogs.msdn.com/jreddy/archive/2005/12/23/troubleshooting-c-c-isolated-applications-and-side-by-side-assemblies-scenario-based-with-solutions.aspx</a><br />
<a href=" http://blogs.msdn.com/dsvc/archive/2008/08/07/part-2-troubleshooting-vc-side-by-side-problems.aspx"></p>
<p>http://blogs.msdn.com/dsvc/archive/2008/08/07/part-2-troubleshooting-vc-side-by-side-problems.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lapthorn.net/archives/28/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
