C++/CX
C++/CX (or C++ Component Extensions) is a language projection for Microsoft's Windows Runtime platform.
≈ 3 min read
C++/CX. encyclopegia.org, snapshot enwiki-001370446943. /a/c-cx
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
C++/CX (or C++ Component Extensions) is a language projection for Microsoft's Windows Runtime platform. It takes the form of a language extension for C++ compilers, and it enables C++ programmers to write programs that call Windows Runtime (WinRT) APIs.
C++/CX is superseded by the C++/WinRT language projection, which is not an extension to the C++ language; rather, it is an entirely standard modern ISO C++17 header file-based library. The language extensions borrow syntax from C++/CLI but target the Windows Runtime Universal Windows Platform native code instead of the Common Language Runtime and managed code.
It brings a set of syntax and library abstractions that project COM's WRL subset-based WinRT programming model in a way that is intuitive to C++/CLI managed extensions' coders. It is possible to call the Windows Runtime from native ISO C++ via the lower level Windows Runtime C++ Template Library (WRL). However, WRL is also superseded by C++/WinRT.
WinRT objects are created, or activated, using ref new and assigned to variables declared with the ^ (hat) notation inherited from C++/CLI. Foo^ foo = ref new Foo(); A WinRT variable is simply a pair of a pointer to virtual method table and pointer to the object's internal data. There are special kinds of runtime classes that may contain component extension constructs.
These are simply referred to as ref classes because they are declared using ref class . public ref class MyClass { }; A file that is generated and updated by the GUI-designer, and thus should not be modified by the programmer. Note the keyword partial . // Foo.private.h pragma once using Platform::String; partial ref class Foo { private: int id; String^ name; }; The file where the programmer writes user-interface logic.
The header in which the compiler-generated part of the class is defined is imported. Note that the keyword partial is not necessary. // Foo.public.h pragma once include "Foo.private.h" using Platform::String; ref class Foo { public: int getId(); String^ getName(); }; This is the file in which the members of the partial class are implemented. // Foo.cpp include "pch.h" include "Foo.public.h" using Platform::String; int Foo::getId() { return id; } String^ Foo::getName() { return name; } generic public ref class Bag { property T Item; }; ifdef __cplusplus_winrt // C++/CX specific code goes here... endif
References
Visual C++ Language Reference (C++/CX)
Text derived from https://en.wikipedia.org/w/index.php?oldid=1370446943 under CC BY-SA 4.0; modifications have been made.