<?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>Wyatt Says... &#187; C#</title>
	<atom:link href="http://wyday.com/blog/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://wyday.com/blog</link>
	<description>Design articles to make your users deliriously happy</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>
		<item>
		<title>How to detect .NET 2.0 vs. .NET 4.0 assemblies, and x86 vs. x64 vs. AnyCPU</title>
		<link>http://wyday.com/blog/2010/how-to-detect-net-assemblies-x86-x64-anycpu/</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&#39;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>
		</item>
		<item>
		<title>Multi-process C# app like Google Chrome</title>
		<link>http://wyday.com/blog/2010/multi-process-c-sharp-application-like-google-chrome-using-named-pipes/</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&#39;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>30</slash:comments>
		</item>
		<item>
		<title>Windows Vista and Windows 7 .NET Controls &#8211; Every possible one you could ever want</title>
		<link>http://wyday.com/blog/2009/windows-vista-and-windows-7-csharp-vb-dotnet-controls-every-possible-one-you-could-ever-want/</link>
		<comments>http://wyday.com/blog/2009/windows-vista-and-windows-7-csharp-vb-dotnet-controls-every-possible-one-you-could-ever-want/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 04:34:16 +0000</pubDate>
		<dc:creator>Wyatt O&#39;Day</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://wyday.com/blog/?p=138</guid>
		<description><![CDATA[Every free &#038; open source .NET control you could ever want. They work with Windows 98, 2000, XP, Vista, and Windows 7. Read on for links.]]></description>
			<content:encoded><![CDATA[<p>There are many Windows 7 controls already out there. I’ve included the best open source .NET components available. If you have other great controls, add them to the comments.</p>
<p>For each control I’ll list what versions of .NET it compiles for and what versions of Windows it will run on.</p>
<h3>Windows Ribbon for Windows Forms</h3>
<p>Arik Poznanski has a great series of posts about the ribbon control he wrote that wraps the Windows 7 API.</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2009/7d7-allcontrols/windows7.ribbon.png" title="Windows 7 Ribbon" class="aligncenter" width="525" height="170" /></p>
<p><a href="http://windowsribbon.codeplex.com/" rel="nofollow"><strong>Download it now</strong></a> – full source code &#038; examples. Also, <a href="http://blogs.microsoft.co.il/blogs/arik/archive/tags/Ribbon/default.aspx" rel="nofollow">view his series of articles</a> (9 of them as of today).<br />
<strong>Works with</strong>: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)<br />
<strong>Windows Versions</strong>: Only Windows 7</p>
<h3>Windows API Code Pack for Microsoft .NET Framework</h3>
<p>This is a mammoth control collection that is the <a href="http://code.msdn.microsoft.com/WindowsAPICodePack/People/ProjectPeople.aspx" rel="nofollow">work of 3 people</a>.</p>
<p><strong>Here are the major features:</strong></p>
<ul>
<li>Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.</li>
<li>Windows 7 Libraries, Known Folders, non-file system containers.</li>
<li>Windows Shell Search API support, a hierarchy of Shell Namespace entities, and Drag and Drop functionality for Shell Objects.</li>
<li>Explorer Browser Control.</li>
<li>Shell property system.</li>
<li>Windows Vista and Windows 7 Common File Dialogs, including custom controls.</li>
<li>Windows Vista and Windows 7 Task Dialogs.</li>
<li>Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)</li>
<li>Sensor Platform APIs</li>
<li>Extended Linguistic Services APIs</li>
<li>Power Management APIs</li>
<li>Application Restart and Recovery APIs</li>
<li>Network List Manager APIs</li>
<li>Command Link control and System defined Shell icons.</li>
</ul>
<p><a href="http://code.msdn.microsoft.com/WindowsAPICodePack/Release/ProjectReleases.aspx" rel="nofollow"><strong>Download it now</strong></a> – full source code &#038; examples.<br />
<strong>Compiles with</strong>: Windows Forms (.NET 3.5) &#038; Windows Presentation Foundation (WPF)<br />
<strong>Windows Versions</strong>: Windows Vista &#038; Windows 7</p>
<h3>Windows 7 Progress Bar</h3>
<p>Windows 7 Progress Bar is an open source progress bar component that allows you to add a progress bar to your program&#8217;s taskbar button. In addition, you can control the different states of the progress bar (normal, error, and paused) for Vista &#038; Windows 7.</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2009/7d7-allcontrols/2000.xp.vista.7.pbs.png" title="Windows 7 Progress bar in action" class="aligncenter" width="600" height="590" /></p>
<p><a href="http://wyday.com/windows-7-progress-bar/"><strong>Download it now</strong></a> – full source code &#038; examples.<br />
<strong>Compiles with</strong>: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)<br />
<strong>Windows Versions</strong>: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7</p>
<h3>VistaMenu</h3>
<p>VistaMenu is a menu component that allows you to add Windows 7 and Windows Vista-style menus with icons to your program. It&#8217;s written in C# and works with all .NET languages.</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2009/7d7-allcontrols/vistamenu-platforms.png" title="VistaMenu" class="aligncenter" width="500" height="575" /></p>
<p><a href="http://wyday.com/vistamenu/"><strong>Download it now</strong></a> – full source code &#038; examples.<br />
<strong>Compiles with</strong>: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)<br />
<strong>Windows Versions</strong>: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7</p>
<h3>SplitButton</h3>
<p>SplitButton is a button control with a region that shows a context menu when clicked. It&#8217;s written in C# and works with all .NET languages.</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2009/7d7-allcontrols/splitbutton.png" title="SplitButton" class="aligncenter" width="250" height="250" /></p>
<p><a href="http://wyday.com/splitbutton/"><strong>Download it now</strong></a> – full source code &#038; examples.<br />
<strong>Compiles with</strong>: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)<br />
<strong>Windows Versions</strong>: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7</p>
<h3>LinkLabel2</h3>
<p>LinkLabel2 is a fixed version of the Windows.Forms LinkLabel control. It features the correct system &#8220;hand&#8221; cursor, and correct font rendering.</p>
<p><img alt="" src="http://img.wyday.com/blog/images/2009/7d7-allcontrols/linklabel2-comparison.png" title="LinkLabel2" class="aligncenter" width="342" height="223" /></p>
<p><a href="http://wyday.com/linklabel2/"><strong>Download it now</strong></a> – full source code &#038; examples.<br />
<strong>Compiles with</strong>: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)<br />
<strong>Windows Versions</strong>: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7</p>
<h3>7 Days of Windows 7</h3>
<p>Join me tomorrow when I talk about Finishing touches: Make your .NET app shine with professionalism. <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/windows-vista-and-windows-7-csharp-vb-dotnet-controls-every-possible-one-you-could-ever-want/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
