<?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>esmithy.net &#187; Uncategorized</title>
	<atom:link href="http://esmithy.net/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://esmithy.net</link>
	<description>Stuff Hammered Out by Eric Smith</description>
	<lastBuildDate>Tue, 17 Apr 2012 03:06:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Kindle for Technical Reading</title>
		<link>http://esmithy.net/2012/01/24/kindle-for-technical-reading/</link>
		<comments>http://esmithy.net/2012/01/24/kindle-for-technical-reading/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 01:21:48 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://esmithy.net/?p=526</guid>
		<description><![CDATA[I&#8217;ve read several novels in Amazon Kindle format (on an actual Kindle device, the PC client, or an iPad), and the experience is pretty good. But having now finished reading a technical book that way, I think there is plenty of room for improvement. The book I read is Jez Humble and David Farley&#8217;s Continuous Delivery: [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve read several novels in Amazon Kindle format (on an actual Kindle device, the PC client, or an iPad), and the experience is pretty good. But having now finished reading a technical book that way, I think there is plenty of room for improvement.</p>
<p><span id="more-526"></span>The book I read is Jez Humble and David Farley&#8217;s<em> <a href="http://www.amazon.com/gp/product/B003YMNVC0/ref=as_li_ss_tl?ie=UTF8&amp;tag=sparksfromthesmi&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B003YMNVC0">Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation</a>. </em>I&#8217;m not sure if the weaknesses are due to Amazon&#8217;s ebook platform, this particular title, or some combination of both, but these were the issues I had:</p>
<ol>
<li>The table of contents as displayed by the PC reader application, isn&#8217;t detailed enough.  The book is divided into three sections, and the sections appear in the ToC, but none of the chapters in the sections do. One of the entries in the ToC is the Contents as it appears in the book itself (which is also where you go if you choose Table of Contents from the iPad menu). It has links to everywhere, but is extremely detailed and spans 19 pages, making it cumbersome to use. There&#8217;s no easy way to just jump to a particular chapter.</li>
<li>Cross references don&#8217;t tell where they&#8217;re going in a meaningful way. They reference other parts of the book by page number, but Kindle books don&#8217;t have page numbers. There <em>is</em> a link, so not all is lost, but I couldn&#8217;t tell if a cross reference was to some part of the book I had already read (and that I ought to therefore nod and say, &#8220;Oh, yeah&#8221;) or somewhere later on. Maybe just a little arrow icon pointing left or right would have been a good hint.</li>
<li>The index is cumbersome. There aren&#8217;t any links to jump to the different letter sections, so if you want to look up &#8220;Tests&#8221;, be prepared to flip through <em>a lot</em> of pages to get to the T&#8217;s.</li>
<li>The figures are too low-res. One in particular, 15.1, was almost completely unreadable. It sounded like a really interesting chart, but it was just too small and couldn&#8217;t be zoomed so I feel kind of cheated out of that.</li>
<li> Compound words were problematic because the dashes were usually dropped and the words mashed together. Apparently someone/something confused them  with dashes as a result of layout (to split words across lines) and dropped them all.</li>
</ol>
<p>It seems possible that Apple, with their new iBooks 2 platform and its textbook focus,  could end up being a better experience for technical books like this. I&#8217;ll be interested to give it a try.</p>
]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2012/01/24/kindle-for-technical-reading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Holiday Amazon Box Problem</title>
		<link>http://esmithy.net/2011/12/26/the-holiday-amazon-box-problem/</link>
		<comments>http://esmithy.net/2011/12/26/the-holiday-amazon-box-problem/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 22:45:56 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://esmithy.net/?p=502</guid>
		<description><![CDATA[By the time Christmas comes around, our house is usually awash with boxes from Amazon. It gets a bit tricky at that point, because I&#8217;m never sure if the box is something I ordered to give to my family, or something someone else sent me as a gift. In the former case, I&#8217;ll want to [...]]]></description>
			<content:encoded><![CDATA[<p>By the time Christmas comes around, our house is usually awash with boxes from Amazon. It gets a bit tricky at that point, because I&#8217;m never sure if the box is something I ordered to give to my family, or something someone else sent me as a gift. In the former case, I&#8217;ll want to wrap it and put it under the tree. In the latter, a lot of times my wife will wrap it on behalf of the giver so it can still be a surprise Christmas morning. The problem is telling them apart.</p>
<p><span id="more-502"></span></p>
<p>I guess I&#8217;m not the only one with this problem. A friend sent me a message thanking me for a gift basket I&#8217;d sent him a couple of weeks ago. He hadn&#8217;t opened it until it was time to start wrapping all the presents he&#8217;d ordered himself from Amazon. Hopefully the food was still edible.</p>
<p>At first I was thinking that Amazon needs to figure out how to solve that problem. If I were Amazon, I might just suggest gift wrapping presents to others so that it is always safe to open the box, but gift wrap starts to get expensive &#8212; especially if you have several less-expensive items.</p>
<p>Another solution is to address the packages in a way that differentiates them. I&#8217;ve changed my wishlist address so that it includes &#8220;(Wishlist)&#8221; after my name. My regular ordering address now has &#8220;(Self Order)&#8221; after my name. Now maybe I just need to add &#8220;(A gift for you)&#8221; after the names of my friends to tip them off.</p>
<p>I guess I&#8217;ll see how it goes&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2011/12/26/the-holiday-amazon-box-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sprint Makes Me Laugh</title>
		<link>http://esmithy.net/2011/05/23/sprint-makes-me-laugh/</link>
		<comments>http://esmithy.net/2011/05/23/sprint-makes-me-laugh/#comments</comments>
		<pubDate>Tue, 24 May 2011 03:19:43 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://esmithy.net/?p=457</guid>
		<description><![CDATA[I got this flyer from Sprint. I wonder if they wrote that &#8220;protecting more than ever before&#8221; with a straight face or what. &#160;]]></description>
			<content:encoded><![CDATA[<p>I got this flyer from Sprint. I wonder if they wrote that &#8220;protecting more than ever before&#8221; with a straight face or what.</p>
<p><span id="more-457"></span></p>
<p><img class="aligncenter size-full wp-image-458" title="Protecting more than ever before" src="http://esmithy.net/content/IMG-640x414-500x323.jpg" alt="Protecting more than ever before" width="500" height="323" /></p>
<p>&nbsp;<br />
<img class="aligncenter size-full wp-image-459" title="New program? $1 more!" src="http://esmithy.net/content/IMG_0001-500x463.jpg" alt="New program? $1 more!" width="500" height="463" /></p>
]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2011/05/23/sprint-makes-me-laugh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OK, Maybe TurboTax Is Worth It</title>
		<link>http://esmithy.net/2011/03/28/ok-maybe-turbotax-is-worth-it/</link>
		<comments>http://esmithy.net/2011/03/28/ok-maybe-turbotax-is-worth-it/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 03:18:48 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://esmithy.net/?p=445</guid>
		<description><![CDATA[I was a bit of a masochist this year. I actually did my federal taxes twice, trying to figure out if there is a cheaper alternative to using TurboTax. But TurboTax, in spite of costing more, ended up being the cheaper option by a long shot. The whole United States tax system is a mess. [...]]]></description>
			<content:encoded><![CDATA[<p>I was a bit of a masochist this year. I actually did my federal taxes twice, trying to figure out if there is a cheaper alternative to using TurboTax. But TurboTax, in spite of costing more, ended up being the cheaper option by a long shot.<br />
<span id="more-445"></span><br />
The whole United States tax system is a mess. That the average citizen can&#8217;t pay their taxes without some kind of help just irks me. That so many people rely on that fact for their livelihood (tax accountants, software makers, etc.) and that it is easier for congress to throw something into the tax code than introduce real legislation convinces me that it is unlikely to change anytime soon.</p>
<p>General rant aside, I also get tired of paying $60 for TurboTax every year, so I cancelled my automatic subscription, determined to try something else this time around. After reading some reviews, I decided to go with <a href="http://www.taxact.com/">TaxACT Online</a>, which looked to be reasonably good and quite a bit less expensive. The nice thing is that you can use the application for free until you&#8217;re ready to actually file or print your return.</p>
<p>There were a few times that I felt unsure about what I was doing while doing my return &#8212; I had some employee stock purchase program things last year to complicate matters. I eventually made it through, though, itemizing my deductions since I&#8217;ve got mortgage interest and lots of charitable donations. My remaining federal tax liability at the end was around $500. </p>
<p>That felt wrong to me. I don&#8217;t think I&#8217;ve <em>ever</em> owed federal taxes beyond what had already been withheld. State taxes, sure &#8212; I frequently owe some there &#8212; but owing federal taxes was enough to encourage me to take a run through <a href="http://turbotax.intuit.com/tax-tools/calculators/taxcaster/">TurboTax&#8217;s estimator</a>. That gave me hope that I might be able to get a more favorable result.</p>
<p>Doing taxes is far from fun, but it was definitely easier with <a href="https://turbotax.intuit.com/login/start.jsp?priorityCode=3468337910&#038;productid=16&#038;abtest=PONHelp%3DC%26feereview%3DC%26EFSelection%3DB%26MintBranded%3DB">TurboTax Online</a>. I felt more like I was being guided along rather than being presented with a bunch of text to read and some form inputs to fill in. I was also able to import a lot of data electronically, which helped with both speed and accuracy. When I finished my federal return (for the second time), I came out with about a $1500 <em>refund</em>.</p>
<p>Maybe I did something wrong with TaxACT. Maybe I did something wrong with TurboTax, but the refund was more in line with previous years. Certainly for my situation, TurboTax was clearly worth the price of admission.</p>
]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2011/03/28/ok-maybe-turbotax-is-worth-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evernote vs. OneNote</title>
		<link>http://esmithy.net/2011/03/05/evernote-vs-onenote/</link>
		<comments>http://esmithy.net/2011/03/05/evernote-vs-onenote/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 16:59:23 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://esmithy.net/?p=436</guid>
		<description><![CDATA[I&#8217;ve used both Evernote and Microsoft OneNote for several years. While there are lots of extensive comparisons of the applications around, I think the difference between them comes down to just a few broad issues. Evernote has these things going for it: Ubiquity Price (free) OneNote&#8217;s list is shorter: It&#8217;s a truly excellent Windows application [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve used both <a href="http://www.evernote.com/" target="_blank">Evernote</a> and <a href="http://office.microsoft.com/en-us/onenote/" target="_blank">Microsoft OneNote</a> for several years. While there are lots of extensive comparisons of the applications around, I think the difference between them comes down to just a few broad issues.<br />
<span id="more-436"></span><br />
Evernote has these things going for it:</p>
<ol>
<li>Ubiquity</li>
<li>Price (free)</li>
</ol>
<p>OneNote&#8217;s list is shorter:</p>
<ol>
<li>It&#8217;s a truly excellent Windows application</li>
</ol>
<p>The folks at Evernote can&#8217;t quite seem to get their act together. I think the Windows application has been through at least two complete rewrites since I&#8217;ve been using it, each time with the promise that <em>this</em> version will finally be the solid platform on which fantastic new features will be added. But the editing abilities still compare unfavorably to 1990&#8242;s-era HTML editors.</p>
<p>I can expect, though, that I&#8217;ll be able to find an Evernote client for pretty much any platform I want, with data synchronized between all of them because of Evernote&#8217;s cloud focus. Not all of the clients are created equal &#8212; Evernote for the iPad simply refuses to edit notes with &#8220;rich&#8221; formatting &#8212; but they aren&#8217;t bad.</p>
<p>OneNote&#8217;s anchor to Desktop Windows has been its biggest downfall. The cloud-stored notebooks of OneNote 2010 are a great advancement, but Microsoft needs clients for other platforms &#8212; and <em>good</em> clients at that. Even when I had a Windows Mobile phone a few years ago, the OneNote client there was pathetic. I regularly run Evernote clients on Windows, Mac, iOS (iPad) and webOS, and until I can do the same with OneNote, it&#8217;s hard to imagine it becoming my primary exocortex. That Microsoft has released an <a href="http://itunes.apple.com/us/app/microsoft-onenote/id410395246?mt=8" target="_blank">iPhone client</a> is promising. Hopefully they&#8217;ll continue to add other platforms.</p>
<p>Using OneNote on Windows is a delight. Formatting works as expected instead of suddenly flaking out like it does in Evernote. Tables are easy to work with and look good. Images can be resized in-line. Screen clips go into the note I&#8217;m editing instead of a separate note, which is the behavior I want 95% of the time.</p>
<p>That Evernote is free is nice, but I&#8217;ve got 80 bucks sitting right here for OneNote if it can make that final jump to universal access.</p>
]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2011/03/05/evernote-vs-onenote/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress</title>
		<link>http://esmithy.net/2007/04/28/wordpress/</link>
		<comments>http://esmithy.net/2007/04/28/wordpress/#comments</comments>
		<pubDate>Sat, 28 Apr 2007 18:06:20 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://esmithy.net/2007/04/28/wordpress/</guid>
		<description><![CDATA[After years of building this site with my own custom software, I&#8217;ve decided to switch to WordPress. My previous system started with XHTML content transformed through various XSLT style sheets thatproduced summaries, an RSS feed, a Google sitemap, and a common appearance across all the pages. The whole process was driven by an Ant script, [...]]]></description>
			<content:encoded><![CDATA[<p>After years of building this site with my own custom software, I&#8217;ve decided to switch to <a title="WordPress" href="http://wordpress.org">WordPress</a>.</p>
<p><span id="more-91"></span></p>
<p>My previous system started with XHTML content transformed through various XSLT style sheets thatproduced summaries, an RSS feed, a Google sitemap, and a common appearance across all the pages. The whole process was driven by an Ant script, and required no server-side code except for a comments form. It worked pretty well except for a few things:</p>
<ul>
<li>Running the scripts (which included FTP to the server) to publish a new article took a while, so it wasn&#8217;t something you could just quickly do.</li>
<li>The scripts were only available on one machine, so publishing could only happen from there.</li>
<li>When my comments form was turned on, it got a bunch of comment spam.</li>
<li>If I wanted any new features, I had to do them all myself.</li>
</ul>
<p>I thought I&#8217;d take a look at some actual blogging software to see what was available. I ran across an extensive comparison (though I can&#8217;t remember where that was now) where the person doing the comparison decided on using WordPress. I had thought about trying to use a .NET application, since I&#8217;m trying hard to learn .NET deeply right now, but there was a telling comment about .Text (the only .NET blogging tool considered) in the comparison. The reviewer said something like, &#8220;.NET programmers are more excited about .NET than actual working software.&#8221; While a sweeping generalization, I sense a bit of truth in there. Also, as a programmer, it is good to be exposed to lots of things, so a PHP application seemed good for technical diversification.</p>
<p>I created my own WordPress theme, both in order to preserve my site&#8217;s look as well as to learn more about WordPress. Then I needed a way to migrate my content. I don&#8217;t have a ton of articles, but certainly more than a manual approach would work for. I tried adding a couple of articles by hand, and quickly discovered that the WordPress editor treats all whitespace as significant, unlike HTML&#8217;s text flowing regardless of line breaks.</p>
<p>My first attempt at an automatic import was to transform my content to WordPress&#8217; native export/import format. I abandoned that after a little while because it was based on RSS, but added a bunch of stuff that wasn&#8217;t really relevant for my content. I realized that I might as well just do an RSS import, which was easier.</p>
<p>The significant whitespace characteristics I noticed in the editor carried over to imports as well, so my conversion program had to strip out all the non-significant linefeeds out. I also discovered that if there were XML namespace declarations where the importer didn&#8217;t expect them, then it would think that there weren&#8217;t any posts to import. It would just say, &#8220;All done! Have Fun!&#8221;, which was kind of infuriating until I figured it out. I think I&#8217;ve heard someone say that blogging software is only as good as its import and export functions, and I almost gave up on WordPress at this point.</p>
<p>Once I got my content imported, I was happier about WordPress when I discovered Ryan McGeary&#8217;s <a title="WP-Syntax Plugin" href="http://wordpress.org/extend/plugins/wp-syntax/">WP-Syntax Plugin</a>. I had thought about doing something like that myself at some point. I did make one small tweak to the plugin, though. GeSHi&#8217;s default syntax colorings were a bit too much for me, so I switched the GeSHi option over to use CSS styles for the highlighting, and chose fewer and more subtle colorings. I&#8217;m sure there are lots of other interesting plugins that I&#8217;ve yet to discover.</p>
<p>There have been some glitches (bug-like behavior), some manual work required even after my automatic import, and still some things to figure out, but I&#8217;m optimistic that WordPress will work out.</p>
]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2007/04/28/wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>By Chance</title>
		<link>http://esmithy.net/2005/10/20/by-chance/</link>
		<comments>http://esmithy.net/2005/10/20/by-chance/#comments</comments>
		<pubDate>Fri, 21 Oct 2005 00:00:00 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://esmithy.net/wp/?p=61</guid>
		<description><![CDATA[A few years ago I was reading some books about biological evolution. At some point, probably reading something by Richard Dawkins, I was thinking about randomness and its ability to produce apparently non-random things. All you need is a little pressure that selects one random thing over another. So I wrote a little program that [...]]]></description>
			<content:encoded><![CDATA[<p>A few years ago I was reading some books about biological evolution. At some point, probably reading something by Richard Dawkins, I was thinking about randomness and its ability to produce apparently non-random things. All you need is a little pressure that selects one random thing over another. So I wrote a little program that demonstrates the idea by transforming a black box into a picture through entirely random steps.<span id="more-61"></span></p>
<p>My program, ByChance, works like this. You supply an image that represents the ideal in survivability. Once you&#8217;ve done that, you click the &#8220;Start&#8221; button. The program starts with a black image with the same dimensions as the &#8220;fitness&#8221; image you picked. It then proceeds to pick a pixel in the image at random (around 200,000 possibilities, depending on the shape of the image). Then it picks a random color (24 bits, so there are around 16.8 million possibilities) for the random pixel and tests the survivability of the new picture. If the new picture is more like the &#8220;fitness&#8221; picture than what was there previously, the new picture, with its single different pixel wins. If not, what was there before wins. The program displays the winning picture, and also keeps a running total of the number of generations that have happened. A generation is every time a pixel changes and the fitness test is done.</p>
<p class="photo"> </p>
<p><span class="caption"><img class="aligncenter size-full wp-image-209" title="ByChance Screen Shot (Early)" src="http://esmithy.net/content/by-chance1.jpg" alt="" width="500" height="475" /></span></p>
<p><span class="caption">Early Screen Shot</span></p>
<p><span class="caption"><img class="aligncenter size-full wp-image-205" title="ByChance Screen Shot" src="http://esmithy.net/content/by-chance2.jpg" alt="" width="500" height="475" /></span></p>
<p><span class="caption">Later Screen Shot</span></p>
<p>I&#8217;m certainly not an expert in evolutionary theory, but it seems like the program serves as an interesting analogy. I should point out that evolution doesn&#8217;t have a perfectly ideal goal that it is shooting for like the fitness image. Given the forces of nature around us and all the aspects of our environment, there is pressure toward a survivable form.</p>
<p>Some of the choices I made in writing the program were arbitrary:</p>
<ul>
<li>Why not make the image size random too?</li>
<li>Why start with black? Why not start with white or a completely random starting image?</li>
</ul>
<p>Maybe something a little different would be a better analogy of our best understanding of what really happens. This experiment is kind of related to the <a href="http://en.wikipedia.org/wiki/Infinite_monkey_theorem">infinite monkey theorem</a>, but with not so many permutations and with pressure toward correctness.</p>
<p>After running the program several times, I&#8217;ve noticed a couple of things. The image becomes recognizable really fast. The image becomes perfect some time later than my patience allows for, but I expect it would take a really,<em>really</em> long time.</p>
<p>If you would like to run ByChance, you can <a href="http://esmithy.net/software/bychance-an-experiment-with-randomness/">download it from here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2005/10/20/by-chance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>.NET Context Menu Handler</title>
		<link>http://esmithy.net/2005/04/07/net-context-menu-handler/</link>
		<comments>http://esmithy.net/2005/04/07/net-context-menu-handler/#comments</comments>
		<pubDate>Fri, 08 Apr 2005 00:00:00 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://esmithy.net/wp/?p=55</guid>
		<description><![CDATA[I&#8217;ve been working on a context menu handler shell extension in C# lately. There are a few samples that people have produced on the web (for example, The Code Project, pek.com, and TheServerSide.net). I&#8217;ve found a better way of implementing IShellExtInit.Initialize than in the examples I&#8217;ve seen. The point of IShellExtInit.Initialize is for the shell [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a context menu handler shell extension in C# lately. There are a few samples that people have produced on the web (for example, <a href="http://www.codeproject.com/csharp/ratingcolumn.asp">The Code Project</a>, <a href="http://www.pek.com/blogs/pek/archives/2005/02/c_explorer_cont.php">pek.com</a>, and <a href="http://www.theserverside.net/articles/showarticle.tss?id=ShellExtensions">TheServerSide.net</a>). I&#8217;ve found a better way of implementing <code>IShellExtInit.Initialize</code> than in the examples I&#8217;ve seen.</p>
<p><span id="more-55"></span></p>
<p>The point of <code>IShellExtInit.Initialize</code> is for the shell to let your handler know which files are selected so that you can display your context menu based on, believe it or not, <em>context</em>. Here is a typical implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">int</span> IShellExtInit<span style="color: #008000;">.</span><span style="color: #0000FF;">Initialize</span> <span style="color: #008000;">&#40;</span>IntPtr pidlFolder, IntPtr lpdobj, <span style="color: #6666cc; font-weight: bold;">uint</span> hKeyProgID<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">try</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// save the information about the selection</span>
    m_dataObject <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>lpdobj <span style="color: #008000;">!=</span> <span style="color: #008000;">&#40;</span>IntPtr<span style="color: #008000;">&#41;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      m_dataObject <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ShellLib<span style="color: #008000;">.</span><span style="color: #0000FF;">IDataObject</span><span style="color: #008000;">&#41;</span>Marshal<span style="color: #008000;">.</span><span style="color: #0000FF;">GetObjectForIUnknown</span><span style="color: #008000;">&#40;</span>lpdobj<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      FORMATETC fmt <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FORMATETC<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      fmt<span style="color: #008000;">.</span><span style="color: #0000FF;">cfFormat</span> <span style="color: #008000;">=</span> CLIPFORMAT<span style="color: #008000;">.</span><span style="color: #0000FF;">CF_HDROP</span><span style="color: #008000;">;</span>
      fmt<span style="color: #008000;">.</span><span style="color: #0000FF;">ptd</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
      fmt<span style="color: #008000;">.</span><span style="color: #0000FF;">dwAspect</span> <span style="color: #008000;">=</span> DVASPECT<span style="color: #008000;">.</span><span style="color: #0000FF;">DVASPECT_CONTENT</span><span style="color: #008000;">;</span>
      fmt<span style="color: #008000;">.</span><span style="color: #0000FF;">lindex</span> <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
      fmt<span style="color: #008000;">.</span><span style="color: #0000FF;">tymed</span> <span style="color: #008000;">=</span> TYMED<span style="color: #008000;">.</span><span style="color: #0000FF;">TYMED_HGLOBAL</span><span style="color: #008000;">;</span>
      STGMEDIUM medium <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> STGMEDIUM<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      m_dataObject<span style="color: #008000;">.</span><span style="color: #0000FF;">GetData</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">ref</span> fmt, <span style="color: #0600FF; font-weight: bold;">ref</span> medium<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      m_hDrop <span style="color: #008000;">=</span> medium<span style="color: #008000;">.</span><span style="color: #0000FF;">hGlobal</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">catch</span><span style="color: #008000;">&#40;</span>Exception<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Then later on, to get the selected file:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Get the file name to work with</span>
StringBuilder sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1024</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Helpers<span style="color: #008000;">.</span><span style="color: #0000FF;">DragQueryFile</span><span style="color: #008000;">&#40;</span>m_hDrop, <span style="color: #FF0000;">0</span>, sb, sb<span style="color: #008000;">.</span><span style="color: #0000FF;">Capacity</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>There&#8217;s a fair amount of nasty interop going on here, which is sometimes inevitable for things like shell extensions. In this case, however, you can actually use the .NET Framework&#8217;s DataObject class instead for much simpler code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">int</span> IShellExtInit<span style="color: #008000;">.</span><span style="color: #0000FF;">Initialize</span> <span style="color: #008000;">&#40;</span>IntPtr pidlFolder, IntPtr lpdobj, <span style="color: #6666cc; font-weight: bold;">uint</span> hKeyProgID<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  DataObject dataObject <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataObject<span style="color: #008000;">&#40;</span>lpdobj<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> selectedFiles <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>dataObject<span style="color: #008000;">.</span><span style="color: #0000FF;">GetData</span><span style="color: #008000;">&#40;</span>DataFormats<span style="color: #008000;">.</span><span style="color: #0000FF;">FileDrop</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://esmithy.net/2005/04/07/net-context-menu-handler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

