What are C++/CX and C++/CLI, and how do they relate to C++ and WinRT?

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?

1

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.

2

Citing https://devblogs.microsoft.com/cppblog/ccx-part-0-of-n-an-introduction/:

. . . 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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật