Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was considering taking up the challenge of learning C++ for designing Metro apps and that's when I came across C++/CX.

Can Metro apps be coded in C++ 11? Do they require C++/CX to work? And what exactly is C++/CX? Is it possible to create a Metro app using only C++, or is C++/CX required? Also, how does C++/CLI tie into this picture?

share|improve this question

2 Answers 2

Microsoft used to simply make a C++ system that let you access their Windows API (called win32), then one day they invented .NET and figured everything had to change.

So they created "Managed Extensions for C++" which was basically C++ but with a load of non-standard extensions, adding keywords like __gc to support .NET features (like allocating on the GC heap rather than the native one)

But people didn't like this as it really wasn;t C++, having all those extra keywords, so Microsoft redesigned it and called it C++/CLI, which had a much smaller set of additional keywords but introduced syntax changes like the ^ (which is a reference 'pointer' to a .NET object on the GC heap).

A few years later and Microsoft has realised .NET isn't the silver bullet they said it was, and they also merged their in-fighting Windows and Developer teams. Part of this re-evaluation led to the creation of a brand new Windows API, called WinRT, that is entirely native code and this meant the old extensions were no longer useful, so Microsoft developed their C++ extensions to one that made working with the new WinRT API easier - by keeping a few extensions from C++/CLI (such as the ^).

So - there you go, 3 different versions of an extended C++ that is superficially C++. At least the latest version is native code again, so you don't need to use the extensions if you don't want to as you can directly access the API (it's called WRL and is a lot like the old ATL template classes)

If you think you might be coding cross-platform code you won't want to - you can change the API calls, but you cannot use the ^ on any compiler other than Visual C++. I'd recommend using the WRL API and keeping your code as standard as possible given the 'extra code' you'd need to write compared to C++/CX isn't so great.

share|improve this answer

Citing http://blogs.msdn.com/b/vcblog/archive/2012/08/29/cxxcxpart00anintroduction.aspx:

. . . while C++/CX is syntactically similar to C++/CLI and thus looks almost the same in many ways, it is semantically quite different. C++/CX code is native code, no CLR required. Programming in C++/CLI can be very challenging, as one must deftly juggle two very different object models at the same time: the C++ object model with its deterministic object lifetimes, and the garbage-collected CLI object model. C++/CX is much simpler to work with, because the Windows Runtime, which is based on COM, maps very well to the C++ programming language.

Windows Runtime defines a relatively simple, low-level Application Binary Interface (ABI), and mandates that components define their types using a common metadata format. C++/CX is not strictly required to write a native Windows Runtime component: it is quite possible to write Windows Runtime components using C++ without using the C++/CX language extensions, and Visual C++ 2012 includes a library, the Windows Runtime C++ Template Library (WRL), to help make this easier. Many of the Windows Runtime components that ship as part of Windows (in the Windows namespace) are written using WRL. There's no magic in C++/CX: it just makes writing Windows Runtime components in C++ much, much simpler and helps to cut the amount of repetitive and verbose code that you would have to write when using a library-based solution like WRL.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.