January 2017

Volume 32 Number 1

[Editor's Note]

Outside In: How Kenny Kerr Brought C++/WinRT to Microsoft

By Michael Desmond | January 2017

Michael DesmondC++ developers hoping to get in on the action with the Windows Runtime (WinRT) have faced a high barrier to entry. Either work with the Windows Runtime C++ Template Library (WRL) originally developed to bootstrap internal development of APIs by Microsoft, or turn to Microsoft’s C++ Component Extensions (C++/CX) to streamline access to WRL capabilities, at the cost of having to learn a new dialect of C++.

Kenny Kerr, a longtime C++ columnist at MSDN Magazine and now an engineer on the Windows team at Microsoft, believed there had to be a better way. He started work early in 2014 on a Windows Runtime projection for standard C++ that would make the language a first-class citizen in the WinRT space.

“I had some previous experience projecting COM APIs into modern C++, so I decided to see whether I could apply those same techniques to the Windows Runtime,” Kerr says. “I was invited to Redmond on two different occasions and it certainly seemed as if they were warming up to the idea. Finally, I was offered a job and joined the Windows team to complete the project with their help.”

The result of that effort is C++/WinRT, a standard C++ language projection for WinRT that is implemented entirely in header files and enables developers to both consume and author Windows Runtime APIs using any standards compliant C++ compiler. This is exciting stuff, and Kerr explores it all in detail in his feature article this month, “Introducing C++/WinRT.”

Kerr explains that there are really two parts to C++/WinRT—the base library and projection that can be downloaded from GitHub (URL), and the cppwinrt.exe compiler that bridges the gap between standard C++ and WinRT. While most of the effort to date has focused on the library and projection, Kerr says the cppwinrt compiler deserves attention. “Developers really need to get their hands on this tool as it solves a lot of problems, from generating projections for different platforms or components, to playing a key role in developing WinRT components entirely with C++/WinRT.”

One of the biggest challenges Kerr faced in developing C++/WinRT was managing the trade-offs that WinRT makes to support projections for JavaScript and managed .NET languages out of the box. He singles out the complexity in how generic collections work across language projections.

“One of the biggest challenges I faced early on was coming up with an efficient way for standard C++ to handle WinRT’s interface-versioning model. I mention this briefly in this month’s article, but I don’t touch on how those ‘required’ interfaces are actually aggregated together at compile time in C++,” Kerr says. “It really pushed my understanding of C++ at that time and has since pushed the Visual C++ compiler to more efficiently handle such techniques at this scale.”

Microsoft for years has been emphasizing openness and cross-­platform support in its dev tools (see my Editor’s Note column in the recent MSDN Magazine Connect(); special issue at msdn.com/magazine/mt790179). The C++/WinRT project is a great example of these values at work, as Microsoft welcomes the best efforts of the community in an effort to improve its platforms. Still, the question begs: How does a guy outside of Microsoft end up creating vital tooling for a mainline Microsoft programming language? Kerr says it comes down to fresh eyes.

“There are a lot of very experienced C++ developers at Microsoft who have spent decades-long careers working with C++ and COM,” Kerr says. “I think it took someone who didn’t realize that it was impossible to just try it anyway and show that it works.”

Michael Desmond is the Editor-in-Chief of MSDN Magazine.

Discuss this article in the MSDN Magazine forum