Microsoft C++/WinRT
Written by Mike James   
Wednesday, 26 October 2016

Microsoft has had a problem about how to make Universal Windows Apps easy to create from C++. The initial approach was to modify the language but this has now been dropped in favour of adding a library to standard C++. 

Microsoft really can't make up its mind how best to do things. Once upon a time we had bold initiatives like .NET that were viewed by many as a revolution but eventually it all turned out well. Recently however there have been far too many retreats from positions that seemed immutable. So it is with C++/CX.

 

cppwinrt

 

When WinRT was introduced with Windows 8 some way was needed to allow C++ programmers to create what we then called Metro apps. These morphed into Windows Store apps and we now call them Universal Windows Apps (UWA) - despite the fact that they only run on Windows 10. Languages like C# could have the extra libraries added without any major changes, but C++ is a language that is more varied in the environments it runs in and it is standardized.

However this didn't stop Microsoft modifying C++ as supported in Visual Studio to create C++/CX:

"Visual C++ component extensions (C++/CX) is a set of extensions to the C++ language that enable the creation of Windows apps and Windows Runtime components in an idiom that is as close as possible to modern C++. Use C++/CX to write Windows apps and components in native code that easily interact with Visual C#, Visual Basic, and JavaScript, and other languages that support the Windows Runtime. In those rare cases that require direct access to the raw COM interfaces, or non-exceptional code, you can use the Windows Runtime C++ Template Library (WRL)."


Quite a few C++ programmers took exception to the phrase "as close as possible to modern C++". Now it seems that CX is out and C++ is back in. C++/WinRT is a library that allow UWAs to be written using perfectly standard C++.

As the Modern C++ for the Windows Runtime blog post puts it:

"C++/WinRT is the future of the Modern project and the first public preview coming officially from Microsoft."

In other words, forget C++/CX and start using this instead.

The GitHub Read Me explains:

"C++/WinRT is a standard C++ language projection for the Windows Runtime implemented solely in header files. It allows you to both author and consume Windows Runtime APIs using any standards-compliant C++ compiler."

What isn't made clear anywhere is why Microsoft, and more importantly us, wasted time on C++/CX. The new release is much improved:

"Significant improvements have been made to virtually all parts of the base library including the metaprogramming facilities, string and error handling. We’ve also added support for various missing features include arrays, collections, and weak references. Delegates are now more efficient and it’s possible to implement any WinRT interface within the projection. This update also includes our complete async programming model based on coroutines."

All good news, but there is still a small shock to be had in the statement of future direction:

"We’re now switching gears to focus on Xaml and component support among other things. "

The other languages using WinRT take Xaml support for-granted; not so C++. 

The library is open source under an MIT licence. At the moment there seems to be very activity on the C++WinRT front. If you search on Google for "how-to" articles you mostly find C++/CX results.

What does this mean?

It could be that there aren't many C++ programmers interested in creating WinRT apps.

Overall moving to standard C++ has to be a good idea, but why did we have to take the detour?

cppwinrticon

More Information

C++/WinRT Available on GitHub

https://github.com/Microsoft/cppwinrt

Related Articles

C++ Going Native - Inside C+/CX design 

GoingNative 2012 - The Videos 

Building and using C++ WinRT components

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin

 

Banner


NVIDIA Releases Free Courses On AI
19/04/2024

NVIDIA has jumped on the AI bandwagon in a big way. Hardware aside, this means working on training material too. Several self- paced courses have been released and for free too!



Interact With Virtual Historic Computers
14/04/2024

Alan Turing's ACE computer is a legendary computer that is particularly special for I Programmer - our account of it was the first ever history article on the site when it launched in 2009. Now this i [ ... ]


More News

 

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Wednesday, 26 October 2016 )