<?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</title>
	<atom:link href="http://www.voyce.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Wed, 11 Aug 2010 03:56:45 +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>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F08%2F10%2Fholiday%2F&amp;t=Holiday&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></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>Minilight renderer in F#</title>
		<link>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/</link>
		<comments>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 17:19:43 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[monte carlo]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=938</guid>
		<description><![CDATA[Porting the Minilight global illumination renderer to F#.]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_961" class="wp-caption alignleft" style="width: 150px"><a href="http://www.voyce.com/wp-content/uploads/2010/06/cornellbox-e.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/cornellbox-e.png" alt="Cornell Box in the evening" title="cornellbox-e" width="140" height="140" class="size-full wp-image-961" /></a><p class="wp-caption-text">Cornell Box in the evening</p></div>I&#8217;m a sucker for eye-candy, and the other day I came across the beautifully lit renders produced by <a href="http://www.hxa.name/minilight/">Minilight</a>. It&#8217;s a nice, minimal implementation of a global illumination renderer that&#8217;s been ported to a wide variety of different languages from C to ActionScript. So of course, I couldn&#8217;t resist trying to implement it in F#.<br />
<span id="more-938"></span></p>
<h3>What is a &#8220;global illumination renderer&#8221;?</h3>
<p>In short; a global illumination renderer attempts to simulate the way that light behaves in the real world. It bounces rays of light around the scene, noting which surfaces are hit, and how each of them affects the ray. Of course real light travels fast &#8211; at about the speed of light, in fact &#8211; and our simulated rays can&#8217;t match that, so although the resulting effect looks natural, it&#8217;s not a very efficient way of getting there. Graphics systems that need to be near real-time (i.e. games), use a variety of short-cuts to try and get the same effect without requiring the same amount of number crunching.</p>
<p>Even this implementation is forced to use a couple of techniques to improve performance, I won&#8217;t go into them here, as they&#8217;re explained pretty thoroughly on the Minilight site. </p>
<p>Interestingly the algorithm uses a Monte Carlo technique to simulate the random path of the ray through the scene and the same technique is used in finance to model how the price of an asset will change through time. </p>
<h3>Translating to F#</h3>
<p><div id="attachment_970" class="wp-caption alignright" style="width: 160px"><a href="http://www.voyce.com/wp-content/uploads/2010/06/roomfront.sun.ml.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/roomfront.sun.ml-150x150.png" alt="Room with sun and light, 800 paths per pixel" title="roomfront.sun.ml" width="150" height="150" class="size-thumbnail wp-image-970" /></a><p class="wp-caption-text">Room with sun and light, 800 paths per pixel</p></div>Luckily, the existing OCaml version is considered one of the reference implementations, and as ML is the spiritual predecessor of F# I didn&#8217;t expect it to be too difficult to port. It wasn&#8217;t. I&#8217;m no ML expert, so some of the language features were a bit of a surprise; things like the use of a dot on all of the operators, but these are pretty minimal syntactic differences.</p>
<p>Some of the ML constructs caused warnings from the F# compiler as I didn&#8217;t use the explicit ML compatibility mode. For instance, the use of the <code>^</code> operator to concatenate strings:<br />
<code><br />
warning FS0062: This construct is for ML compatibility. Consider using the '+' operator instead. This may require a type annotation to indicate it acts on strings.<br />
</code><br />
Some other changes included:</p>
<ul>
<li>Using dot rather than # notation to access class members</li>
<li>Using square bracket for array element access (<code>array.[n]</code> rather than <code>array.(n)</code>)</li>
<li>Removing <code>let...and</code> for non-recursive bindings</li>
</ul>
<p>There was also the opportunity to make use of some of the .NET framework classes, things like <code>System.Drawing.Bitmap</code> to write pixels directly into a bitmap and then save it into a .PNG file. Much easier than trying to find something to read the .PPM file that the original version emits.    </p>
<h3>Potential improvements</h3>
<p>One of the most obvious improvements that could be made is to make use of the parallelism support in F# and .NET. The algorithm itself is easily (if not embarrassingly) parallelisable, given that it iterates over the pixels in the output image, and performs independent operations on each of them. Unfortunately I haven&#8217;t had a chance to look at this yet &#8211; and the Windows VM I&#8217;m using only has a single processor anyway, so on a purely selfish note, I wouldn&#8217;t see any immediate performance improvements.  It should be as simple as changing the pixel loop to use <code>Parallel.For</code>, or creating an <code>async</code> computation expression.</p>
<p>Something else to note: I err&#8217;d on the side of caution when it comes to saving intermediate images, so every iteration it creates and writes the file. This will be doing lots of allocation and strictly unnecessary work, especially for simple scenes.</p>
<p>Given this approach is so completely compute bound it would be interesting to see how moving some of the calculations to a GPU would affect it. It might even be possible to use quotations for some of the inner loops and then generate Nvidia intermediate language (PTX) from them &#8211; that&#8217;s something I&#8217;ve been wanting to do for a while. </p>
<p>I did run the code through the Visual Studio 2010 profiler to get a rough idea of where the time was being spent; it looked like the majority was in the leaf of the calculations where numerical operations where being performed on the vectors, which is consistent with what we&#8217;d expect.</p>
<h3>Use the source</h3>
<p>So, here&#8217;s the source. No warranties implied, use at your own risk, your mileage may vary, all errors are mine etc, etc.<br />
<a href='http://www.voyce.com/wp-content/uploads/2010/06/minilight_fsharp.zip'>minilight_fsharp</a></p>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F06%2F30%2Fminilight-renderer-in-fsharp%2F&amp;t=Minilight+renderer+in+F%23&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>London Underground UI Fail</title>
		<link>http://www.voyce.com/index.php/2010/06/04/london-underground-ui-fail/</link>
		<comments>http://www.voyce.com/index.php/2010/06/04/london-underground-ui-fail/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 10:10:48 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Rant]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[London]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=879</guid>
		<description><![CDATA[You'd think replacing a magnetic board with a digital system would be a good thing, wouldn't you? Well, not if you get the "user interface" completely wrong...]]></description>
			<content:encoded><![CDATA[<p>I mentioned this on Twitter the other day, but I was so incensed I just had to scribble out a blog post too. It&#8217;s a classic case of replacing a traditional (in this case paper-based) &#8220;interface&#8221; with an electronic one, and in the process failing to translate the fundamental functionality that made the original system useful.</p>
<p>How can you screw-up creating an electronic version of an existing sign?<br />
<span id="more-879"></span></p>
<p>Here&#8217;s the offending item:<a href="http://www.voyce.com/wp-content/uploads/2010/06/lu_sign.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/lu_sign-224x300.png" alt="Underground line status" title="Underground line status" width="224" height="300" class="alignright size-medium wp-image-888" /></a><br />
It&#8217;s a replacement for a combination of magnetic labels and hand scrawled messages that convey the current state of each of the London underground lines. They&#8217;re generally one of &#8220;good service&#8221;, &#8220;minor delays&#8221;, &#8220;severe delays&#8221;, or &#8220;oh no, you&#8217;ll never get to work&#8221;. </p>
<p>For the majority of people, their only interaction with this system is walking past, early in the morning, when they&#8217;re not at their sharpest, and trying to figure out if their tube line is working. As such, if there was a magnetic label stuck on your line, you knew things weren&#8217;t good. Given the lines themselves are colour coded, it&#8217;s easy to determine which line you&#8217;re interested in. Bear in mind that people aren&#8217;t going to get closer than about 2 metres to the board. </p>
<p>And herein lies the problem: by replacing the analogue board with a digital version, it&#8217;s no longer possible to ascertain by the physical presence of a label or writing, what state the line is in. </p>
<p>Let me say that again. It&#8217;s virtually impossible to tell, even from relatively close, if there are delays. Take a look at that screenshot (dodgy quality as it is) and see if you can tell which line has &#8220;minor delays&#8221;. Yeah, not easy is it? Now try doing that as you&#8217;re briskly walking past at 7.46am.  </p>
<p><div id="attachment_890" class="wp-caption alignleft" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/06/lu_sign_detail.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/lu_sign_detail-300x119.png" alt="Underground line status (detail)" title="lu_sign_detail" width="300" height="119" class="size-medium wp-image-890" /></a><p class="wp-caption-text">Underground line status (detail)</p></div>It&#8217;s not helped by the fact that the state descriptions are all roughly the same length and form, &#8220;good service&#8221; could just as easily be &#8220;severe delays&#8221; when it&#8217;s in 36pt and seen from 2m away. There have been many studies on the legibility of type, most in the context of road signage, and of course, there are the seminal texts (e.g. <a href="http://www.amazon.com/gp/product/0881792063?ie=UTF8&#038;tag=wwwvoycecom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0881792063">The Elements of Typographic Style</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwvoycecom-20&#038;l=as2&#038;o=1&#038;a=0881792063" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />) on how typography can be applied for good, not evil. Shame no-one responsible for this application seems to have read them. </p>
<p>I&#8217;m surprised that they&#8217;ve relied solely on text and haven&#8217;t used any other means of distinguishing the significant information. Some other things that could&#8217;ve been used:</p>
<ul>
<li>Colour (of the text itself, the background, or some indicator. Need some inspiration? How about taking a look at something <em>way</em> out there, like, say, traffic lights)</li>
<li>Size</li>
<li>Weight (using font weight to indicate relative importance)</li>
<li>Icons (or some other kind of visual indicators, nothing flashy)</li>
</ul>
<p>I&#8217;m sure there are a whole load of advantages to having this digital system; most notably that it&#8217;s connected, and can be automatically and centrally updated. If only they&#8217;d spent any time on thinking about how people were actually going to use it!</p>
<p><a href="http://en.wikipedia.org/wiki/Harry_Beck">Harry Beck</a> would be turning in his grave.  </p>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F06%2F04%2Flondon-underground-ui-fail%2F&amp;t=London+Underground+UI+Fail&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/06/04/london-underground-ui-fail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>.NET 4.0 Type Equivalence causes BadImageFormatException</title>
		<link>http://www.voyce.com/index.php/2010/04/23/net-4-0-type-equivalence-causes-badimageformatexception/</link>
		<comments>http://www.voyce.com/index.php/2010/04/23/net-4-0-type-equivalence-causes-badimageformatexception/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 10:53:33 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[WinDbg]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.NET4]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[IL]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=840</guid>
		<description><![CDATA[Interop assemblies containing certain constructs will cause a BadImageFormatException in .NET 4.0]]></description>
			<content:encoded><![CDATA[<p>I recently discovered a nasty backward compatibility problem with the new type equivalence feature in .NET 4.0. Luckily it&#8217;s relatively difficult to hit it if you&#8217;re in a pure-C# environment, but if you happen to generate any assemblies directly using IL, you should watch out. Read on for all the gory details.<br />
<span id="more-840"></span></p>
<h2>What is .NET type equivalence?</h2>
<p>Described at a high level <a href="http://msdn.microsoft.com/en-us/library/dd997297.aspx">here</a>, .NET 4.0 type equivalence essentially gives you a way of indicating that different .NET types represent the same underlying COM type and is most commonly used in COM interop scenarios. One of the reasons for its introduction is to save developers from having to ship large interop DLLs with their software, e.g. the multi-megabyte Microsoft.Office.Interop. Instead the compiler can inline the definition of any types used, and mark them appropriately as representing the original COM types. </p>
<h2>The error</h2>
<p>We noticed that whenever we built and ran an application that referenced a DLL using .NET 2.0, it worked. Doing the same thing with .NET 4.0 caused a <a href="http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx">BadImageFormatException</a>.<br />
<code><br />
Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An attempt was made to load a program with an incorrect format.<br />
   at X.Main()<br />
</code> </p>
<h2>Let&#8217;s dig!</h2>
<p>So, the BadImageFormatException doesn&#8217;t actually tell us much. Let&#8217;s break out WinDbg and see what we can find. Running the faulting app we can see several C++ exceptions before the CLR exception is thrown:<br />
<code><br />
(178c.790): C++ EH exception - code e06d7363 (first chance)<br />
...<br />
(178c.790): C++ EH exception - code e06d7363 (first chance)<br />
(178c.790): CLR exception - code e0434352 (first chance)<br />
</code><br />
I changed the exception handling settings to stop on C++ exceptions (<code>sxe eh</code>) then ran again to see where things were going wrong. It stopped here:<br />
<code><br />
0:000> kp<br />
ChildEBP RetAddr<br />
0012d15c 79084c0f KERNEL32!RaiseException+0x53<br />
0012d194 793371be MSVCR100_CLR0400!_CxxThrowException+0x48<br />
0012d5e4 79455cae clr!EEFileLoadException::Throw+0x1a8<br />
0012d634 794558d2 clr!CompareTypeTokens+0x200<br />
0012d6b0 791b5c00 clr!IsTypeDefEquivalent+0x102<br />
0012d6d4 791b2ca8 <b>clr!MethodTableBuilder::CheckForTypeEquivalence</b>+0x94<br />
0012d7ac 791b27c9 clr!MethodTableBuilder::BuildMethodTableThrowing+0x60d<br />
0012d9a4 791a4578 clr!ClassLoader::CreateTypeHandleForTypeDefThrowing+0x88e<br />
</code><br />
Interesting. Notice how the call stack contains some .NET 4.0 specific methods relating to the new type equivalence feature. We&#8217;re hitting a new code path, which is consistent with the fact that running against a down-level CLR works.</p>
<p>After a bit more toing-and-froing, I discovered that the C++ exception is thrown when <code>clr!MDInternalRO::IsValidToken</code> returns an error. By disassembling the function we can see it&#8217;s just looking at various bits in the token value, and it decides that the value passed (0&#215;02000000) isn&#8217;t valid. Looking at the output from ildasm that token doesn&#8217;t appear anywhere. And if we add a dump of the value, we can see that it indeed doesn&#8217;t look like the other tokens: </p>
<pre>
0:000> bu clr!MDInternalRO::IsValidToken "dd esp+8 L1; g"
...
0012f5a8  02000001
0012f31c  06000001
0012f2c0  02000002
0012f0f4  02000002
0012ebe4  01000001
0012e944  23000001
...
0012d5f4  02000000
(18ec.1ec8): C++ EH exception - code e06d7363 (first chance)
</pre>
<h2>What&#8217;s the culprit?</h2>
<p>So it looks pretty conclusive; the DLL contains something that the CLR isn&#8217;t expecting. But what? It&#8217;s time to break out the oldest tool in the troubleshooting box: the binary chop!</p>
<p>Eventually I got the referenced DLL down to only a single simple construct. Can you guess what it is? A global literal value. A <em>real</em> global value, one that isn&#8217;t even part of a type. Crazy huh? In IL it looks like this:<br />
<code><br />
.field public static literal valuetype Test.MyEnum LiteralValue = int32(0x00000001)<br />
</code><br />
It&#8217;s a literal value of an enumerated type. That&#8217;s important: using a value of a simple type (say int32) does not provoke the error.</p>
<p>Now, I wasn&#8217;t even sure that this is a valid IL construct, but according to the ECMA IL spec, specifically <a href="http://jilc.sourceforge.net/ecma_p2_cil.shtml#_Toc524940530">partition II, section 15</a>, it is:</p>
<blockquote><p>The CLI also supports global fields, which are fields declared outside of any type definition. Global fields shall be static.</p></blockquote>
<p>So it looks like we&#8217;re not doing anything illegal, backed up by the fact that the .NET 2.0 CLR can make use of it without a problem.</p>
<p>Interestingly, there&#8217;s another aspect that influences whether this code path is hit. As mentioned above, type equivalence is intended for use with interop libraries. As such, it only kicks in if your referenced assembly is marked with the PrimaryInteropAssembly attribute, e.g.:</p>
<p><code><br />
  .custom instance void [mscorlib]System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute::.ctor(int32,int32) = ( 01 00 01 00 00 00 00 00 00 00 00 00 )<br />
</code></p>
<h2>The Fix?</h2>
<p>The issue is currently with Microsoft product support. Let&#8217;s see what they come up with; is it too esoteric for a hotfix&#8230;?</p>
<h2>The Repro</h2>
<p>Here&#8217;s some code and instructions on how to repro the problem.</p>
<ol>
<li>Build the IL into a DLL using ilasm.<br />
<code>"c:\WINNT\Microsoft.NET\Framework\v2.0.50727\ilasm.exe" /dll Test.il /output=Test.dll</code>
</li>
<li>Build the application into a .NET 4.0 EXE that references the DLL<br />
<code>"c:\winnt\Microsoft.NET\Framework\v4.0.30319\csc.exe" TestConsumer.cs /reference:Test.dll</code>
</li>
<li>Run the resulting <code>TestConsumer.exe</code> application and you&#8217;ll get the exception</li>
</ol>
<p><b>Test.il</b><br />
<code><br />
.assembly extern mscorlib<br />
{<br />
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )<br />
  .ver 2:0:0:0<br />
}<br />
.assembly Test<br />
{<br />
  .custom instance void [mscorlib]System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute::.ctor(int32,int32) = ( 01 00 01 00 00 00 00 00 00 00 00 00 )<br />
  .hash algorithm 0x00008004<br />
  .ver 1:0:0:0<br />
}<br />
.module Test.dll<br />
.imagebase 0x00400000<br />
.file alignment 0x00000200<br />
.stackreserve 0x00100000<br />
.subsystem 0x0003<br />
.corflags 0x00000001 </p>
<p>.field public static literal valuetype Test.MyEnum LiteralValue = int32(0x00000001)</p>
<p>.class public auto ansi sealed Test.MyEnum<br />
       extends [mscorlib]System.Enum<br />
{<br />
  .field public specialname rtspecialname int32 value__<br />
  .field public static literal valuetype Test.MyEnum Zero = int32(0x00000000)<br />
  .field public static literal valuetype Test.MyEnum One = int32(0x00000001)<br />
}<br />
</code><br />
<b>TestConsumer.cs</b></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> X
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        var v <span style="color: #008000;">=</span> Test.<span style="color: #0000FF;">MyEnum</span>.<span style="color: #0000FF;">Zero</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F04%2F23%2Fnet-4-0-type-equivalence-causes-badimageformatexception%2F&amp;t=.NET+4.0+Type+Equivalence+causes+BadImageFormatException&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/04/23/net-4-0-type-equivalence-causes-badimageformatexception/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating an iPad flip-clock with Core Animation</title>
		<link>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/</link>
		<comments>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 17:48:04 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=791</guid>
		<description><![CDATA[Using Core Animation to create flip-card number animations on the iPad and iPhone]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_one.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_one.png" alt="flipclock_one" title="flipclock_one" width="69" height="127" class="alignleft size-full wp-image-793" /></a>As part of the sliding puzzle game I&#8217;m developing for the iPhone and iPad (well, I can&#8217;t survive on the profits from <a href="http://voyce.com/BattleFingers/">BattleFingers</a> forever), I looked for a way to represent a numeric score and time display in an interesting way. One of the nicer visual effects you could use for this is the &#8220;flip-card clock&#8221; style, where each number consists of a top and bottom part, and the top part flips down to reveal the next number. It&#8217;s been used in a few other places including the home screen in the HTC Diamond device, and its physical, realistic style fits well with the iPad, so I set about creating a version for the iPhone and iPad using the built-in Core Animation library. Read on for more details.<br />
<span id="more-791"></span><br />
I started by thinking about the motions that would be required for the animation. We can break it down as three elements, the top, the bottom and the flipping part. Each of these parts can be represented as a Core Animation Layer (a <code>CALayer</code>). We create them using the class method on CALayer, there&#8217;s no additional <code>retain</code> here, as the <code>_toplayer</code> property is retained.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">_toplayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CALayer layer<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Splitting images</h2>
<p>Now we&#8217;ve got the layers, we need something to but into them. I didn&#8217;t want to create lots of pre-processed images for the top and bottom sections of each number, so instead I wrote a routine to split the images in code, drawing each half into an image context and grabbing a <code>UIImage</code> from it. This is then stored in an array for later use. We can get any of the elements from the array and set it as the <code>content</code> of the layer as required.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// The size of each part is half the height of the whole image</span>
CGSize size <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.width, <span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Create image-based graphics context for top half</span>
UIGraphicsBeginImageContext<span style="color: #002200;">&#40;</span>size<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Draw into context, bottom half is cropped off</span>
<span style="color: #002200;">&#91;</span>img drawAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>,<span style="color: #2400d9;">0.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// Grab the current contents of the context as a UIImage </span>
<span style="color: #11740a; font-style: italic;">// and add it to our array</span>
UIImage <span style="color: #002200;">*</span>top <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> retain<span style="color: #002200;">&#93;</span>;			
<span style="color: #002200;">&#91;</span>_imagesTop addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>top<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Now draw the image starting half way down, to get the bottom half</span>
<span style="color: #002200;">&#91;</span>img drawAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>,<span style="color: #002200;">-</span><span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// And store that image in the array too</span>
UIImage <span style="color: #002200;">*</span>bottom <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> retain<span style="color: #002200;">&#93;</span>;			
<span style="color: #002200;">&#91;</span>_imagesBottom addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>bottom<span style="color: #002200;">&#93;</span>;
&nbsp;
UIGraphicsEndImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>Now our <code>_imagesTop</code> and <code>_imagesBottom</code> arrays contains all the images we need, let&#8217;s get &#8216;em moving.</p>
<h2>Applying animation</h2>
<p><div id="attachment_808" class="wp-caption alignright" style="width: 212px"><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_axes1.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_axes1-202x300.png" alt="The axes and anchor point of a CALayer" title="flipclock_axes" width="202" height="300" class="size-medium wp-image-808" /></a><p class="wp-caption-text">The axes and anchor point of a CALayer</p></div>The animation we need to apply to the &#8216;flipping&#8217; part is a rotation around the bottom of the layer, at the join between the two halves. The default location of the anchor point is the middle of the layer, which would mean the piece would rotate around the middle, but we can easily change it to instead be at the middle in the bottom (for our purposes it could be anywhere on the bottom, as we&#8217;re only interested in x-axis rotation):</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">_fliplayer.anchorPoint <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.5</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>I use the <code>CATransform3DMakeRotation</code> function to create a transform around the X axis using the vector [1,0,0]. For the first part of the motion, we go from 0 radians to pi/2 radians (0 to 90 degrees), using an explicit <code>CABasicAnimation</code> object:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CABasicAnimation <span style="color: #002200;">*</span>topAnim <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CABasicAnimation animationWithKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;transform&quot;</span><span style="color: #002200;">&#93;</span>;
topAnim.duration<span style="color: #002200;">=</span><span style="color: #2400d9;">0.25</span>;
topAnim.repeatCount<span style="color: #002200;">=</span><span style="color: #2400d9;">1</span>;
topAnim.fromValue<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCATransform3D<span style="color: #002200;">:</span>CATransform3DMakeRotation<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">float</span> f <span style="color: #002200;">=</span> <span style="color: #002200;">-</span>M_PI<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>;
topAnim.toValue<span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCATransform3D<span style="color: #002200;">:</span>CATransform3DMakeRotation<span style="color: #002200;">&#40;</span>f, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
topAnim.delegate <span style="color: #002200;">=</span> self;
topAnim.removedOnCompletion <span style="color: #002200;">=</span> FALSE;
<span style="color: #002200;">&#91;</span>_fliplayer addAnimation<span style="color: #002200;">:</span>topAnim forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span>k_TopAnimKey<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Drawing layer content</h2>
<p>Unfortunately a CALayer doesn&#8217;t have a &#8220;back&#8221;, so creating the flip layer is not as easy as it could be. We need to add a step in the process to change the image displayed by the flip layer half way through its fall. We can do this in a variety of ways, I&#8217;ve chosen to set a delegate object to perform the drawing of the layer contents:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>_fliplayer setDelegate<span style="color: #002200;">:</span>_layerHelper<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This means our delegate object (<code>_layerHelper</code>) has its <code>drawLayer</code> method called whenever the layer needs to display its contents. Be wary though, this may not be as often as you think! Core graphics aggressively caches the contents of the layer, and will only call your delegate when absolutely necessary. You can force it to happen by calling <code>setNeedsDisplay</code>, which invalidates the contents of the layer:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>_fliplayer setNeedsDisplay<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>I encapsulated this in the helper object itself, by providing a custom implementation of the <code>isTop</code> property setter that calls <code>setNeedsDisplay</code>. At least that way callers don&#8217;t have to be aware of this requirement.</p>
<p>The <code>drawLayer</code> method itself simply draws one of two images into the context, depending on whether it&#8217;s in &#8216;top&#8217; mode. A slight further complication is that when drawing the bottom part, the image needs to be inverted to display upside down. This is achieved by applying a translation and scale to the context before drawing the image:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGContextSaveGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
CGContextTranslateCTM<span style="color: #002200;">&#40;</span>context, 0.0f, r.size.height<span style="color: #002200;">&#41;</span>;
CGContextScaleCTM<span style="color: #002200;">&#40;</span>context, 1.0f, <span style="color: #002200;">-</span>1.0f<span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextDrawImage<span style="color: #002200;">&#40;</span>context, r, <span style="color: #002200;">&#91;</span>_imgTop CGImage<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextRestoreGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;</pre></div></div>

<h2>Avoiding implicit animation</h2>
<p>I&#8217;ve tried to avoid using implicit animation here, instead using explicit construction of <code>CABasicAnimation</code> objects, because we need some control of when things happen, and the order in which they happen. Normally, it would be easier to just set some property of the view and let the OS manage animating it. Many properties have default transition that are applied whenever they&#8217;re changed, so it takes some additional effort to make them change immediately.</p>
<p>In our example we change the contents of the top half and show the flip layer, but we need that to happen immediately so we disable actions within an explicit transaction that we then commit. This gives us the control we need, and avoids the default behaviour of the transition occurring when the message loop next runs.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>CATransaction begin<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>CATransaction setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kCFBooleanTrue
				forKey<span style="color: #002200;">:</span>kCATransactionDisableActions<span style="color: #002200;">&#93;</span>;
_toplayer.contents <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>_imagesTop objectAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self getNextIndex<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> CGImage<span style="color: #002200;">&#93;</span>;
_fliplayer.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#91;</span>CATransaction commit<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Getting some perspective</h2>
<p>Although the images I&#8217;ve used to illustrate this post are isometric, what we really want is a front-on perspective view, so that the falling piece seems to stick out. For this we have to set a <code>sublayerTransform</code> on the view&#8217;s inherent layer, by setting an individual element on a transform:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CATransform3D aTransform <span style="color: #002200;">=</span> CATransform3DIdentity;
<span style="color: #a61390;">float</span> zDistance <span style="color: #002200;">=</span> <span style="color: #2400d9;">1000</span>;
aTransform.m34 <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.0</span> <span style="color: #002200;">/</span> <span style="color: #002200;">-</span>zDistance;	
<span style="color: #002200;">&#91;</span>self layer<span style="color: #002200;">&#93;</span>.sublayerTransform <span style="color: #002200;">=</span> aTransform;</pre></div></div>

<p>This gives us a much more realistic look.</p>
<h2>Putting it together</h2>
<p>Wow, so now we&#8217;ve got some appropriately sliced images, some layers and some animations. Let&#8217;s put them together to get the final effect.<br />
<div id="attachment_812" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock-300x96.png" alt="The animation states (last is same as first)" title="flipclock" width="300" height="96" class="size-medium wp-image-812" /></a><p class="wp-caption-text">The animation states (last is same as first)</p></div><br />
I&#8217;ve used a very simple state machine that moves through 3 states; TopToMiddle, MiddleToBottom, ResetForNext. We can use the <code>animationDidStop</code> delegate as the state transition point. We don&#8217;t have to bother determining exactly which animation finished, because we do the same thing (change state) regardless.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>animationDidStop<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CAAnimation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>oldAnimation finished<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>flag
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self changeState<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<ul>
<li><strong>TopToMiddle</strong>: show flip layer, and start rotation through 90 degrees</li>
<li><strong>MiddleToBottom</strong>: change image on flip layer, start rotation through further 90 degrees</li>
<li><strong>ResetForNext</strong>: change displayed top and bottom layer contents and hide flip layer</li>
</ul>
<p>Let&#8217;s see how it looks in action:<br />
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/RbPmAl_AeSU&#038;hl=en_US&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RbPmAl_AeSU&#038;hl=en_US&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F04%2F10%2Fcreating-an-ipad-flip-clock-with-core-animation%2F&amp;t=Creating+an+iPad+flip-clock+with+Core+Animation&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Calling MSBuild tasks with F#</title>
		<link>http://www.voyce.com/index.php/2010/03/31/calling-msbuild-tasks-with-fsharp/</link>
		<comments>http://www.voyce.com/index.php/2010/03/31/calling-msbuild-tasks-with-fsharp/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 17:31:15 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[msbuild]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=774</guid>
		<description><![CDATA[It's easy to call MSBuild tasks directly from F#. Although possibly unnecessary.]]></description>
			<content:encoded><![CDATA[<p>The other day I was trying to understand some strange behaviour in msbuild with regard to how it resolves referenced assemblies. I thought I&#8217;d try directly invoking the tasks that are used during the build, specifically <a href="http://msdn.microsoft.com/en-us/library/9ad3f294.aspx">ResolveAssemblyReference</a>, so that I could experiment with them in F# interactive. It turned out to be pretty straightforward.<br />
<span id="more-774"></span><br />
In this example I&#8217;m attempting to resolve a reference to &#8220;class1.dll&#8221; from the GAC, taking into account the contents of the app.config (which can be used change the version resolution in MSBuild):</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #066; font-weight: bold;">#I @&quot;C:\winnt\Microsoft.NET\Framework\v2.0.50727\&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Tasks.dll&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Utilities.dll&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Framework.dll&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Engine.dll&quot;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">open</span> System
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Build</span><span style="color: #000080;">.</span><span style="color: #505090;">Framework</span>
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Build</span><span style="color: #000080;">.</span><span style="color: #505090;">Utilities</span>
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Build</span><span style="color: #000080;">.</span><span style="color: #505090;">Tasks</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: #06c; font-weight: bold;">let</span> t <span style="color: #000080;">=</span> 
        ResolveAssemblyReference<span style="color: #000080;">&#40;</span>Silent <span style="color: #000080;">=</span> <span style="color: #06c; font-weight: bold;">true</span>,
            Assemblies <span style="color: #000080;">=</span> <span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span> <span style="color: #06c; font-weight: bold;">upcast</span> TaskItem<span style="color: #000080;">&#40;</span> ItemSpec<span style="color: #000080;">=</span><span style="color: #008080;">&quot;class1&quot;</span> <span style="color: #000080;">&#41;</span> <span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span>,
            AllowedAssemblyExtensions <span style="color: #000080;">=</span> <span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span><span style="color: #008080;">&quot;.dll&quot;</span><span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span>,
            AppConfigFile <span style="color: #000080;">=</span> <span style="color: #008080;">&quot;c:<span style="color: #008080; font-weight: bold;">\\</span>dev<span style="color: #008080; font-weight: bold;">\\</span>myapp<span style="color: #008080; font-weight: bold;">\\</span>myapp.exe.config&quot;</span>,
            SearchPaths <span style="color: #000080;">=</span> <span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span><span style="color: #008080;">&quot;{GAC}&quot;</span><span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span>
            <span style="color: #000080;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">match</span> t<span style="color: #000080;">.</span><span style="color: #505090;">Execute</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #06c; font-weight: bold;">with</span>
    <span style="color: #000080;">|</span> <span style="color: #06c; font-weight: bold;">true</span>  <span style="color: #000080;">-&gt;</span> printf <span style="color: #008080;">&quot;%A<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span> t<span style="color: #000080;">.</span><span style="color: #505090;">ResolvedFiles</span>
    <span style="color: #000080;">|</span> <span style="color: #06c; font-weight: bold;">false</span> <span style="color: #000080;">-&gt;</span> printf <span style="color: #008080;">&quot;Task failed&quot;</span></pre></div></div>

<p>The output is:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span>C<span style="color: #000080;">:</span>\WINNT\assembly\GAC_MSIL\class1\1<span style="color: #000080;">.</span>1<span style="color: #000080;">.</span>8<span style="color: #000080;">.</span>0__120bce90f68b861a\class1<span style="color: #000080;">.</span><span style="color: #505090;">dll</span><span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span></pre></div></div>

<p>The code makes good use of F#&#8217;s named constructor arguments, which map to property setters on the object we&#8217;ve just created. We can also create the arrays of <a href="http://msdn.microsoft.com/en-us/library/microsoft.build.utilities.taskitem.aspx">TaskItem</a>s and strings fairly easily, although an explicit upcast is required in order to obtain the ITaskItem (F# doesn&#8217;t upcast implicitly like many object oriented languages).</p>
<p>I&#8217;ve just discovered that Jomo Fisher wrote about <a href="http://blogs.msdn.com/jomo_fisher/archive/2008/05/22/programmatically-resolve-assembly-name-to-full-path-the-same-way-msbuild-does.aspx">exactly the same thing</a> back in May 2008! He mentions using an object expression in order to provide an implementation of <code>IBuildEngine</code>, which I&#8217;m getting away with by setting the <code>Silent</code> property on the <code>ResolveAssemblyReference</code> task, meaning that it never attempts to obtain the logging context from the build engine.</p>
<p>Another gotcha here is the fact that versions of various interfaces including <code>IBuildEngine</code> and <code>ITaskItem</code> exist in both the 2.0.0.0 and 3.5.0.0 versions of the <code>Microsoft.Build.Framework</code> assembly. Be careful that you reference the correct version for the task that you&#8217;re calling. Normally it will be the 2.0 versions, in which case you&#8217;ll need to use explicit file references in your script, adding the directory to the library include path:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #066; font-weight: bold;">#I @&quot;C:\winnt\Microsoft.NET\Framework\v2.0.50727\&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Framework.dll&quot;</span></pre></div></div>

<p>Rather than partially qualified assembly references:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Framework&quot;</span></pre></div></div>

<p>As the latter will resolve to the latest installed version of the assembly, 3.5, which is not what you want. Look out for errors like:</p>
<blockquote><p>
System.InvalidCastException: Unable to cast object of type &#8216;Microsoft.Build.Utilities.TaskItem&#8217; to type &#8216;Microsoft.Build.Framework.ITaskItem&#8217;.
</p></blockquote>
<h2>Alternatives</h2>
<p><div id="attachment_777" class="wp-caption alignleft" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/03/msbuild_verbosity.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/msbuild_verbosity-300x174.png" alt="The Tools|Options MSBuild verbosity setting" title="msbuild_verbosity" width="300" height="174" class="size-medium wp-image-777" /></a><p class="wp-caption-text">The Tools|Options MSBuild verbosity setting</p></div>Although this was a useful experiment, I discovered that it&#8217;s often much easier to just increase the MSBuild verbosity and wade through the reams of output to find what you&#8217;re after (but then <a href="http://en.wiktionary.org/wiki/yak_shaving">the Yak will remain hairy</a>). There&#8217;s an option in Tools|Options|Projects and Solutions|Build and Run to change the output level from Silent to Diagnostic. Beware: you can easily get megabytes of text output from diagnostic mode!</p>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F03%2F31%2Fcalling-msbuild-tasks-with-fsharp%2F&amp;t=Calling+MSBuild+tasks+with+F%23&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/03/31/calling-msbuild-tasks-with-fsharp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Modifying the VC runtime to get better heap allocation stack traces</title>
		<link>http://www.voyce.com/index.php/2010/03/17/modifying-the-vc-runtime-to-get-better-heap-allocation-stack-traces/</link>
		<comments>http://www.voyce.com/index.php/2010/03/17/modifying-the-vc-runtime-to-get-better-heap-allocation-stack-traces/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 23:24:30 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WinDbg]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[heap]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=754</guid>
		<description><![CDATA[Heap allocation stack traces are useless when using certain versions of the MSVC runtime. Is it possible to modify and rebuild MSVCR80 to avoid this?]]></description>
			<content:encoded><![CDATA[<p>Today I was trying to track down some &#8211; how can I put this politely &#8211; &#8220;unusual&#8221; memory usage in some unmanaged code running inside Excel. I broke out WinDbg and tried the usual suspects to get an idea of how memory was being used. Unfortunately, the way that msvcr80.dll is built stopped me from getting decent stack traces for the allocations, so I decided to try and rebuild it with a fix to remedy the situation.<br />
<span id="more-754"></span></p>
<h2>Collecting stack traces</h2>
<p>One of the most helpful things the heap manager can do for you when investigating memory issues is to capture stack traces for each heap allocation. You can enable the &#8220;collect stack traces&#8221; heap flag using the gflags GUI or from within WinDbg:</p>
<pre>
0:006> !gflag +ust
Current NtGlobalFlag contents: 0x00001040
    hpc - Enable heap parameter checking
    ust - Create user mode stack trace database
</pre>
<p>This means that for each heap block (one located at <code>0x0bbf7308</code> in this case), you can see where it was allocated by using the -a (show all information) option:</p>
<pre>
0:006> !heap -p -a 0bbf7308
    address 0bbf7308 found in
    _HEAP @ a630000
      HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
        0bbf7308 0073 0000  [07]   0bbf7310    00380 - (busy)
        Trace: 401c
        7c96d6dc ntdll!RtlDebugAllocateHeap+0x000000e1
        7c949d18 ntdll!RtlAllocateHeapSlowly+0x00000044
        7c91b298 ntdll!RtlAllocateHeap+0x00000e64
        78134333 MSVCR80!malloc+0x00000077
</pre>
<p>But the obvious problem with this is that the stack trace always stops at malloc. Something&#8217;s allocating some memory? You don&#8217;t say&#8230; </p>
<p>It turns out that this is a <a href="http://http://www.nynaeve.net/?p=209">well understood</a> and documented issue with the Microsoft VC++ runtime, variously known as msvcrt, msvcr70, msvcr71, msvcr80, msvcr90, etc. Unfortunately they&#8217;re all built using the stack frame pointer omission optimisation. Well they&#8217;re built with the <a href="http://msdn.microsoft.com/en-us/library/8f8h5cxt.aspx">-O1</a> (favour small code) option, which implies <a href="http://msdn.microsoft.com/en-us/library/2kxx5t2c.aspx">-Oy</a>. This means that the fast stack-walking algorithm the heap manager uses stops at functions without a return address. The only way to get a decent trace in this situation would be to use the DbgHelp API along with the .pdb files, which would be far too slow to do at each allocation site.</p>
<h2>&#8220;Fixing&#8221; it</h2>
<p>So, given that the source for the runtime library ships as part of Visual Studio, maybe it would be possible to build it without the -Oy option?</p>
<p>My first attempt at building it failed miserably with errors like:<br />
<code><br />
NMAKE : fatal error U1073: don't know how to make 'build\intel\mt_obj\startup.lib'<br />
</code><br />
Luckily this <a href="http://blogs.msdn.com/michkap/articles/478235.aspx">excellent page</a> helped me get past this to a point where I could actually get a DLL built.</p>
<p>The next stage was to modify the build scripts to use different compiler switches. This was simply a case of changing line 69 of <code>makefile.sub</code> from:<br />
<code>CFLAGS=$(CFLAGS) -O1</code><br />
to:<br />
<code>CFLAGS=$(CFLAGS) -O1 <b>-Oy-</b></code></p>
<p>I thought I may have to also modify the build scripts to output a version of the DLL with the same name as the file I was replacing, msvcr80.dll, directly, in case there were internal references to the name in embedded manifests. There&#8217;s a section at the top of the build script for choosing a name for your private version of the library, but it strongly discourages use of the &#8220;reserved&#8221; MSVC* names. Luckily it turns out not to be necessary; the DLL is constructed in such a way as to be rename-able without any ill effects. I could build _sample_.dll (the default output name) and simply copy it to the destination directory in the SxS tree (<code>C:\WINNT\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.3053_x-ww_b80fa8ca</code>) and rename it.</p>
<h2>Result</h2>
<p>Now I get the expected full stack trace (names have been changed to protect the innocent):</p>
<pre>
0:006> !heap -p -a 0bbf7308
    address 0bbf7308 found in
    _HEAP @ a630000
      HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state
        0bbf7308 0073 0000  [07]   0bbf7310    00380 - (busy)
        Trace: 401c
        7c96d6dc ntdll!RtlDebugAllocateHeap+0x000000e1
        7c949d18 ntdll!RtlAllocateHeapSlowly+0x00000044
        7c91b298 ntdll!RtlAllocateHeap+0x00000e64
        78134333 MSVCR80!malloc+0x00000077
        7816207f MSVCR80!operator new+0x0000001d
        fa92336 leakydll!std::allocator<std::vector<ATL::CAdapt<ATL::CComBSTR>,std::allocator<ATL::CAdapt<ATL::CComBSTR> > > >::allocate+0x00000016
        fa9879b leakydll!std::vector<CComVariant,std::allocator<CComVariant> >::resize+0x0000005b
        ...
        ...etc...
</pre>
<p>That&#8217;ll make it <i>much</i> easier to work out what&#8217;s happening and who&#8217;s responsible. Of course, you should be careful with this modified version. Only use it on development machines, and make sure it doesn&#8217;t escape into the wild: with great power comes great responsibility.</p>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F03%2F17%2Fmodifying-the-vc-runtime-to-get-better-heap-allocation-stack-traces%2F&amp;t=Modifying+the+VC+runtime+to+get+better+heap+allocation+stack+traces&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/03/17/modifying-the-vc-runtime-to-get-better-heap-allocation-stack-traces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPad &#8211; The rise of the naturalistic user interface</title>
		<link>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/</link>
		<comments>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 01:05:53 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=679</guid>
		<description><![CDATA[Apple's iPad applications make use of real-world objects in their user interfaces: books, newspapers, address books. What is it about the iPad that makes it a good platform for this kind of UI?]]></description>
			<content:encoded><![CDATA[<p>It was fascinating to see Apple unveiling its new iPad hardware recently, and one of the things that caught my eye were the interfaces of the various apps that were demonstrated. They look different from apps on other platforms, and even from the equivalent apps on the iPhone. It seems to me as if there&#8217;s been a change to a more naturalistic style of user interfaces. Why is this, and what is it about the iPad that makes it suited to this kind of UI?<br />
<span id="more-679"></span></p>
<h2>Form factor</h2>
<p>The most obvious reason that this kind of interface works on the iPad is the form factor of the device itself. Think about it: an iPhone is a small (well, smallish) object which has no physical, real-world equivalent. It&#8217;s not supposed to &#8220;be&#8221; anything other than a phone. The iPad, on the other hand, is intended to mimic an actual object, or rather, a variety of objects: a book, a newspaper or an address book for example. The interface for each of these uses reflects this directly: the address book looks like a &#8220;little black book&#8221;, complete with tabs. </p>
<p>The iPhone uses some of the same metaphors &#8211; like the address book for contacts &#8211; but the representation is abstract, whereas the iPad UI is literal, using an actual image of a book. The abstraction is necessary on the iPhone in order for it to remain usable with a smaller screen. Compare the iPad and iPhone Contacts interfaces:</p>
<table>
<tr>
<td><div id="attachment_682" class="wp-caption alignnone" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/02/contacts_ipad_fullpage_small.png"><img src="http://www.voyce.com/wp-content/uploads/2010/02/contacts_ipad_fullpage_small-300x230.png" alt="The realistic looking address book application on the iPad" title="contacts_ipad_fullpage_small" width="300" height="230" class="size-medium wp-image-682" /></a><p class="wp-caption-text">The realistic looking address book application on the iPad</p></div>
</td>
<td><div id="attachment_684" class="wp-caption alignnone" style="width: 130px"><a href="http://www.voyce.com/wp-content/uploads/2010/02/contacts_iphone_small.png"><img src="http://www.voyce.com/wp-content/uploads/2010/02/contacts_iphone_small-156x300.png" alt="iPhone contacts interface" title="contacts_iphone_small" width="120" height="230" class="size-medium wp-image-684" /></a><p class="wp-caption-text">iPhone contacts interface</p></div></td>
</tr>
</table>
<p>The abstract to realistic continuum has been explored extensively in the world of icons (explained brilliantly <a href="http://ignorethecode.net/blog/2010/01/21/realism_in_ui_design/">here</a>), but less so in the interface as a whole. Obviously some apps don&#8217;t have any form of real world equivalent (think System Preferences.app), so they&#8217;re likely to stay in a more abstract form. </p>
<h2>Display fidelity</h2>
<p>Of course, it&#8217;s always been possible to <i>represent</i> real objects on the screen, but without a display capable of a decent resolution it probably won&#8217;t look real. So another enabler for naturalistic UI is display technology: the more pixels and colour depth the better when it comes to rendering physical things. Realism often relies on subtle lighting and rich textures to achieve the desired effect. Anyone who&#8217;s ever attempted to render wood grain using 8-bit colour will appreciate how much easier it is with a 32-bit 1024&#215;768 display. </p>
<p>The need for display quality goes hand-in-hand with a need for more processing power to push the pixels. If the processing &#8220;oomph&#8221; required to render your interface with sufficient quality means that it&#8217;s not responsive enough, then you&#8217;ve failed by any measure. The iPad seems to have reached a sweet spot where display capabilities, raw power and form-factor meet to make naturalistic UIs a feasible approach.   </p>
<h2>Direct manipulation</h2>
<p><a href="http://www.voyce.com/wp-content/uploads/2010/03/Apple_Mouse_no.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/Apple_Mouse_no.png" alt="Apple_Mouse_no" title="Apple_Mouse_no" width="160" height="160" class="alignleft size-full wp-image-722" /></a>Up until the relatively recent introduction of direct manipulation technologies like touch-senstive displays, there&#8217;s a been a forced physical separation between users and their computer in the form of a mouse and keyboard. A drag operation using a mouse involves disconnected, abstract operations like pointing and clicking, which bear no relation to the object being acted upon. As such, there&#8217;s little use in having an extremely realistic representation of something to interact with, because the suspension-of-disbelief has already been broken. </p>
<p>But in the world of touch-based devices, our interactions are much closer to the physical actions we&#8217;d make, so having a closer visual representation to go along with it is beneficial. For instance, turning a page in an eBook and actually seeing the page flick over seems consistent when using a natural gesture like flicking a finger across the screen. Otherwise if you had to click a corner of the page and drag it across in a poor imitation of the physical action the visual aspects can quickly start to feel superfluous.   </p>
<p>Perhaps given the iPad&#8217;s larger interaction surface we can expect to see a wider and more expressive range of gestures supported?  </p>
<h2>History</h2>
<p>Of course, naturalistic UI isn&#8217;t really a new thing. It&#8217;s in use in quite a few applications already, albeit mostly in desktop apps, where capable hardware is more readily available. In fact, there was much a-twittering (not <i>all</i> of it from Will Shipley) about the similarity between the demo&#8217;d iPad apps and the interface of the fantastic Mac application <a href="http://delicious-monster.com/">Delicious Library</a>. I&#8217;m sure of course &#8211; how do they say it in the movie credits &#8211; the similarity is entirely coincidental&#8230;</p>
<table>
<tr>
<td valign="top"><div id="attachment_733" class="wp-caption alignnone" style="width: 303px"><img src="http://www.voyce.com/wp-content/uploads/2010/03/delicious_library_shrunk.png" alt="Delicious Library UI" title="delicious_library_shrunk" width="293" height="196" class="size-full wp-image-733" /><p class="wp-caption-text">Delicious Library UI</p></div></td>
<td><div id="attachment_734" class="wp-caption alignnone" style="width: 160px"><img src="http://www.voyce.com/wp-content/uploads/2010/03/ibooks_shrunk.png" alt="iBooks UI" title="ibooks_shrunk" width="150" height="199" class="size-full wp-image-734" /><p class="wp-caption-text">iBooks UI</p></div></td>
</tr>
</table>
<p><a href="http://www.voyce.com/wp-content/uploads/2010/03/rebirth_knobs_crop.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/rebirth_knobs_crop.png" alt="rebirth_knobs_crop" title="rebirth_knobs_crop" width="250" height="110" class="alignleft size-full wp-image-717" /></a>One of the first widespread uses of naturalistic UI elements was in software synths. Guys like <a href="http://www.propellerheads.se/">Propellerheads</a> and <a href="http://www.native-instruments.com/">Native Instruments</a> set about creating exact software duplicates of well-known and well-loved bits of <a href="http://en.wikipedia.org/wiki/Roland_TB-303">mid-80&#8217;s audio hardware</a>. The UIs included virtual versions of a huge number of physical elements that had never been used before: including things like sliders, LEDs, toggle buttons, rotary knobs and rocker switches. These interface elements were probably first seen in software-based mixing desks, but the techniques used to make them feel real have gone on to be used in many different ways. Even the lowly push button in both Windows and MacOS got an upgrade by application of some of the 3D effects that they originated. </p>
<h2>Where Now?</h2>
<p>It will be interesting to see what other types of app are given the iPad realism makeover. It certainly looks like all of the standard Apple apps are being changed, including Notes, iCal, iBooks and Contacts, which were shown in the launch presentation, but how will 3rd-party developers manage? It undoubtedly takes extra effort to make something look convincing when it can be compared to the physical object itself. </p>
<p>Apple has previously managed to get a good level of consistency in its abstract UIs by providing the various interface elements ready-made, but will that approach scale to this kind of UI? No doubt the developers who take great pride in the interfaces now will continue to strive to create apps that sit comfortably alongside Apple&#8217;s own, but perhaps there&#8217;ll just be a more obvious visual distinction between those guys and the less polished application user interfaces than there has been in the past.</p>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F03%2F11%2Fipad-the-rise-of-the-naturalistic-user-interface%2F&amp;t=iPad+-+The+rise+of+the+naturalistic+user+interface&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/feed/</wfw:commentRss>
		<slash:comments>3</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>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F03%2F05%2Ftoo-busy-to-blog%2F&amp;t=Too+busy+to+blog...%21%3F&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></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>Where&#8217;s my window?</title>
		<link>http://www.voyce.com/index.php/2010/01/31/wheres-my-window/</link>
		<comments>http://www.voyce.com/index.php/2010/01/31/wheres-my-window/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 20:06:30 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[hidden]]></category>
		<category><![CDATA[invisible]]></category>
		<category><![CDATA[missing]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=667</guid>
		<description><![CDATA[Where's my window gone? I'm sure I left it around here somewhere...]]></description>
			<content:encoded><![CDATA[<p>On Windows, if you regularly change screen resolution or size, perhaps by accessing a machine remotely, you might find some of your application windows are no longer visible; they&#8217;re positioned outside of the visible display area. If you can&#8217;t see the window, it can be a <i>little</i> difficult to use the application. How can you get that window back?<br />
<span id="more-667"></span><br />
In most cases &#8211; but only only on pre-Vista versions of Windows &#8211; it can be easily resolved by right clicking on the task bar icon for the application, selecting Move and then using the cursor keys. This makes the cursor &#8220;stick&#8221; to the caption of the window, and you can move the mouse (without clicking!) to bring it onto the screen. Clicking releases the window.</p>
<p>You can do it without the mouse, too. Just make sure the window is selected in the task bar (perhaps by using the Windows key and then tabbing to the appropraite icon), then hit Alt-Space, Alt-M, and then using the cursor keys.</p>
<p>The only problem is, some application developers choose to change the system menu &#8211; the menu visible from clicking the app&#8217;s icon in the top left, or by right-clicking the task bar icon &#8211; perhaps deciding for some insane reason not to include the standard Move option (as an aside, this breaks one of the fundamental tenets of usability: don&#8217;t change &#8211; or in this case, remove &#8211; existing, established behaviour). If this is the case, you can instead use a handful of lines of Windows API code to access the window and move it programatically. Here&#8217;s the entire code of a program that will do exactly that:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;windows.h&gt;</span>
<span style="color: #339900;">#include &lt;tchar.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> _tmain<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, TCHAR <span style="color: #000040;">*</span>argv<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>argc <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		_tprintf<span style="color: #008000;">&#40;</span>_T<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;usage: mover windowtitle<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	HWND hwnd <span style="color: #000080;">=</span> FindWindow<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, argv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>hwnd<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		SetWindowPos<span style="color: #008000;">&#40;</span>hwnd, HWND_TOP, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">400</span>,<span style="color: #0000dd;">400</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">else</span>
		_tprintf<span style="color: #008000;">&#40;</span>_T<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Unable to find window %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span>, argv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Compile it up and you can use it as a handy little utility to move arbitrary top level windows, e.g. if you&#8217;ve got regedit running:<br />
<code><br />
mover "Registry Editor"<br />
</code><br />
The only tricky thing is finding the exact title of the window to use. Well, you wouldn&#8217;t want it to be <i>too</i> easy, would you?</p>
<div><table border=0 bgcolor=#ffffff> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http%3A%2F%2Fwww.voyce.com%2Findex.php%2F2010%2F01%2F31%2Fwheres-my-window%2F&amp;t=Where%27s+my+window%3F&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><!-- Generated by Digg Digg plugin, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/
	-->]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/01/31/wheres-my-window/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
