<?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>InterKnowlogy Blogs</title>
	<atom:link href="http://blogs.interknowlogy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.interknowlogy.com</link>
	<description>Blogging the Art of Software</description>
	<lastBuildDate>Wed, 02 May 2012 22:05:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Windows 8 Developer Event &#8211; LA</title>
		<link>http://blogs.interknowlogy.com/2012/05/02/windows-8-developer-event-la/</link>
		<comments>http://blogs.interknowlogy.com/2012/05/02/windows-8-developer-event-la/#comments</comments>
		<pubDate>Wed, 02 May 2012 22:03:35 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3210</guid>
		<description><![CDATA[On Monday, May 23rd, I had the chance to talk about Interknowlogy and some of our latest Developments at Microsofts Windows 8 Developer Event in Los Angeles. In particular, I spoke about our &#8220;Personal Rehab Trainer&#8221; which enables patients to practice their rehab exercises at home instead of having to go to rehab sessions. If [...]]]></description>
			<content:encoded><![CDATA[<p>On Monday, May 23rd, I had the chance to talk about Interknowlogy and some of our latest Developments at Microsofts Windows 8 Developer Event in Los Angeles.<br />
In particular, I spoke about our &#8220;Personal Rehab Trainer&#8221; which enables patients to practice their rehab exercises at home instead of having to go to rehab sessions. If you want to find out how this Rehab Trainer cuts costs, how it provides patients with better service and what all this has to do with WinRT and Windows 8, make sure to check out the recorded event at <a title="Windows 8 Developer Event" href="http://livestre.am/1Hjyk" target="_blank">Windows 8 Developer Event</a>. My presentation can be found between 1h:44m and 1h:51m.</p>
<p>I met a ton of great and really inspiring Microsoft Developer Evangelists who spoke about the following topics:</p>
<ul>
<li>Windows 8 from the Consumer’s Perspective<br />
(by <a title="Jerry Nixon" href="http://blog.jerrynixon.com/" target="_blank">Jerry Nixon</a>)</li>
<li>Windows 8 Store and Developer Opportunity<br />
(by Michael Johnson)</li>
<li>Windows 8 Hello World<br />
(by <a title="Alice Pang" href="http://blogs.msdn.com/b/alicerp/" target="_blank">Alice Pang</a> (Make sure to register for her <a title="Windows 8 Developer Camp" href="http://blogs.msdn.com/b/alicerp/archive/2012/04/26/register-now-attend-a-free-windows-8-developer-camp-near-you.aspx" target="_blank">Windows 8 Developer Camp</a>))</li>
<li>Visual Studio 11<br />
(by <a title="Jeremy Foster" href="http://www.linkedin.com/in/codefoster" target="_blank">Jeremy Foster</a>)</li>
<li>Windows 8 Core Capabilities &amp; Interactions<br />
(by Matt Harrington)</li>
<li>Metro Design Language<br />
(by <a title="Jeremy Foster" href="http://www.linkedin.com/in/codefoster" target="_blank">Jeremy Foster</a>)</li>
<li>Building Metro Apps with JavaScript<br />
(by Michael Palermo)</li>
<li>Building Metro Apps with XAML<br />
(by <a title="Jerry Nixon" href="http://blog.jerrynixon.com/" target="_blank">Jerry Nixon</a>)</li>
</ul>
<div>Thanks to the pictures <a title="Justine Li" href="http://www.linkedin.com/pub/justine-j-li/35/569/929" target="_blank">Justine Li</a> took from the event I can provide you with a few impressions of the event!</div>
<p><a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/MG_3462.jpg"><img class="alignnone  wp-image-3212" title="Microsoft's Evangelists" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/MG_3462-1024x682.jpg" alt="" width="450" /></a><em>MS Evangelists</em></p>
<p><a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/DSCN0223.jpg"><img class="alignnone  wp-image-3213" title="The Audience" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/DSCN0223-1024x768.jpg" alt="" width="450" /></a><em>The Audience</em></p>
<p><a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000039.jpg"><img class="alignnone  wp-image-3218" title="Trial night..." src="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000039-1024x768.jpg" alt="" width="450" /></a><em>The Audience the day before</em></p>
<p><a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000391.jpg"><img class="alignnone  wp-image-3215" title="The presentation" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000391-1024x768.jpg" alt="" width="450" /></a><em>Me speaking</em></p>
<p><a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000434.jpg"><img class="alignnone  wp-image-3214" title="Giving autographs :)" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000434-1024x768.jpg" alt="" width="450" /></a><em>Me giving autographs <img src='http://blogs.interknowlogy.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </em></p>
<p><a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000043.jpg"><img class="alignnone  wp-image-3216" title="The Demo" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000043-1024x768.jpg" alt="" width="450" /></a><em>The demo on the demo table</em></p>
<p><a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000045.jpg"><img class="alignnone  wp-image-3217" title="Our booth in the VIP area" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/05/WP_000045-1024x768.jpg" alt="" width="450" /></a><em>Our VIP booth</em></p>
<p>Thank you, Microsoft, for this great event!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/05/02/windows-8-developer-event-la/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP Simplified: CoreApplicationService (Lifecycle)</title>
		<link>http://blogs.interknowlogy.com/2012/04/30/wp-simplified-coreapplicationservice-lifecycle/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/30/wp-simplified-coreapplicationservice-lifecycle/#comments</comments>
		<pubDate>Tue, 01 May 2012 05:00:17 +0000</pubDate>
		<dc:creator>Danny Warren</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows Phone 7.5]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3156</guid>
		<description><![CDATA[In my post Simplyfying the Windows Phone Development Experience! Codename: LionHeart I explain that LionHeart is a demo app that I’m using to prove out a few lessons we’ve learned here at IK from our last Windows Phone project. In this post I will start to get into the meat of the app starting in [...]]]></description>
			<content:encoded><![CDATA[<p>In my post <a href="http://blogs.interknowlogy.com/2012/04/11/simplifying-the-windows-phone-development-experience-codename-lionheart/">Simplyfying the Windows Phone Development Experience! Codename: LionHeart</a> I explain that LionHeart is a demo app that I’m using to prove out a few lessons we’ve learned here at IK from our last Windows Phone project. In this post I will start to get into the meat of the app starting in a class named CoreApplicationService (CAS).<br />
<h2>What is CoreApplicationService’s Purpose?</h2>
<h3>Event Forwarding</h3>
<p>One of the purposes of the CoreApplicationService (CAS) is to expose events from across the app to ViewModels (VMs) or any other class that is not instantiated by App.xaml. This class acts, in a very simplified way, as an event aggregator. It is not, however, an event aggregator as found in Prism. Instead it’s more of a one to one event forwarding class. For example, in App.xaml there are two events named Deactivated and Closing. Therefore, in the CAS there are two identical events named Deactivated and Closing. When the event is handled in App.xaml.cs we simply forward the handling onto the CAS as show in this example:  </p>
<p><pre class="brush: csharp; title: ; notranslate">
public partial class App : Application
{
   private void ApplicationDeactivated(object sender, DeactivatedEventArgs e)
   {
       CoreApplicationService.Instance.OnDeactivated(e);
   }
}
</pre>
</p>
<p>Currently the events handled in the CAS are:
<p>From App.xaml</p>
<ul>
<li>Deactivated
<li>Closing
<li>Obscured
<li>Unobscured
<li>NavigationFailed
<li>UnhandledException</li>
</ul>
<p>From PhoneApplicationFrame</p>
<ul>
<li>Navigating
<li>Navigated</li>
</ul>
<p>In all cases, the CAS acts as a forwarding system for any object the desires to subscribe to these events. In LionHeart those objects are usually VMs. This pattern allows the VM to be responsible for knowing when and what to do during these events. This pattern has made more and more sense as we’ve discussed possible solutions to our problem of telling VMs when to Deactivate (prepare for tombstoning) etc.</p>
<h3>Error Reporting</h3>
<p>Another responsibility of CAS is to prompt the consumer of the app to send error data to the developer. We found <a href="http://blogs.msdn.com/b/andypennell/archive/2010/11/01/error-reporting-on-windows-phone-7.aspx" target="_blank">Little Watson</a> created by Andy Pennell at Microsoft which simply collects unhandled exception information and stores it in a file in IsolatedStorage before the app closes. The next time the consumer launches the app they are prompted to send the error file to the developer, which they can choose to not send it if they desire. The error file is then deleted and the application will not prompt again until an error file exists again. This is so helpful I cannot even begin to express how many bugs we have been able to track down because of this tool. I want to start buffing this helper class out with logging since the error information we receive on the phone is not as helpful as it could be. Adding a logging feature that began each time the application was launched would be of even greater benefit.</p>
<h3>Navigation</h3>
<p>This purpose is what originally drove us to create the CAS. In fact we had originally named the CAS as NavigationService, but as it’s functionality increased and purpose morphed we decided that name was to specific and did not convey what we wanted. Navigation will be covered in greater detail in another post. In simple terms we use a dictionary of object to string mappings. Each string represents the Uri to a page. These mappings are set immediately after initializing the CAS as shown in the section below “How to use CoreApplicationService.” </p>
<p><pre class="brush: csharp; title: ; notranslate">
public partial class App : Application
{
   private void InitializeNavigationMappings()
   {
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.HOME_VIEW_KEY, &quot;/Views/HomeView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.MY_VIEW_KEY, &quot;/Views/MyView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.ALL_CLIENTS_VIEW_KEY, &quot;/Views/AllClientsView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.CLIENT_VIEW_KEY, &quot;/Views/ClientView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.MY_REPORTS_VIEW_KEY, &quot;/Views/MyReportsView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.REPORT_VIEW_KEY, &quot;/Views/ReportView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.ALL_SESSIONS_VIEW_KEY, &quot;/Views/AllSessionsView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.MY_SESSIONS_VIEW_KEY, &quot;/Views/MySessionsView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.SESSION_VIEW_KEY, &quot;/Views/SessionView.xaml&quot;);
       CoreApplicationService.Instance.Mappings.Add(ViewKeys.SETTINGS_VIEW_KEY, &quot;/Views/SettingsView.xaml&quot;);
   }
}
</pre>
</p>
<p>In the example code above you will notice the use of ViewKeys which is a struct that contains string values that we use as keys. The key does not need to be a string instead it can be any object. Sometimes we will use typeof(object) for views that represent specific types. We found that strings were required for some views and decided to go with all strings for consistency. Remembering that VMs will be requesting navigation most of the time we did not use typeof(Page) as the key, because VMs should not have access to those types.</p>
<h2>How to use CoreApplicationService</h2>
<p>The CAS is provided via a static property of itself named Instance as a singleton. There are two times the CAS will need to be instantiated. The first is when the application is Launching. The second case is when the application is being Activated, but only if there is no application state. In both cases no VMs exist yet, therefore the CAS will not forward the Launching and Activating events because no object would or could receive them. Instead we use the events to initialize the CAS.</p>
<p><pre class="brush: csharp; title: ; notranslate">
public class CoreApplicationService
{
   private static CoreApplicationService _instance;
   public static CoreApplicationService Instance
   {
       get { return _instance ?? (_instance = new CoreApplicationService()); }
   }
}

public partial class App : Application
{
   private void Initialize(bool isLaunching)
   {
       CoreApplicationService.Instance.Initialize(RootFrame, isLaunching);
       InitializeNavigationMappings(); //As shown in above section “What is CoreApplicationService’s Purpose?” and subsection “Navigation”.
   }

   private void ApplicationLaunching(object sender, LaunchingEventArgs e)
   {
       Initialize(true);
   }

   private void ApplicationActivated(object sender, ActivatedEventArgs e)
   {
       if (!e.IsApplicationInstancePreserved)
       {
           Initialize(false);
       }
   }
}
</pre>
</p>
<p>Initialize accepts two parameters: the PhoneApplicationFrame which is used for navigation, and a boolean indicating if the application is launching.</p>
<p><pre class="brush: csharp; title: ; notranslate">
public class CoreApplicationService
{
   public void Initialize(PhoneApplicationFrame frame, bool isLaunching)
   {
       LittleWatson.CheckForPreviousException();

       _frame = frame;
       _frame.Navigated += FrameNavigatedHandler;
       _frame.Navigating += FrameNavigatingHandler;

       PersistTombstoningValue(IS_LAUNCHING_KEY, isLaunching);
   }
}
</pre>
</p>
<p> The reason for the boolean is for VM initialization. This will be explained in much greater detail later on, but for those curious minds out there during Activating (without state) when VMs initialize there are no navigation parameters. This is used as an indication that the application was tombstoned. Because this same state exists during Launching we must differentiate the two somehow. We got around this by adding a boolean to the tombstoning values that is checked for when no navigation parameters exist and indicates the application is Launching not Activating. As I stated before I will cover this in later posts in greater detail.</p>
<h2>Conclusion</h2>
<p>This concludes the introduction into the CoreApplicationService and how it plays into the lifecycle of the phone app. This service is the backbone to LionHeart and all phone apps that use it. As we cover navigation and how VMs integrate with this service you’ll understand why it is so important and why it is so helpful. As always if you have any suggestions for improvement, comments, or questions please post them. This is not meant to be a one man show, but rather a starting point for phone app architecture.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/30/wp-simplified-coreapplicationservice-lifecycle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More than you ever wanted to know about AES Crypto in .NET</title>
		<link>http://blogs.interknowlogy.com/2012/04/27/more-than-you-ever-wanted-to-know-about-aes-crypto-in-net/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/27/more-than-you-ever-wanted-to-know-about-aes-crypto-in-net/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 19:01:36 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[AES]]></category>
		<category><![CDATA[Block Ciphers]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[CryptoStream]]></category>
		<category><![CDATA[Decryption]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Hashing]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[Passwords]]></category>
		<category><![CDATA[PBKDF2]]></category>
		<category><![CDATA[RandomNumberGenerator]]></category>
		<category><![CDATA[RFC 2898]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3159</guid>
		<description><![CDATA[First, before I begin anything, I want to point out that cryptography is hard. REALLY hard. There are so many possible points of failure, and those points of failure and methods of attack can change depending on what the purpose of encrypting the data is. If you do it wrong, you get lawsuits, and/or you [...]]]></description>
			<content:encoded><![CDATA[<p>First, before I begin anything, I want to point out that cryptography is hard. REALLY hard. There are so many possible points of failure, and those points of failure and methods of attack can change depending on what the purpose of encrypting the data is. If you do it wrong, you get lawsuits, and/or you end up on the front pages of major news organizations for data security breaches. Or a rival nation gets your top-secret plans to rule the world. You get the idea. I&#8217;ll touch on some of the technical points of failure briefly; I&#8217;m mainly going to be exploring this topic through a fairly simple scenario: A password vault file, encrypted with a password, and stored locally on my computer (potentially synced to other computers through some syncing service).</p>
<p>As with any good crypto, the first line of defense is always preventing an attacker from gaining access to the encrypted data in the first place. If data is going over a network, encryption should be part of that as well, and that brings in a whole new host of issues that are outside of the scope of this article. Since I&#8217;m planning on storing the data locally on my hard drive, the first line of defense is me and my computer: Lock my computer when I walk away. Make sure there&#8217;s no spyware or malware on my computer, no keyloggers or other devices that could steal my password, etc&#8230; Going back to my original point about crypto being hard, it&#8217;s hard not only because writing the code is hard, it&#8217;s difficult because of all the ancillary ways someone could potentially get access to my data that I have to account for. </p>
<p><img src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/hacker2.png" alt="" title="hacker" width="308" height="400" class="alignright size-full wp-image-1689" /></p>
<p>If I leave my computer unlocked, someone could steal data off of it. Install a keylogger. If I leave this password app open someone could just go in and look at my passwords after I&#8217;ve decrypted them. If they have physical access someone could install a HARDWARE keylogger between my keyboard and computer. Pull out my hard drive and clone it. Hack into the company Wi-Fi network and remote access my computer. Or even STEAL my computer. Or TSA could confiscate it. And/or force / legally compel me to reveal my password. You get the idea. There is no such thing as absolute security or secrecy.</p>
<p>However, let&#8217;s assume for a moment that an attacker DOES somehow manage to get access to my vault file. (Maybe by getting access to my computer when the vault program is closed and the data encrypted, or a folder syncing program has a hiccup and spams a public link to it on the Internet) My password file is in the hands of someone actively trying to get at my data, and the only thing protecting the data is my password and good cryptography. So. How do I use good cryptographic practices to secure my data?</p>
<p>Since we want to use the latest and greatest, we pick AES (Advanced Encryption Standard, successor to Date Encryption Standard and Triple Data Encryption Standard or Triple DES), Rijndael 256 to be specific (It&#8217;s good enough for government work&#8230;). In the <code>System.Security.Cryptography</code> namespace, Microsoft has kindly supplied us with the RijndaelManaged class and a pre-provided implementation of the AES standard. I ALWAYS recommend using a pre provided class instead of attempting to roll your own. The ones from Microsoft have gone through EXTENSIVE testing, code, and security review to verify the correctness of the algorithms and code. Frankly, if you write your own, yours will probably have bugs. Bad ones. Bugs that might get you put on the front page of major news organizations for data security breaches if you do it wrong. Warning given, point made, moving on.</p>
<p>Now, there are a couple of things you&#8217;ll need in order to do symmetric encryption when we crack open the RijndaelManaged class and try to create an encryption transform:</p>
<ul>
<li>A Key</li>
<li>An Initialization Vector or IV</li>
<li>Your Data</li>
</ul>
<h2>The Key</h2>
<p>First, the key, which is represented as a byte array of some fixed size. The size of your key is important, the number of bits has to match what the algorithm supports, in the case of Rijndael, it supports key sizes of 128, 192, and 256. In our case, we&#8217;ll be using a key size of 256. The number of <strong>byte</strong>s we need is 256 divided by 8 (remember, the key size for the algorithm is specified in <strong>bit</strong>s, but our code mainly works with <strong>byte</strong>s). So if I&#8217;m declaring a byte array for the key for AES 256, it would be <code>new byte[32]</code>. </p>
<h3>Derive your Key</h3>
<p>Now wait, how the heck to I remember a 32 number combination? I can&#8217;t. You probably can&#8217;t, and unless you&#8217;re a brainiac with an eidetic memory I wouldn&#8217;t suggest trying with any reasonable hope of success. So, since I have now come to this sad conclusion about my memory, I need some way to take a password or key that I can memorize and turn it into a 32 byte key. Fortunately, there&#8217;s a way to do just that by way of a password based key derivation function called <code>PBKDF2</code>. It&#8217;s also a standard (RFC 2898, which is only important because the code uses the name of the spec for the class name and not <code>PBKDF2</code> like I would expect&#8230; go figure). Essentially, <code>PBKDF2</code> is a piece of code that hashes an arbitrary length of text into a pseudo random key. Now, we could use something like <code>MD5</code> to do something similar, but <code>PBKDF2</code>is designed with cryptography in mind, and to be slow on purpose. Why does it need to be slow? Simply this, cryptography is a big huge lever that makes it easy to go one way, and hard to go another. <code>MD5</code> is FAST to compute, and someone trying to break into your encrypted data wants to be able to test as many passwords as possible as fast as possible. <code>PBKDF2</code>is slow and more difficult to compute, and the harder it is, the longer it takes to generate a hash, which dramatically reduces the number of passwords a hacker trying to attack your vault can try per second. (There&#8217;s a really good article by Jeff Atwood here: <a href="http://www.codinghorror.com/blog/2012/04/speed-hashing.html">http://www.codinghorror.com/blog/2012/04/speed-hashing.html</a> on hashing algorithms in security, rainbow tables, speed hashing, why it&#8217;s important to have a slow hash for security, and so on. If you&#8217;re interested on reading more about it)</p>
<p>How do we create this hashed key with <code>PBKDF2</code>? The constructor takes 3 things, a string password, an iteration count, and a byte array for something called a salt (Not in that order). The Password is easy, it&#8217;s a string or byte array and it&#8217;s whatever you choose to use as your &#8220;<code>uB3rAw3$omeP@assw0rd!</code>&#8220;. iteration count is pretty self-explanatory too, it defaults to 1000, and the bigger the number, the more calculation rounds it does and the longer it takes to calculate the hash. But what about this salt thing? What is it, and why is it important? Do I even care? So here we go.</p>
<h3>Salt your Vault</h3>
<p>If you&#8217;ve heard about salt or salting passwords before, it was probably in reference to a website or service, usually some piece of code that you controlled that sat between your users (or a supposed attacker) and the  hashed passwords in your database so that an attacker couldn&#8217;t just *make up* a password like <code>zn3lzl</code> that would hash to the same value as the users password like <code>mycoolpassword2</code> and allow them to log in. If we assume that the attacker has access to your password vault, we can probably assume he has access to your program as well, and it won&#8217;t be very hard to figure out some static salt value you&#8217;ve stored in your code. So it&#8217;s useless right? In some ways yes, in some ways no. IF it&#8217;s JUST you, or the attacker is targeting JUST YOUR vault, then yes, it doesn&#8217;t matter. However, if for some reason your password vault app becomes popular, and an attacker gains access to, lets say 5000 different peoples vault files, it&#8217;s much much easier to check the same passwords across ALL the vaults at once if the salt values are the same. That is again assuming he is not targeting just one particular vault. If they&#8217;re all different, the time required to check a password across all the vaults goes up by a factor of 5000, making it less viable to quickly crack multiple vaults. My thought is to simply store the salt along with the vault, since if an attacker has access to your vault, he probably has access to wherever I&#8217;d store the salt anyways, and it at least requires him to compute a separate hash for each vault. So, I&#8217;ll generate and store a separate, cryptographically random generated salt with my vault file.</p>
<p>Something like this: </p>
<pre class="brush: csharp; title: ; notranslate">
var salt = new byte[256];

using (var rnd = RandomNumberGenerator.Create())
{
     rnd.GetBytes(salt);
}</pre>
<p>As an aside, realize that no amount of encryption can save your data from a bad password. Good hackers are GOING to use huge word lists and fantastic substitution / transposition / combination rules before they even attempt to use a brute force attack. &#8216;<code>MyL1ttl3P0ny</code>&#8216; is not a good password. &#8216;<code>abc123</code>&#8216; is arguably much worse; but then you&#8217;re probably not reading this if <code>abc123</code> is something you&#8217;d use for a password.</p>
<p>Now that we have our password, the salt (loaded from our vault file) and the number of iterations, we can derive a key with the correct size:</p>
<pre class="brush: csharp; title: ; notranslate">var deriveBytes = new Rfc2898DeriveBytes(myPassword, mySalt, 10000);
var aes256Key = deriveBytes.GetBytes(32);</pre>
<p>Tada! magic. We now have a byte key from the password that we supplied earlier. Ok, now that we have our key, we can see that when you try to create our encryption or decryption transform that it is requiring something called an initialization vector (IV). I know when I was going through all this that I was thinking &#8220;what the heck is an initialization vector?&#8221; Since I had to teach myself what it was and why it was important, I&#8217;m going to assume somebody also doesn&#8217;t know and brain dump what I&#8217;ve learned on you all as well. </p>
<h2>Block Ciphers, Chaining, and Initialization Vectors</h2>
<p>First, we have to understand a few things, how a block ciphers works, how cipher block chaining works, how the IV plays in, and why it&#8217;s all important. To begin with, block ciphers. Most computer ciphers these days are done using cipher blocks of a given bit size, usually in round multiples of 2, for example 128 bit or 16 bytes chunks (this is actually the size AES uses). Our clear text gets chunked up into these small, manageable blocks of data. Then encryption transform is then run multiple times on each block, and the resulting blocks are all concatenated together to form the final encrypted output.</p>
<p>Because encrypted blocks are computed independently, changes somewhere in the original unencrypted data might only change the encrypted data for a few blocks of the resulting encrypted output. Furthermore, if you happened to have the same 16 byte chunk repeated again such that it aligned with a different blocks, you will get the exact same block of encrypted output. On one hand, this could be useful if you want to send delta updates to an encrypted file, it also means that attacks against individual blocks are feasibly be easier or useful information could be obtained by comparing one version of the vault to another or even patterns might still exist even within the encrypted date. A really awesome example of why it’s important to apply some additional steps during the encryption process with block ciphers are these three images below: (Courtesy of Wikipedia): </p>
<p>Original | No Block Chaining | Proper Cipher Block Chaining<br />
<img src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/tux-plain.jpg" alt="" title="tux-plain" width="196" height="216" class="alignleft size-full wp-image-1692" /><img src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/tux-ecb.png" alt="" title="tux-ecb" width="196" height="216" class="alignleft size-full wp-image-1691" /><img src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/tux-cbc.png" alt="" title="tux-cbc" width="196" height="216" class="alignleft size-full wp-image-1690" /><br style="clear: left;" /></p>
<p>This is where CBC or cipher block chaining comes in. CBC fixes this problem by taking the previously encrypted block and performing a bitwise XOR between it and the raw bytes of the plain text of the next block to be encrypted. Effectively, this means that a one byte change in the first block will change EVERY OTHER block in the resulting ciphertext. However, there&#8217;s one last piece.  If the first couple of blocks are NOT changed in any way, you can still leek some information about changes that were made by way of the first changed block. So if I have blocks <code>A</code> <code>B</code> <code>C</code> <code>D</code> <code>E</code> and block <code>C</code> gets changed, CBC will cause the resulting ciphertext for blocks <code>D</code> and <code>E</code> to change. It will NOT affect blocks <code>A</code> and <code>B</code>. So, at last, we finally get to the purpose of the initialization vector. The IV is essentially a completely random block to start off the cipher chain. Makes sense now doesn&#8217;t it? If I have a completely random block that I create and pass along, it guarantees that even if the plain text doesn&#8217;t change at all, the ciphertext will be completely different each time, assuming I generate a new IV each time I change the cipher text. In practice, encrypted data should be statistically indistinguishable from random noise.</p>
<p>Illustration of the process of a block cipher with CBC for Encryption:<br />
<img src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/crypto-cbc-encrypt.png" alt="" title="crypto-cbc-encrypt" width="600" height="243" class="alignnone size-full wp-image-1693" /></p>
<p>Illustration of the process of a block cipher with CBC for Decryption:<br />
<img src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/crypto-cbc-decrypt.png" alt="" title="crypto-cbc-decrypt" width="600" height="222" class="alignnone size-full wp-image-1694" /></p>
<p>Now that we know why we need an initialization vector, we also know, or can guess, what size it should be without having to look at the documentation (16 bytes, because that&#8217;s the block size for AES, and our IV is essentially a known random starting block). Since we should generate a new block and also store it with our vault, I&#8217;m going to declare our IV and initialize it the same way we initialized our salt:</p>
<pre class="brush: csharp; title: ; notranslate">var iv = new byte[16];

using (var rnd = RandomNumberGenerator.Create())
{
   rnd.GetBytes(mySalt);
   rnd.GetBytes(iv);
}</pre>
<h2>The CryptoStream</h2>
<p>Now that we have all the pieces we can put it all together and encrypt our data to a MemoryStream (the memory stream could be anything, including a <code>FileStream</code>, but this is easier for demo and console output):</p>
<pre class="brush: csharp; title: ; notranslate">using(var ms = new MemoryStream())
{
   using (var cryptoStream = new CryptoStream(ms, transform.CreateEncryptor(aes256Key, iv), CryptoStreamMode.Write))
   {
      cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Count());
      cryptoStream.FlushFinalBlock();
   }

   cipherTextBytes = ms.ToArray();
}</pre>
<p>And now the code snippet for decrypting the <code>cypherTextBytes</code>:</p>
<pre class="brush: csharp; title: ; notranslate">using (var ms = new MemoryStream(cipherTextBytes))
{
   using (var cryptoStream = new CryptoStream(ms, transform.CreateDecryptor(aes256Key, iv), CryptoStreamMode.Read))
   {
      var decryptedBytes = new byte[cipherTextBytes.Length];
      var length = cryptoStream.Read(decryptedBytes, 0, decryptedBytes.Length);

      var decryptedText = Encoding.UTF8.GetString(decryptedBytes.Take(length).ToArray());
   }
}</pre>
<h3>Padding under the covers</h3>
<p>Some final notes block cipher padding: You&#8217;ll notice that when I&#8217;m reading the stream I have the following line of code: <code>decryptedBytes.Take(length).ToArray()</code> When you&#8217;re using a block cipher like AES, just like the key has to be exactly a certain size, each block of initial data ALSO has to be a certain size. This means you ARE going to get some extra data tacked on the end of your stream that you weren&#8217;t anticipating. There&#8217;s a couple of ways this can be handled, <code>RijndaelManaged</code> has a couple of padding modes that it can use ranging from filling all the additional slots of data with zeros, or filling them with completely random data, but by default it uses <code>PaddingMode.PKCS7</code> which fills each extra bytes needed to make the length of the data an even multiple of 16 bytes with the number that represents the number of padded bytes added to fill the empty space. If you have the exact amount of data to exactly to fill the number of blocks, the padding algorithm will add an extra block to ensure that the last byte in the last block that is read represents the amount of padding. Otherwise, depending on whatever data you&#8217;re storing, you could accidentally lose some of your data if it was misinterpreted as padding. The crypto stream is aware of the padding and will return the correct length of the original data on the last read call. I simplified the stream reading process for simplicity of demonstrating the use of the crypto stream and how it handles padding, it just reads everything and trims the result with <code>decryptedBytes.Take(length).ToArray()</code>. In real life, you should use or make a &#8216;real&#8217; stream reader that reads data out of the stream in chunks and aggregates them together, or just serialize / deserialize your objects directly to and from the crypto stream.</p>
<p>Finally:</p>
<h2>The Full Demo</h2>
<pre class="brush: csharp; title: ; notranslate">using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

public class CryptoDemo
{
    public static void Main(string[] args)
    {
        TestEncryptionAndDecryption();

        Console.ReadLine();
    }

    public static void TestEncryptionAndDecryption()
    {
        const string myPassword = &quot;uB3rAw3$omeP@assw0rd!&quot;;
        const string myData = &quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit. &quot; +
                              &quot;Morbi rutrum pulvinar purus, nec ornare neque cursus id. &quot; +
                              &quot;Nunc non tortor est. Morbi laoreet commodo tellus, et suscipit neque elementum eu. &quot; +
                              &quot;Sed velit lorem, ultricies id varius vitae, eleifend eget massa. &quot; +
                              &quot;Curabitur dignissim eleifend quam, sit amet interdum velit rutrum vel. &quot; +
                              &quot;Nulla nec enim tortor.&quot;;
        var plainTextBytes = Encoding.UTF8.GetBytes(myData);

        Console.WriteLine(&quot;Password ({0} bytes): &quot;, Encoding.UTF8.GetBytes(myPassword).Length);
        Console.WriteLine(myPassword);
        Console.WriteLine();

        Console.WriteLine(&quot;Plain Text ({0} bytes): &quot;, plainTextBytes.Length);
        Console.WriteLine(myData);
        Console.WriteLine();

        var mySalt = new byte[256];
        var iv = new byte[16];

        using (var rnd = RandomNumberGenerator.Create())
        {
            rnd.GetBytes(mySalt);
            rnd.GetBytes(iv);
        }

        var transform = new RijndaelManaged();

        Console.WriteLine(&quot;Salt ({0} bytes): &quot;, mySalt.Length);
        Console.WriteLine(Convert.ToBase64String(mySalt));
        Console.WriteLine();
        Console.WriteLine(&quot;Initilization Vector ({0} bytes): &quot;, iv.Length);
        Console.WriteLine(Convert.ToBase64String(iv));
        Console.WriteLine();

        // Derive the passkey from a hash of the password plus salt with the number of hashing rounds.
        var deriveBytes = new Rfc2898DeriveBytes(myPassword, mySalt, 10000);

        // This gives us a derived byte key from our password.
        var aes256Key = deriveBytes.GetBytes(32);

        Console.WriteLine(&quot;Derived Key ({0} bytes): &quot;, aes256Key.Length);
        Console.WriteLine(Convert.ToBase64String(aes256Key));
        Console.WriteLine();

        byte[] cipherTextBytes;

        using (var ms = new MemoryStream())
        {
            using (var cryptoStream = new CryptoStream(ms, transform.CreateEncryptor(aes256Key, iv), CryptoStreamMode.Write))
            {
                cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Count());
                cryptoStream.FlushFinalBlock();
            }

            cipherTextBytes = ms.ToArray();

            Console.WriteLine(&quot;Encrypted Text ({0} bytes): &quot;, cipherTextBytes.Length);
            Console.WriteLine(Convert.ToBase64String(cipherTextBytes));
            Console.WriteLine();
        }

        // this resets the algorithm. Normally, if we have a seperate encrypt / decrypt method
        // we would create a new instance of
        transform.Clear();

        using (var ms = new MemoryStream(cipherTextBytes))
        {
            using (var cryptoStream = new CryptoStream(ms, transform.CreateDecryptor(aes256Key, iv), CryptoStreamMode.Read))
            {
                var decryptedBytes = new byte[cipherTextBytes.Length];
                var length = cryptoStream.Read(decryptedBytes, 0, decryptedBytes.Length);

                var decryptedText = Encoding.UTF8.GetString(decryptedBytes.Take(length).ToArray());

                Console.WriteLine(&quot;Decrypted Text ({0} bytes): &quot;, decryptedText.Length);
                Console.Write(decryptedText);
                Console.WriteLine();
            }
        }
    }
}</pre>
<h3>Sample Output</h3>
<pre>Password (21 bytes):
uB3rAw3$omeP@assw0rd!

Plain Text (355 bytes):
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi rutrum pulvinar p
urus, nec ornare neque cursus id. Nunc non tortor est. Morbi laoreet commodo tel
lus, et suscipit neque elementum eu. Sed velit lorem, ultricies id varius vitae,
 eleifend eget massa. Curabitur dignissim eleifend quam, sit amet interdum velit
 rutrum vel. Nulla nec enim tortor.

Salt (256 bytes):
EA0wFLH3/VvAjh72dGmzd9taoFkPFymo5jKjONW5sozvPaHSuNFJdRE46pG7oc8JrvFIxfsyoNl+FSD9
iSM+jkVLLCpUB5Dr+JczPh9ZQIeLcFdk9mSP1hlekQhZOJu+Hs4+AGvkQNtxWTjlHZsQBU/uiSoDBAaB
4UyVKpv2ziHUePvWA+A9+pQLQ9YPYNQYYo+thfPOVAZMPejkPkIaBjEZBIeKVfLTN2339FJwWfVCz28H
edurTTVmuhysreMnSGWSuhijYkdNloOY4dam7pAg2sJhPAJonZ8UiBQ0VmPjNJsWclidaR/JB9reLPXz
AVoZgpVbcIJ3ntXzmYyIpg==

Initilization Vector (16 bytes):
JDkX+NZLCjW1IXaV8qHmFA==

Derived Key (32 bytes):
JJN8Ms4s4On7sSHpDGm+TZkEbJPUhV2WJ2RxhWUpjus=

Encrypted Text (368 bytes):
7invqU61t5YP6R5ZzLo80jhEUBDAnu3MT/PoRgPc0plM+XyTH/vVNy9Vs6wwaamBPRhW0i6mWHrs2UxV
M65DuBFB3WLGyUfPEuJO2q37NWhWshkozMnY/fRM6reKQbVv8r5fLNPaDpf/JrJnRQfbK573yIBLOAN6
1xNUkXRH0xamUBMV1M4orQ1aa/6Z00ziHKTNKilsDJ9S5AwP5qMpYk9clnQd6UgSPEC+w1vv58Ca7Zkf
6KTXTnUGWIDK0mmJIU0/vJeeijPrcvgo1IJj2CCJfMLXhrmCCX4VZw5ahMZr+3d2YzYO6qfpoaMFIoJn
h52Qs0KzgYaNR1tUIHrqGJPAEiBabtW8NnmsnzTRdZtrGpTe+aZddztpXyqNhsqxsxmvxHNPKjWIxAAx
SWRyFQsWVs9uvCadS8dus3og5pU10HxfGL8WNGVtzy+hJ30bROJ73DyukxWtlX1kzeUc7lOUCh8kZKkG
KOArExGY2JY=

Decrypted Text (355 bytes):
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi rutrum pulvinar p
urus, nec ornare neque cursus id. Nunc non tortor est. Morbi laoreet commodo tel
lus, et suscipit neque elementum eu. Sed velit lorem, ultricies id varius vitae,
 eleifend eget massa. Curabitur dignissim eleifend quam, sit amet interdum velit
 rutrum vel. Nulla nec enim tortor.</pre>
<p>That concludes my epic tour de AES in .NET. It&#8217;s like writing papers in college all over again. Hope somebody finds it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/27/more-than-you-ever-wanted-to-know-about-aes-crypto-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PhoneGap to Access Native iPad APIs</title>
		<link>http://blogs.interknowlogy.com/2012/04/25/phonegap-to-access-native-apis/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/25/phonegap-to-access-native-apis/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 00:37:13 +0000</pubDate>
		<dc:creator>Dan Hanan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[#phonegap]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3137</guid>
		<description><![CDATA[I’m working on a project that required an iPad “application”, which we ended up writing as an HTML site that is accessed in Safari.  Later, that same app had a requirement to access the camera roll on an iPad.  Thanks to Chris Rudy here at IK for introducing us to PhoneGap – a way to [...]]]></description>
			<content:encoded><![CDATA[<p>I’m working on a project that required an iPad “application”, which we ended up writing as an HTML site that is accessed in Safari.  Later, that same app had a requirement to access the camera roll on an iPad.  Thanks to <a href="http://blogs.interknowlogy.com/author/chrisrudy/" target="_blank">Chris Rudy</a> here at IK for introducing us to PhoneGap – a way to wrap your HTML web page(s) in a framework that is then compiled into a native application for the OS you’re targeting (iPad, Android, WinPhone7, etc).  Chris blogged about it <a href="http://blogs.interknowlogy.com/2012/02/26/how-to-use-phonegap-api/" target="_blank">here</a> and <a href="http://blogs.interknowlogy.com/2012/02/29/how-to-use-phonegap-api-ios-android/" target="_blank">here</a>.</p>
<h2>Unexpected Error</h2>
<p>The PhoneGap framework exposes a handful of <a href="http://docs.phonegap.com/en/1.6.1/index.html" target="_blank">APIs</a> to access the native hardware on the device (such as camera, accelerometer, compass, contacts, etc).  This all sounded great.  I sat down to write the code, following the examples in the API docs.  I could access the camera roll no problem – the user is shown the photos, they choose one, and you wake up in an event handler in your code.  Next I would try to post that image to a simple REST API running on my Windows machine. No matter what I did, I would get an “Unexpected Error” from the post.  I tried the PhoneGap FileTransfer API and then some more low level AJAX post methods.  All resulted in errors.</p>
<p>I let the code sit for a week until the next <a href="http://blogs.interknowlogy.com/2010/11/10/what-is-recess/" target="_blank">RECESS</a>, when I dug a little deeper.  I finally found that I was running into a <a href="https://issues.apache.org/jira/browse/CB-496" target="_blank">KNOWN BUG</a> in the Camera API, and that it was fixed and released THAT DAY.  So now with <a href="http://phonegap.com/download" target="_blank">PhoneGap version 1.6.1</a>, the Camera.getPicture( ) method will properly return the BYTES of the image chosen from the camera roll instead of the URL to the local file.  These base64-encoded bytes are obviously what I want to post to my web server.  The code as posted everywhere around the web now works fine (notice I gave up on the FileTransfer object and just post the bytes using AJAX):</p>
<pre class="brush: jscript; gutter: true; highlight: [6]; title: ; notranslate">
function browseCameraRoll()
{
	navigator.camera.getPicture( onPhotoLoadSuccess, onFail,
		{
		quality: 50,
		destinationType: Camera.DestinationType.DATA_URL,
		sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
		encodingType: Camera.EncodingType.PNG,
		} );
}

function onPhotoLoadSuccess( imageData )
{
	var url = 'http://myserver.com/UploadImage2';
	var params = { base64Image: imageData };

	$.ajax({
		   type: &quot;POST&quot;,
		   url: url,
		   data: params,
		   success: function (returndata)
		   {
			//alert( 'back from POST: ' + returndata.Status );
			grayscaleImage.src = &quot;data:image/png;base64,&quot; + returndata.GrayscaleVersion
		   }} );
}
</pre>
<h2>File Access APIs</h2>
<p>Today I continued by learning the file access APIs.  I simply want to write a configuration file in isolated storage the first time the application runs, and then read it on each subsequent startup.  This is super simple, and from what I can tell, does not even require using PhoneGap.  The HTML5 File System APIs can be used to read and write files, create directories, etc. <a href="http://www.html5rocks.com/en/tutorials/file/filesystem/" target="_blank">Here is a good write-up</a> on the available APIs.  I thought since the FileWriter and FileReader objects are listed in Cordova’s PhoneGap API documentation, that I was getting an instance of the file through the HTML5 APIs, and then using PhoneGap APIs to read and write the file.  This doesn’t seem to be the case.  FileWriter and FileReader are HTML5 APIs.  Still a bit confused on why Cordova claims them as theirs (assuming just for the convenience of having all the docs in one place).</p>
<p>In any case, file access was a piece of cake – just followed the <a href="http://docs.phonegap.com/en/1.6.1/cordova_file_file.md.html#FileWriter_full_example" target="_blank">example here</a>.</p>
<p><P>&nbsp;</P><br />
<P>&nbsp;</P></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/25/phonegap-to-access-native-apis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP Simplified: Wireframes and Information Map</title>
		<link>http://blogs.interknowlogy.com/2012/04/18/wp-simplified-wireframes-and-information-map/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/18/wp-simplified-wireframes-and-information-map/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 23:33:48 +0000</pubDate>
		<dc:creator>Danny Warren</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Windows Phone 7.5]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3124</guid>
		<description><![CDATA[In architecture a blueprint must exist before a house or office complex can be built. Without the blueprint there would be mass confusion and little if anything would ever happen. The final product would be disaster. The same concept applies to software especially on the phone. If you just start coding the resulting app would [...]]]></description>
			<content:encoded><![CDATA[<p>In architecture a blueprint must exist before a house or office complex can be built. Without the blueprint there would be mass confusion and little if anything would ever happen. The final product would be disaster. The same concept applies to software especially on the phone. If you just start coding the resulting app would struggle to be coherent or usable to the consumer. In order to prevent this we need some kind of software blueprint to help the developer stay focused and deliver what is desired and intended. Over the last 3 years here at InterKnowlogy I’ve come across a variety of ways to represent the flow and design of an application. I have gone from paper to whiteboards to Visio to combinations of all of the above and more. What I’ve discovered is the digital formats take too long to accomplish anything so they are more of a final design asset rather than the means to get to the desired result. Whiteboards are my preferred medium for sketching wireframes and information flow. Microsoft has one of the coolest examples of wireframes participating in the flow of information called an <a href="http://msdn.microsoft.com/en-us/library/hh202895(v=vs.92).aspx" target="_blank">Information Map</a>. The <a href="http://i.msdn.microsoft.com/dynimg/IC505433.png" target="_blank">example image</a> on the aforementioned site is not the highest quality, but it demonstrates the intended purpose.</p>
<h2>Information Map</h2>
<p>As I mentioned earlier I don’t like going to a digital medium because I feel it takes too long to make it worth while. But I am a huge fan of the whiteboard so I’m including am image of the information map of LionHeart that I created on a whiteboard. Thus, digitizing my whiteboard information map. It’s not beautiful but it conveys the idea clear enough that I feel little to no need to rework it using Visio or some other pretty digital designer.</p>
<p><a href="http://blogs.interknowlogy.com/2012/04/18/wp-simplified-wireframes-and-information-map/lionheart-infomap/" rel="attachment wp-att-3127"><img src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/LionHeart-Infomap-225x300.jpg" alt="" title="LionHeart Infomap" width="225" height="300" class="alignnone size-medium wp-image-3127" /></a></p>
<p>There are just a few important items to mention here. First, the Windows Phone platform has some strict navigation rules namely the back button always goes back to the previous page. There are times this rule can be ignored such as when going to a settings screen and selecting save. Hitting the back button after selecting save should not return to the settings screen in most cases. Essentially any screen that is treated more like a modal dialog should not be returned to via the back button. These cases should be called out in the information map. Second, certain UI aspects should be called out such as multi-select lists, pivot or panorama control, or other controls using none intuitive interactions (based on a static drawing). Finally, remember that these information maps only take the UI aspect of the application into account. Do show the layout to some of your colleges or potential consumers and make sure the flow of the app cuts down on as many touches as possible to accomplish what is important. Once the information map is complete then it’s time to move on to the project structure and start coding!</p>
<h2>Code Architecture</h2>
<p>This is an entire different beast. I will not be covering this topic now. Perhaps at a future time. Admittedly, code architecture is one of those religious wars that I absolutely LOVE to discuss. For now I will only say that after you have an information map completed decide on what models exist and what VMs exist. Remember if commands will be used for buttons such as with the <a href="http://blogs.interknowlogy.com/2012/02/22/bindable-application-bar-attached-property-windows-phone-7/" target="_blank">BindableApplicationBar</a> that VMs should be used. Also, take into account if you will be using IsolatedStorage or the local application database. LionHeart is designed around IsolatedStorage for purpose of its demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/18/wp-simplified-wireframes-and-information-map/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Monotouch and iOS Storyboard limitations</title>
		<link>http://blogs.interknowlogy.com/2012/04/18/monotouch-and-ios-storyboard-limitations/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/18/monotouch-and-ios-storyboard-limitations/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 21:34:25 +0000</pubDate>
		<dc:creator>Bret Faller</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3119</guid>
		<description><![CDATA[Recently I&#8217;ve been doing MonoTouch research for iOS development.  While doing so I ran into a limitation when using MonoTouch and the new iOS Storyboards.  What I&#8217;ve found is that in general, MonoTouch and Storyboards play along really well together.  However, I found they only play nicely if you don&#8217;t need to create any custom [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been doing MonoTouch research for iOS development.  While doing so I ran into a limitation when using MonoTouch and the new iOS Storyboards.  What I&#8217;ve found is that in general, MonoTouch and Storyboards play along really well together.  However, I found they only play nicely if you don&#8217;t need to create any custom controls that manage ViewControllers and navigation.  If you are just creating a simple application that has very straightforward navigation and uses only the standard iOS controls or subclassed controls, Storyboards are the way to go.  If you decide that you want custom controls that manage ViewControllers and want finer control over navigation, Storyboards are not for you.  What brought this about was I decided I wanted a neat UITabBar that would have an action button in the middle (similar to Instagram and other photo sharing applications).  I quickly realized this isn&#8217;t possible by subclassing the UITabBar without a lot of hackish techniques.  I decided I was going to create my own UITabBar.  In order to do this I needed to create a custom view to act as the tab bar and to manage the active ViewController.  This meant instantiating and managing the ViewControllers in code.  Now here is where Storyboards fail.  The problem I ran into was that the code generated by MonoTouch for my ViewControllers did not contain the proper constructors/bindings needed to instantiate them from code nor could I wire them up myself.  MonoTouch had generated some code to bind the ViewControllers&#8217; classes to the Storyboard but it doesn&#8217;t allow access to it.  Now, sure, I know I could create a method to open the xib and search for the resource to bind to but that seems nasty to me and kludgy.  I wanted nice clean binding between my code behind and my xibs.  I found that the way to have clean bindings and be able to dynamically instantiate and manage ViewControllers from code was to keep them separate in their independent xibs.  Going this route allowed me  to use those ViewControllers in both ways, via code and via Interface Builder.  In short, if you plan on using MonoTouch to create an app that needs to be able to instantiate and show ViewControllers via code, do not use Storyboards.  Otherwise, go for it because Storyboards really simplify navigation and also give you an overview of your application flow.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/18/monotouch-and-ios-storyboard-limitations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simplifying the Windows Phone development experience! Codename: LionHeart</title>
		<link>http://blogs.interknowlogy.com/2012/04/11/simplifying-the-windows-phone-development-experience-codename-lionheart/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/11/simplifying-the-windows-phone-development-experience-codename-lionheart/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 23:56:58 +0000</pubDate>
		<dc:creator>Danny Warren</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows Phone 7.5]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3114</guid>
		<description><![CDATA[Each time you start a new project one of the first things most of us developers do is pull in code we want to reuse. If we don’t have any existing code then we try to figure out how to leverage concepts and theories from past experiences and platforms. The latter is exactly what we [...]]]></description>
			<content:encoded><![CDATA[<p>Each time you start a new project one of the first things most of us developers do is pull in code we want to reuse. If we don’t have any existing code then we try to figure out how to leverage concepts and theories from past experiences and platforms. The latter is exactly what we did during the development of my last project, a Windows Phone project. We have a ton of XAML and MVVM experience here at Interknowlogy, and a few of us had done small RECESS phone apps. None of us had done a full blown app from scratch on the phone before, but today I can say we did an awesome job! What I want to focus on are the lessons we learned from that project and how to apply them to future phone projects to help simplify the process. My coworker <a href="http://blogs.interknowlogy.com/author/taskins/" target="_blank">Tim Askins</a> and I spent a few RECESS discussing what we could improve on and and what we thought went well. The result is what I call LionHeart.</p>
<h2>Introduction to LionHeart</h2>
<p>LionHeart is a demo phone app that I am working on that is applying the code lessons learned. These lessons include application lifecycle, navigation, tombstoning, MVVM on the phone, how to provide mock data vs. real data, styling, and many more. The project it self is a demo based on work my wife does as a Behavior Interventionist (BI) for children with autism. We got talking about what could potentially simplify her line of work as well as provide a compelling demo app for the phone. The resulting app will allow for BIs to create reports that are currently done on paper, then transferred to another paper and placed in a binder, then that binder is driven to the main office once a month, and then driven back to the client’s home where BIs go when then work with the children. Wow, that was a mouth full. The app will also allow BIs to view their schedule of sessions for the day/week/month/etc. from within the application. The schedule will also be integrated into the normal phone calendar from Windows Live as well. Individual client information will also be available including previous reports, charts showing progress, and whether there will be a supervisor attending the session as well. Sound like a full blown app? I’m really excited to bring this app to life. I just wish it wasn’t just a demo app.</p>
<h2>Components of LionHeart</h2>
<p>Let’s remind ourselves again that the reason we are am creating LionHeart is to help solidify patterns and practices on the phone that will help simplify and speed up the development process of future phone apps. Since there are so many components to LionHeart I wanted to give a brief overview of what I think some of those components will be over the next few weeks.</p>
<h4>Framework Components</h4>
<ul>
<li><a href="http://blogs.interknowlogy.com/2012/04/18/wp-simplified-wireframes-and-information-map/" target="_blank">Wireframes and Information Map</a>
<li><a href="http://blogs.interknowlogy.com/2012/04/30/wp-simplified-coreapplicationservice-lifecycle/" target="_blank">CoreApplicationService (Application Lifecycle)</a>
<li>CoreApplicationService (Navigation)
<li>CoreApplicationService (Tombstoning)
<li>PageViewModel (Initialization)
<li>PageViewModel and Integrating CoreApplicationService
<li>ViewBase and Integrating with PageViewBase
<li>DataProviders for Real vs. Mock Data </li>
</ul>
<h4>Application Components</h4>
<ul>
<li>HomeVM
<li>Navigating to Pages with a Pivot Control and to a Specific PivotItem
<li>Calendar Integration
<li>Styling </li>
</ul>
<p>With that said as I complete each post I’ll update the list with links.</p>
<h2>Final Thoughts</h2>
<p>When all is said and done these components should provide a solid foundation for developing on the Windows Phone platform. If you have any questions or thoughts about how to improve on our design please let me know. Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/11/simplifying-the-windows-phone-development-experience-codename-lionheart/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to create a WinRT WRL C++ Component from scratch that can be consumed by .NET components</title>
		<link>http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 23:52:39 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3003</guid>
		<description><![CDATA[If you have to develop Hybrid WinRT Components that expose both COM and WinRT components you have to either write bare metal C++ or use the new Windows Runtime Template Library, which supports you in dealing with COM. More about WRL can be found at http://msdn.microsoft.com/en-us/library/hh438466(v=vs.110).aspx Microsoft provided a few sample WRL C++ Projects. However they did [...]]]></description>
			<content:encoded><![CDATA[<p>If you have to develop Hybrid WinRT Components that expose both COM and WinRT components you have to either write bare metal C++ or use the new Windows Runtime Template Library, which supports you in dealing with COM. More about WRL can be found at <a href="http://msdn.microsoft.com/en-us/library/hh438466(v=vs.110).aspx">http://msdn.microsoft.com/en-us/library/hh438466(v=vs.110).aspx</a></p>
<p>Microsoft provided a few sample WRL C++ Projects. However they did not include a WRL C++ Project Template in the Visual Studio 2011 Consumer Preview. I reverse-engineered the Sample Projects to find out what is necessary in order to develop a WRL Component from scratch as I didn&#8217;t want to use the available Sample Projects as my Project foundation. I also modified the Project in a way that the resulting DLL contains not only the COM component itself but also the proxy/stub implementation.</p>
<p>These are the steps I came up with:</p>
<ol>
<li>Create a new &#8220;Visual Studio C++ &#8211; Windows Metro Style &#8211; WinRT Component DLL&#8221; Project. I called it &#8220;WRLTemplate&#8221;.<br />
(Please make sure that the solution folder does not contain any white spaces.)<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/1/" rel="attachment wp-att-3004"><img class="alignnone size-full wp-image-3004" title="1" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/1.png" alt="" width="400"/></a></li>
<li>Delete the automatically created WinRTComponent.cpp/h files.<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/2/" rel="attachment wp-att-3009"><br />
<img class="alignnone  wp-image-3009" title="Delete WinRTComponent files" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/2.png" alt="" width="161" height="156" /></a></li>
<li>Add Module-Definition File &#8220;WRLTemplate.def&#8221;<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/3/" rel="attachment wp-att-3014"><img class="alignnone size-full wp-image-3014" title="Module Definition File" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/3.png" alt="" width="400" /></a></p>
<p>Set the content to the following, describing all exported methods of the DLL</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
EXPORTS
DllCanUnloadNow         PRIVATE
DllGetActivationFactory PRIVATE
DllGetClassObject       PRIVATE
</pre>
</li>
<li>Add the MIDL File “WRLTemplate.idl”. The content will be added later, when we define the modules&#8217; functionality.<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/5/" rel="attachment wp-att-3016"><img class="alignnone size-full wp-image-3016" title="Midle File" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/5.png" alt="" width="400" /></a></li>
<li>Open the Project Settings from the Solution Exporer and adjust the following settings</li>
<li>C/C++ General Tab<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/6/" rel="attachment wp-att-3019"><img class="alignnone size-full wp-image-3019" title="C/C++ General Tab" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/6.png" alt="" width="400" /></a>&nbsp;</li>
<ul>
<li><strong>Additional Include Directories:</strong> $(IntermediateOutputPath);$(ProjectDir);$(OutDir);%(AdditionalIncludeDirectories)
</li>
<li><strong>Consume Windows Runtime Extension: </strong>No</li>
</ul>
<li>C/C++ Preprocessor Tab<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/8/" rel="attachment wp-att-3022"><img class="alignnone size-full wp-image-3022" title="08_C/C++ Preprocessor" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/8.png" alt="" width="400"/></a><br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/9/" rel="attachment wp-att-3023"><img class="alignnone size-medium wp-image-3023" title="09_Preprocessor Definitions" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/9-300x197.png" alt="" width="300" height="197" /></a></p>
<ul>
<li><strong>Preprocessor Definitions:<br />
</strong>
<pre class="brush: csharp; gutter: false; title: ; notranslate">ENTRY_PREFIX=Prx;REGISTER_PROXY_DLL;PROXY_CLSID_IS={ 0x24352b56, 0xa2ea, 0x4327, { 0xba, 0xcb, 0xe9, 0xea, 0x33, 0x8d, 0xb3, 0x9d } };_WINRT_DLL;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</pre>
<p>Those are mainly necessary for the Proxy/Stub, which will be part of the same component. ENTRY_PREFIX defines the Prefix of the generated exported DLL entry methods of the Proxy/Stub and is necessary to avoid naming conflicts</li>
</ul>
</li>
<li>Linker &#8211; Input Tab.<br />
Add rpcrt4.lib as an Additional Dependency<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/10-2/" rel="attachment wp-att-3024"><img class="alignnone size-full wp-image-3024" title="10_Linker Input" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/10.png" alt="" width="400" /></a></li>
<li>MIDL General Tab<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/11/" rel="attachment wp-att-3025"><img class="alignnone size-full wp-image-3025" title="11_MIDL_General" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/11.png" alt="" width="400" /></a>
<ul>
<li><strong>Additional Include Directories:</strong> $(LibraryWPath);$(ProjectDir);%(AdditionalIncludeDirectories)</li>
<li><strong>Additional Metadata Directories:</strong> $(LibraryWPath);%(AdditionalMedataDirectories)</li>
</ul>
</li>
<li>MIDL Output Tab<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/12/" rel="attachment wp-att-3026"><img class="alignnone size-full wp-image-3026" title="12_MIDL_Output" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/12.png" alt="" width="400"  /></a>
<ul>
<li><strong>Metadata File:</strong>$(OutDir)%(Filename).winmd</li>
<li><strong>Header File:</strong>%(Filename).h</li>
<li><strong>IID File:</strong>%(Filename)_i.c</li>
<li><strong>Proxy File:</strong>%(Filename)_p.c</li>
</ul>
</li>
<li>MIDL Command Line<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/13/" rel="attachment wp-att-3027"><img class="alignnone size-full wp-image-3027" title="13_MIDL_CommandLine" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/13.png" alt="" width="400"  /></a>
<ul>
<li><strong>Additional Options:</strong> /ns_prefix<br />
This will add the “ABI” Prefix to the generated namespaces in the proxy/stub files.</li>
</ul>
</li>
<li>Custom Build Step General Tab<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/14/" rel="attachment wp-att-3028"><img class="alignnone size-full wp-image-3028" title="14_Custom Build Step" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/14.png" alt="" width="400" /></a><br/><a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/15/" rel="attachment wp-att-3029"><img class="alignnone size-full wp-image-3029" title="15_Command Line" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/15.png" alt="" width="400"  /></a>
<ul>
<li><strong>Command Line: </strong>mdmerge -partial -i &#8220;$(OutDir).&#8221; -o &#8220;$(OutDir)Output&#8221; -metadata_dir &#8220;$(WindowsSDK_MetadataPath)&#8221; &amp;&amp; copy /y $(OutDir)Output\* $(OutDir)</li>
<li><strong>Outputs: </strong>$(OutDir)%(TargetName).winmd</li>
<li><strong>Execute After:</strong> Midl</li>
</ul>
</li>
<li>Add common includes to the generated pch.h file
<pre class="brush: cpp; gutter: false; title: ; notranslate">
#pragma once

#include &lt;SDKDDKVer.h&gt;

#define WIN32_LEAN_AND_MEAN

//Windows Header Files:
#include &lt;windows.h&gt;
#include &lt;assert.h&gt;
#include &lt;tchar.h&gt;
#include &lt;Strsafe.h&gt;

//WRL
#include &lt;wrl\client.h&gt;
#include &lt;wrl\implements.h&gt;
#include &lt;wrl\ftm.h&gt;
#include &lt;wrl\event.h&gt;
#include &lt;wrl\wrappers\corewrappers.h&gt;
#include &lt;wrl\module.h&gt;
</pre>
</li>
<li>Set the WRLTemplate.idl content, which describes what functionality your Component will expose
<pre class="brush: cpp; gutter: false; title: ; notranslate">
import &quot;Windows.Foundation.idl&quot;;

#include &lt;sdkddkver.h&gt;

namespace WRLTemplate
{
	runtimeclass MyComponent;

	[version(NTDDI_WIN8), uuid(9789F754-FF6E-4AB5-9868-C1430D294A1B)]
	interface IMyCallbackProvider : IInspectable
	{
		HRESULT Call([in] HSTRING callbackValue);
	}

	[version(NTDDI_WIN8), uuid(1589F754-FF6E-4AB5-9868-C1430D294A1B), exclusiveto(MyComponent)]
	interface IMyComponent : IInspectable
	{
		HRESULT Foo([in] HSTRING someString, [in]IMyCallbackProvider* myCallback);
	}

	[version(NTDDI_WIN8), activatable(NTDDI_WIN8)]
	runtimeclass MyComponent
	{
		[default] interface IMyComponent;
	}
}
</pre>
</li>
<li>Add MyComponent.h
<pre class="brush: cpp; gutter: false; title: ; notranslate">
#include &quot;pch.h&quot;
#include &quot;WRLTemplate.h&quot; //Generated by the MIDL compiler

using namespace Microsoft::WRL;
using namespace ABI::WRLTemplate;

namespace WRLTemplate
{
	class DECLSPEC_UUID(&quot;A23CF192-F869-4DFE-9477-4045A73CA2AB&quot;) MyComponent :
		public RuntimeClass&lt;
			// WRL
			RuntimeClassFlags&lt;RuntimeClassType::WinRtClassicComMix&gt;,
			FtmBase	,
			// Custom
			IMyComponent&gt;
	{
		InspectableClass(RuntimeClass_WRLTemplate_MyComponent, TrustLevel::BaseTrust);

	public:
		// IMyComponent
		IFACEMETHOD (Foo)(HSTRING someString, IMyCallbackProvider* myCallback);
	};
}
</pre>
</li>
<li>Add MyComponent.cpp
<pre class="brush: cpp; gutter: false; title: ; notranslate">
#include &quot;pch.h&quot;
#include &quot;MyComponent.h&quot;

namespace WRLTemplate
{
	IFACEMETHODIMP MyComponent::Foo (HSTRING someString, IMyCallbackProvider* myCallback)
	{
		myCallback-&gt;Call(someString);

		return S_OK;
	}
}
</pre>
</li>
<li>Add WRLTemplate.cpp
<pre class="brush: cpp; gutter: false; title: ; notranslate">
#include &quot;pch.h&quot;
#include &quot;MyComponent.h&quot;

// COM proxy/stubs
extern &quot;C&quot; HRESULT WINAPI PrxDllGetClassObject(REFCLSID, REFIID, _Deref_out_ LPVOID*);
extern &quot;C&quot; BOOL WINAPI PrxDllMain(_In_opt_ HINSTANCE, DWORD, _In_opt_ LPVOID);
extern &quot;C&quot; HRESULT WINAPI PrxDllCanUnloadNow();

BOOL WINAPI DllMain( __in_opt HINSTANCE hInstance, __in DWORD dwReason, __in_opt LPVOID lpReserved )
{
    if( DLL_PROCESS_ATTACH == dwReason )
    {

        //
        //  Don't need per-thread callbacks
        //
        DisableThreadLibraryCalls( hInstance );

        Microsoft::WRL::Module&lt;Microsoft::WRL::InProc&gt;::GetModule().Create();
    }
    else if( DLL_PROCESS_DETACH == dwReason )
    {
        Microsoft::WRL::Module&lt;Microsoft::WRL::InProc&gt;::GetModule().Terminate();
    }

    PrxDllMain( hInstance, dwReason, lpReserved );

    return TRUE;
}

STDAPI DllGetActivationFactory(_In_ HSTRING activatibleClassId, _COM_Outptr_ IActivationFactory** factory)
{
    auto &amp;module = Microsoft::WRL::Module&lt;Microsoft::WRL::InProc&gt;::GetModule();
    return module.GetActivationFactory(activatibleClassId, factory);
}

STDAPI DllCanUnloadNow()
{
    auto &amp;module = Microsoft::WRL::Module&lt;Microsoft::WRL::InProc&gt;::GetModule();
    return module.Terminate() ? S_OK : S_FALSE;
}

STDAPI DllGetClassObject( __in REFCLSID rclsid, __in REFIID riid, __deref_out LPVOID FAR* ppv )
{
    auto &amp;module = Microsoft::WRL::Module&lt;Microsoft::WRL::InProc&gt;::GetModule();
    HRESULT hr = module.GetClassObject( rclsid, riid, ppv );
    if (FAILED(hr))
    {
        hr = PrxDllGetClassObject( rclsid, riid, ppv );
    }
    return hr;
}

namespace WRLTemplate {
	ActivatableClass(MyComponent)
}
</pre>
</li>
<li>Try to compile. It will fail.</li>
<li>Add the Proxy Stub files to the solution: Select “Show all files” in the Solution explorer and include dlldata.c + WRLTemplate_i.c, WRLTemplate_p.c to the solution<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/17/" rel="attachment wp-att-3031"><img class="alignnone size-full wp-image-3031" title="17_ProxyStubs" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/17.png" alt="" width="150" /></a></li>
<li>Deactivate the usage of Precompiled Headers on these 3 files by going to their properties (right click and select Properties) and changing the <strong>Precompiled Header</strong> to <strong><strong>Not Using Precompiled Headers</strong></strong><br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/18/" rel="attachment wp-att-3032"><img class="alignnone size-full wp-image-3032" title="18_PCH" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/18.png" alt="" width="400"  /></a></li>
<li>Recompile – should work fine. Now use the Component from a C# project</li>
<li>Create a new C# project<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/19/" rel="attachment wp-att-3033"><img class="alignnone size-full wp-image-3033" title="19_BlankApp" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/19.png" alt="" width="400" /><br />
</a></li>
<li>Add Reference to the winmd file. Make sure you do NOT select WRLTemplate.winmd from the Output folder. Although they are binary equal you will get an exception at runtime, telling you that the Type is not registered.<br />
<a href="http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/attachment/20/" rel="attachment wp-att-3020"><img class="alignnone size-full wp-image-3020" title="20_Add Reference" src="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/20.png" alt="" width="400" /></a></li>
<li>Instantiate the COM component and use it for example in your BlanPages&#8217; OnNavigatedTo-Method
<pre class="brush: csharp; gutter: false; title: ; notranslate">
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var comp = new MyComponent();
            var callback = new Callback();

            const string testString = &quot;Test&quot;;
            comp.Foo(testString, callback);

            Debug.Assert(callback.ReceivedValue == testString);
        }

        class Callback : IMyCallbackProvider
        {
            public string ReceivedValue { get; set; }

            public void Call(string callbackValue)
            {
                ReceivedValue = callbackValue;
            }
        }
</pre>
</li>
<li> If you followed all steps correctly, the solution should compile and work as expected <img src='http://blogs.interknowlogy.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
</ol>
<p>If you have specific questions regarding any of these settings please post a comment and I will get back to you.<br />
I attached the example solution (<a href='http://blogs.interknowlogy.com/wp-content/uploads/2012/04/WRLTemplate.zip'>WRLTemplate</a>). Please note that you will have to compile the project &#8220;WRLTemplate&#8221; and again reference its WRLTemplate.winmd afterwards in the ConsumerApp project.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/11/how-to-create-a-winrt-wrl-c-component-from-scratch-that-can-be-consumed-by-net-components/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Presentation Materials for New England Code Camp 17</title>
		<link>http://blogs.interknowlogy.com/2012/04/01/presentation-materials-for-new-england-code-camp-17/</link>
		<comments>http://blogs.interknowlogy.com/2012/04/01/presentation-materials-for-new-england-code-camp-17/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 15:15:00 +0000</pubDate>
		<dc:creator>John Bowen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Async]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Visual Studio 11]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=3000</guid>
		<description><![CDATA[Thanks to everyone for coming! What&#8217;s new in Visual Studio 11: Slides &#124; CodeCheck the slides for the list of all of the new Visual Studio features we looked at. Easy Async in .NET 4.5: Slides &#124; Code (for VS11 Beta)The only code demo we didn&#8217;t get to look at can be found in the [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to everyone for coming!</p>
<p>What&#8217;s new in Visual Studio 11: <a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/VS11NewFeatures.zip" target="_blank">Slides</a> | <a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/VsFeatures.zip" target="_blank">Code</a><br />Check the slides for the list of all of the new Visual Studio features we looked at.</p>
<p>Easy Async in .NET 4.5: <a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/AsyncVS11.zip" target="_blank">Slides</a> | <a href="http://blogs.interknowlogy.com/wp-content/uploads/2012/04/AsyncDemos.zip" target="_blank">Code</a> (for VS11 Beta)<br />The only code demo we didn&#8217;t get to look at can be found in the AddingAsync page, which shows a progression of converting a more complex 2 step data loading process from fully synchronous to fully asynchronous including cancellation and exception handling.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/04/01/presentation-materials-for-new-england-code-camp-17/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to REALLY consume a WinRT object with the WRL</title>
		<link>http://blogs.interknowlogy.com/2012/03/28/how-to-really-consume-a-winrt-object-with-the-wrl/</link>
		<comments>http://blogs.interknowlogy.com/2012/03/28/how-to-really-consume-a-winrt-object-with-the-wrl/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 23:35:32 +0000</pubDate>
		<dc:creator>Kevin Stumpf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.interknowlogy.com/?p=2980</guid>
		<description><![CDATA[Microsoft published an example that supposedly demonstrates how to consume a WinRT object with the WRL at How to Create and Consume an Object. However, if you&#8217;ve tried that example you probably noticed that it simply does not work as the following snippet returns E_INVALIDARG. The problem is, that HString::MakeReference(RuntimeClass_Windows_Foundation_Uri) does not return a valid [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft published an example that supposedly demonstrates how to consume a WinRT object with the WRL at <a href="http://msdn.microsoft.com/en-us/library/hh700149(v=vs.110).aspx">How to Create and Consume an Object</a>.</p>
<p>However, if you&#8217;ve tried that example you probably noticed that it simply does not work as the following snippet returns <code>E_INVALIDARG</code>.</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
ComPtr&lt;IActivationFactory&gt; uriActivationFactory;
HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Uri).Get(), &amp;uriActivationFactory);
</pre>
<p>The problem is, that <code>HString::MakeReference(RuntimeClass_Windows_Foundation_Uri)</code> does not return a valid <em>HStringReference</em>-instance.</p>
<p>Instead, you should create a <em>HStringReference</em>-object using its constructor and pass that instance to the <em>GetActivationFactory </em>call:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
ComPtr&lt;IActivationFactory&gt; uriActivationFactory;
HStringReference runtimeClassUri(RuntimeClass_Windows_Foundation_Uri);
HRESULT hr = GetActivationFactory(runtimeClassUri.Get(), &amp;uriActivationFactory);
</pre>
<p>Now, the call should return <code>S_OK</code> and you&#8217;ll have a valid <code>uriActivationFactory</code> that you can work with.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.interknowlogy.com/2012/03/28/how-to-really-consume-a-winrt-object-with-the-wrl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

