Nico Vuyge's blog

Taking the blue AND the red pill

Nico Vuyge

Converting a c++ Metro app from the Developer Preview to the Consumer Preview of Windows 8

Nico Vuyge

40 days of Windows 8 Metro and WinRT development: Day 0

As promised previously, the first day (day 0) of my 40 days of Windows 8 development adventure would consist of installing the Consumer Preview of Windows 8, followed by converting a small C++ Metro app that I have been building over the last few months to this latest build.

Installing Windows 8 Consumer Preview.

Yesterday afternoon I was able to download the necessary software immediately after it became available. The downloads of Windows 8 Consumer Preview and Visual Studio 11 Ultimate Beta (from MSDN) finished in only a couple of minutes, at a download rate of 4.5 MB/s (that's 'MegaByte', thank you Telenet and Microsoft!). I was probably early and lucky, because after I had downloaded the 32 bit edition, the download of the 64 bit edition went significantly slower.

I installed the 32-bit edition both on my beta laptop (I don't install beta software on my production laptop, just to make sure beta's don't sabotage my daily work) and on the Windows 8 tablet I received from Microsoft at the Build conference. By the end of the evening, I had 2 working Windows 8 Consumer Preview machines ready for development work today. The installation went fairly smoothly, although there were some minor issues:

  • Installing Windows 8 Consumer Preview from the update tool was much to my surprise successfull (I learned not to do OS upgrades the hard way), and in the end, I didn't need to install from the ISO's I just downloaded. The only issue was that the first time I tried I selected to search for updates during the install. This hung for about 2 hours until I killed the setup. I retried without searching for updates and the install went smoothly.
  • After installation, I needed to install .NET 2.0 via the Control Panel Turn Windows Features On or Off. This should install these components using Windows Update, but I got the error message that I didn't have a connection to the Internet. Which was clearly not correct. After restarting the machine, I could install these components via Windows Update without any problem (Isn't it surprising how many computer problems get solved by rebooting?).
  • The reason for installing the .NET 2.0 components was to be able to run my home written RSS reader application (I hope to release this one day as a Metro App), which uses CardSpaces as authentication mechanism. This is not included on Windows 8, but on the Developer Preview this could be installed by installing the older .NET runtime components. This solution doesn't seem to work anymore on Windows 8 Consumer Preview, so I'll have to figure out what else I have to do to get this functionality back.
  • I haven't been able to download anything from the Windows Store. I always get the very informative message Your purchase couldn't be completed. Something happened and your purchase can't be completed. To be investigated later, today is C++ conversion day.

Converting my C++ app from Developer Preview to Consumer Preview.

The first thing I noticed when I started the conversion was that I had to accept a license for Metro development. Much to my surprise, this Metro Developer License will only last until 31/3/2012! Clearly Microsoft is planning to quickly start requiring formal app developer licenses. That is not a problem for me, give me the registration link ASAP.

There is much more detail in the specific documentation for C++, but you will still want to look for the samples for more elaborate coding samples.

I spent the entire day converting my app. There have been significant changes in WinRT and the C++ support for WinRT between Developer Preview and Consumer Preview. I encountered the following conversion issues:

  • Licensing: ICurrentProduct has been changed to ICurrentApp. Similarly, FeatureLicense has been changed to ProductLicense.
  • Task based parallelism: The (unofficial) ppltasks.preview.h has been replaced with an official implementation in ppltasks.h. I encountered couple of related breaking changes: StorageFileRetrievalOperation is gone, instead there is now a generic variant IAsyncOperation<StorageFile^>. Similarly, the StatusOperation is now replaced with IAsyncAction.
  • Value Converters: The contract for IValueConverter (see one of my previous blogs) has changed slightly. Instead of using plain strings as type names, it now uses the dedicated type Windows::UI::Xaml::Interop::TypeName instead.
  • SettingsPane: This has been changed somewhat. I haven't had the time yet to port my code to the new mechanism.
  • Microsoft Advertising: These ad controls didn't seem to work, but I haven't spent much time investigating this. That is a problem for later.
  • Boxing: The C++ Team has added support for boxing. At first sight, it seems very similar to boxing in C#, and makes all the conversions from Windows Runtime basic types much more cleaner and simpler, just like you would do in C#. No need to deal with IReference anymore.
  • Data binding and DependencyProperties: There was no support at all in the Developer Preview for XAML Data Binding in C++. You had to do everything yourself by building an infrastructure very similar to C# Reflection using ICustomProperty and such. You can see for yourself how painfull this is in an article by Nish Sivakumar on CodeProject. With the new C++ compiler and library support in the Consumer Preview, this boils down to just attributing your databindable class with [Windows::UI::Xaml::Data::Bindable] and the compiler/build system will generate the necessary supporting code behind the scenes. You still need to implement Windows::UI::Xaml::Data::INotifyPropertyChanged on your class and trigger notifications when a property changes, but that is not more than what you would have to do in C# anyway. I considered the amount of work you had to do in the Developer Preview to make a C++ class data bindable in  XAML the biggest disadvantage of C++ compared to C# for developing Metro apps, but that disadvantage is now totally gone.

All in all, this experience was more or less what I hoped for. I had estimated to do this conversion in one day, and indeed it was actually done in one day, even including writing this post. The most important thing for a C++ developer in this Consumer Preview is bringing C++ at the ease of use level of C# for a number of very important mechanisms like async support (task based parallelism), boxing and data binding.

View Nico Vuyge's profile on LinkedIn Nico Vuyge is a freelance software developer in East-Flanders (Belgium), specializing in Microsoft technologies. Nico has fully embraced managed software development in C# after a decade of software development in the unmanaged world in C++.
Apart from his interests in state-of-the-art managed software development, he is also interested in the hardware aspects of informatics, in particular performance and silent computing related aspects. For more details, see our company history , or contact him directly at nicov@iconstructions.be.
Microsoft Tag for Nico Vuyge