<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Wyatt Says...</title>
	
	<link>http://wyday.com/blog</link>
	<description>Articles on open source C# controls and the wyUpdate updater program.</description>
	<lastBuildDate>Sat, 03 Jul 2010 07:18:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/wyday/wyattsblog" /><feedburner:info uri="wyday/wyattsblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>wyday/wyattsblog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>How to detect .NET 2.0 vs. .NET 4.0 assemblies, and x86 vs. x64 vs. AnyCPU</title>
		<link>http://feedproxy.google.com/~r/wyday/wyattsblog/~3/csgL2j5qdys/</link>
		<comments>http://wyday.com/blog/2010/how-to-detect-net-assemblies-x86-x64-anycpu/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 02:09:31 +0000</pubDate>
		<dc:creator>Wyatt O'Day</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[wyBuild]]></category>
		<category><![CDATA[wyUpdate]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://wyday.com/blog/?p=145</guid>
		<description><![CDATA[How to detect .NET assemblies, their target platform (x86, x64, etc.), and other details.]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://img.wyday.com/blog/images/2010/how-to-detect-net-assemblies/net_logo.png" title=".NET Framework" class="alignright" width="150" height="143" />In today’s article I’m going to talk about an interesting problem: detecting .NET assemblies. More than that, I’ll be talking about detecting some features of .NET assemblies and how you can expand and mold our code for your own uses. The code’s at the bottom of the article, it’s written in C# and licensed under the BSD license. Go get it.</p>
<p>I’ve seen this question pop up in a few different forms:</p>
<ul>
<li>How do I detect .NET assemblies?</li>
<li>How can I detect the difference between .NET 2.0 and .NET 4.0 assemblies?</li>
<li>How can I detect the difference between x86, x64, and AnyCPU .NET assemblies?</li>
</ul>
<p>And the list goes on and on. But this raises the question…</p>
<h2>Why detect .NET assemblies?</h2>
<p>We detect .NET assemblies because we respect humans’ time. Let me explain.</p>
<p>When <a href="http://wyday.com/wyupdate/">wyUpdate (our open source updater)</a> installs updates it can do a few things beyond simple patching, registry changing, and file copying. Namely it can:</p>
<ul>
<li>NGEN assemblies</li>
<li>Install &#038; update COM assemblies using RegAsm</li>
<li>Install &#038; update assemblies in the GAC (Global Assembly Cache).</li>
</ul>
<p>Which means wyUpdate needs to know whether the executable (or dll) is a .NET assembly, whether it’s strong signed, and what platform target it is (i.e. x86, x64, or Any CPU).</p>
<p>We could ask the user for every file, but that’s such a hassle. Who wants to waste time checking boxes for every exe and dll in their project? Rather than wasting the users’ time we quickly scan the .dll and .exe files for their details when the update is built inside <a href="http://wyday.com/wybuild/">wyBuild</a>.</p>
<h2>How not to do .NET detection</h2>
<p>Do not use LoadLibrary(), or Assembly.Load() functions to load an assembly in memory to then parse it. This breaks when you have an x86 process trying to a load an x64 assembly (or vice versa).</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2010/how-to-detect-net-assemblies/target.png" title="Platform target" class="aligncenter" width="349" height="102" /></p>
<h2>How to detect .NET</h2>
<p>Instead of using LoadLibrary (or one of its brethren) we’ll just treat the executables as dumb files. That is, just run a simple loop over the file and skip over the unneeded parts. You can check out the C# code posted at the bottom of this article, but you should be aware of 2 resources we used when designing the .NET detection algorithm:</p>
<ul>
<li>CLI Partition II: Metadata Definition and Semantics (<a href="http://download.microsoft.com/download/7/3/3/733AD403-90B2-4064-A81E-01035A7FE13C/MS%20Partition%20II.pdf">get the PDF</a>) from the <a href="http://msdn.microsoft.com/en-us/netframework/aa569283.aspx">ECMA C# and Common Language Infrastructure Standards</a></li>
<li><a href="http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx">Portable Executable and Common Object File Format Specification</a> (i.e. the PECOFF Spec)</li>
</ul>
<p>The PECOFF spec gives you the general layout of .exe and .dll files, and the CLI Partition II gives .NET specific features that we detect. Namely, is the assembly strong signed, is it built for Any CPU or x86 alone, and what base version of the .NET framework is it built for (2.0 or 4.0).</p>
<p>Also, when you check out the code, notice how the code handles PE32 files versus how it handles PE32+ files. That is to say, 32-bit assemblies have a subtly different layout than 64-bit assemblies.</p>
<h2>Tell me if you find this useful – how are you using it?</h2>
<p>If you find this code useful, tell me how you’re using it in the comments.</p>
<h2>Get the C# source</h2>
<p><a href="http://wyupdate.googlecode.com/files/AssemblyParser-v2.zip">Download the AssemblyDetails C# source</a>. It works with .NET 2.0, 3.0, 3.5, 4.0.</p>
<p><strong>Example usage:</strong></p>
<pre>
AssemblyDetails ad = AssemblyDetails.FromFile(filename);

// ad == null for non .NET assemblies
if (ad != null)
    Console.WriteLine(Path.GetFileName(filename) + ": " + ad.CPUVersion + ", " + ad.FrameworkVersion);
else
    Console.WriteLine(Path.GetFileName(filename) + ": Not a .NET 2.0+ executable.");
</pre>
<p><strong>Update 7/3/2010: </strong> There was a slight bug in the first version. Re-download the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://wyday.com/blog/2010/how-to-detect-net-assemblies-x86-x64-anycpu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://wyday.com/blog/2010/how-to-detect-net-assemblies-x86-x64-anycpu/</feedburner:origLink></item>
		<item>
		<title>Multi-process C# app like Google Chrome</title>
		<link>http://feedproxy.google.com/~r/wyday/wyattsblog/~3/l44ojxh9zzM/</link>
		<comments>http://wyday.com/blog/2010/multi-process-c-sharp-application-like-google-chrome-using-named-pipes/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 01:16:34 +0000</pubDate>
		<dc:creator>Wyatt O'Day</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[wyBuild]]></category>
		<category><![CDATA[wyUpdate]]></category>
		<category><![CDATA[AutomaticUpdater]]></category>
		<category><![CDATA[google chrome]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://wyday.com/blog/?p=140</guid>
		<description><![CDATA[How to communicate between multiple processes in C# using named pipes. Included source code &#038; example.]]></description>
			<content:encoded><![CDATA[<p>2 months ago we released <a href="http://wyday.com/wybuild/">wyBuild &#038; wyUpdate v2.5</a>. This release adds a free automatic updater control for C# &#038; VB.NET apps. And because we wanted to keep things simple we left the wyUpdate.exe to do all the hard work (checking, download, installing) in the background while <a href="http://wyday.com/wybuild/help/automatic-updates/">the AutomaticUpdater control</a> is visible on your app’s main form.</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2010/multi-process-c-sharp-app/update-available.png" title="AutomaticUpdater control in action" class="aligncenter" width="324" height="183" /></p>
<p>We wanted the AutomaticUpdater to be able to control the update steps, view progress, and cancel the updating. But we also wanted to keep all the updating logic in the wyUpdate.exe. For this to be successful we needed a way for the AutomaticUpdater control to talk to wyUpdate.exe while it’s running.</p>
<h2>The Answer: Inter-process communication (IPC)</h2>
<p><img alt="" src="http://img.wyday.com/blog/images/2010/multi-process-c-sharp-app/chrome-logo.png" title="Google Chrome" class="alignright" width="130" height="130" /></p>
<p>Inter-Process communication is a fancy computer science way of saying “processes that can talk to each other”. <a href="http://dev.chromium.org/developers/design-documents/inter-process-communication">Google Chrome uses IPC</a> to communicate between tabs of the browser &#038; plugins. It’s a simple way to keep parts of your program isolated from crashes.</p>
<p>For instance, if a tab of Google Chrome crashes only that single tab is killed. The rest of your tabs will continue to function normally.</p>
<h2>Lots of bad ways to do IPC</h2>
<p>Now that you know what inter-process communication is, let me tell you the worst ways to do it.</p>
<ul>
<li><strong>Shared memory</strong>: Difficult to set up &#038; difficult to manage.</li>
<li><strong>Shared files / registry</strong>: Very slow due to the writing &#038; reading to/from disk. Difficult to manage.</li>
<li><strong><a href="http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx" rel="nofollow">SendMessage</a> / <a href="http://msdn.microsoft.com/en-us/library/ms644944(VS.85,lightweight).aspx" rel="nofollow">PostMessage</a></strong>: Locks up the UI thread while the message is processed. Messages are limited to integer values. Can’t communicate from a non-admin process to an admin process. Assumes that your processes have a window.</li>
</ul>
<h2>Named Pipes</h2>
<p>Inter process communication using named pipes is what Google Chrome uses and what we use for wyUpdate and the AutomaticUpdater control. Let me teach you about <strong>named pipes</strong>.</p>
<p>“Like Mario’s pipes?”</p>
<p>Exactly like Mario’s pipes. Except, instead of jumping Mario through the pipe, you push data through the pipe:</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2010/multi-process-c-sharp-app/mario-pipes-wyupdate.jpg" title="Mario&#039;s pipes" class="aligncenter" width="600" height="383" /></p>
<h2>What do you put in the pipe?</h2>
<p>You can transfer any data between your processes. So what data should your transfer? The answer is “it depends”. The rule of thumb is to <strong>keep it short, and keep it simple</strong>. Here’s what we do with the named pipe between wyUpdate and the AutomaticUpdater control sitting on your application:</p>
<ul>
<li><strong>Command codes</strong>: The AutomaticUpdater can command wyUpdate to check for updates, download the updates, extract the update, and install the update, or cancel any current progress.</li>
<li><strong>Responses</strong>: wyUpdate can tell the AutomaticUpdater if there’s an update available, what changes there are in the update, and the progress of the current step (e.g. downloading).</li>
</ul>
<p>With this simple setup the AutomaticUpdater control that’s on your application is completely isolated from wyUpdate.</p>
<h2>Get the C# source</h2>
<p><a href="http://wyupdate.googlecode.com/files/NamedPipes.zip">Download the named pipes C# source</a>. It works with .NET 2.0, 3.0, 3.5 on Windows 2000 – Windows 7.</p>
<p>There are two files that do all the work: <strong>PipeServer.cs</strong> and <strong>PipeClient.cs</strong>. We use the PipeServer.cs file inside wyUpdate, and we use the PipeClient.cs file inside the AutomaticUpdater control.</p>
<p>Also included in the zip file is a simple messaging program to demonstrate communication between two separate processes:</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2010/multi-process-c-sharp-app/server-client.png" title="Named pipes client/server example" class="aligncenter" width="714" height="401" /></p>
<p><strong>Tell me what you think in the comments. I want to hear from you.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://wyday.com/blog/2010/multi-process-c-sharp-application-like-google-chrome-using-named-pipes/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		<feedburner:origLink>http://wyday.com/blog/2010/multi-process-c-sharp-application-like-google-chrome-using-named-pipes/</feedburner:origLink></item>
		<item>
		<title>Finishing touches: Make your .NET app shine with professionalism</title>
		<link>http://feedproxy.google.com/~r/wyday/wyattsblog/~3/uNtDGylnxLQ/</link>
		<comments>http://wyday.com/blog/2009/finishing-touches-make-your-net-app-shine-with-professionalism/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 07:53:22 +0000</pubDate>
		<dc:creator>Wyatt O'Day</dc:creator>
				<category><![CDATA[Asthetics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows Vista]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://wyday.com/blog/?p=139</guid>
		<description><![CDATA[Another easy tip to round out the series in 7 Days of Windows 7.]]></description>
			<content:encoded><![CDATA[<p>This is another easy tip to wrap up this series of articles.</p>
<h3>Keyboard accessibility</h3>
<p>Start your application and unplug your mouse. Can you navigate and use your application? If you hit the tab key does the next logical control get focused? Can you open the file menu by pressing Alt-F?</p>
<h4>Set tab ordering</h4>
<p>Simply set the “TabIndex” property of your controls in ascending starting with 0. This way when your users press the tab key they next focused control is the next control in the flow of your form.</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2009/7d7-polish/taborder.png" title="Tab ordering" class="aligncenter" width="281" height="229" /></p>
<h4>Menu quick keys</h4>
<p>To add “quick key” ability to your menus you just need to put an ampersand (“&#038;”) before the letter that will be used for quick access. For example, instead of a menu item captioned “File”, caption it “&#038;File” instead. Now your users can access that menu quickly by pressing Alt-F.</p>
<h3>SystemStyle Buttons, Radio Buttons, and Checkboxes</h3>
<p>In Windows Vista Microsoft changed the buttons, radio buttons, and checkboxes to have subtle animations. When you hover, check, and click these controls they all yield organic animations. But if you built your app using Windows Forms the subtle animations aren’t there.</p>
<p>To add these animations all you have to do is set the “FlatStyle” of these controls to “System”.</p>
<h3>Windows UX Guide</h3>
<p>Microsoft has assembled a great collection of <a href="http://msdn.microsoft.com/en-us/library/aa511258(loband).aspx">guidelines for designing applications</a>. It’s filled with screenshot examples showing good &#038; bad designs. Plus it’s surprising self deprecating – some of their examples of bad design are screenshots taken directly from Microsoft apps.</p>
<p>You should skim the guide at least once and bookmark it for later.</p>
<h3>7 Days of Windows 7</h3>
<p>That’s it for the series. If you missed the earlier articles you can <a href="http://wyday.com/blog/2009/7-days-of-windows-7-csharp-and-vb-net-tips/">see the full list of articles in the series</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://wyday.com/blog/2009/finishing-touches-make-your-net-app-shine-with-professionalism/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://wyday.com/blog/2009/finishing-touches-make-your-net-app-shine-with-professionalism/</feedburner:origLink></item>
	</channel>
</rss>
