[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
The Windows Runtime platform supports Windows Metro style apps that only execute in a trustworthy operating system environment; use authorized functions, data types, and devices; and are distributed from the Windows Store. Microsoft has provided Visual C++ component extensions (C++/CX) that simplify writing apps for the Windows Runtime platform. This topic serves as a quick reference. For more complete documentation, see Using Windows Runtime Components in Visual C++ and Component Extensions for Runtime Platforms.
When building from the command line, use the new /ZW compiler option to build a Metro style app or Windows Runtime component. To access declarations defined in the Windows Runtime, which are defined in the new Windows Runtime metadata (.winmd) files, specify the #using directive, or the /FU compiler option. When you create a new project for a Metro style app, Visual Studio by default sets these options and adds references to all Windows Runtime libraries.
The following table is a quick reference for Visual C++ support for the Windows Runtime:
|
Concept |
Standard C++ |
C++/CX |
Remarks |
|---|---|---|---|
|
Fundamental types |
C++ fundamental types. |
C++/CX fundamental types that implement fundamental types defined in the Windows Runtime. |
The default namespace contains C++/CX built-in, fundamental types. The compiler implicitly maps C++/CX fundamental types to standard C++ types. The Platform family of namespaces contains types that implement fundamental Windows Runtime types. |
|
bool |
bool |
An 8-bit Boolean value. |
|
|
__wchar_t |
char16 |
A 16-bit nonnumeric value that represents a Unicode (UTF-16) code point. |
|
|
short unsigned short |
int16 uint16 |
A 16-bit signed integer. A 16-bit unsigned integer. |
|
|
int unsigned int |
int uint32 |
A 32-bit signed integer. A 32-bit unsigned integer. |
|
|
long long –or- __int64
unsigned long long |
int64 uint64 |
A 64-bit signed integer. A 64-bit unsigned integer. |
|
|
float, double |
float32, loat64 |
A 32-bit or 64-bit IEEE 754 floating-point number. |
|
|
enum {} |
enum class {} -or- enum struct {} |
A 32-bit enumeration. |
|
|
(Does not apply) |
Platform::Guid |
A 128-bit nonnumeric value (a GUID) in the Platform namespace. |
|
|
(Does not apply) |
Windows::Foundation::DateTime |
A date-time structure. |
|
|
(Does not apply) |
Windows::Foundation::TimeSpan |
A timespan structure. |
|
|
(Does not apply) |
A Windows Runtime type |
A type that is designed to run on the Windows Runtime platform, and whose declaration is contained in a Windows Runtime metadata file. |
|
|
(Does not apply) |
Platform::Object^ |
The reference-counted base object in the Windows Runtime type system. |
|
|
std::wstring L "…" |
Platform::String^ |
Platform::String^ is a reference-counted, immutable, sequence of Unicode characters that represent text. |
|
|
Pointer to… |
Pointer to object (*):
T *identifier |
Handle-to-object (^, pronounced "hat"):
T^ identifier |
All Windows Runtime classes are declared with the handle-to-object modifier. Members of the object are accessed with the arrow (->) class-member-access operator. The hat modifier means "pointer to a Windows Runtime object that is automatically reference counted." More precisely, handle-to-object declares that the compiler should insert code to automatically manage the object's reference count, and delete the object if the reference count goes to zero. |
|
Reference to… |
Reference to an object (&): T & identifier |
Tracking reference (%): T % identifier |
Only Windows Runtime types can be declared with the tracking reference modifier. Members of the object are accessed with the dot (.) class-member-access operator. The tracking reference means "a reference to a Windows Runtime object that is automatically reference counted." More precisely, a tracking reference declares that the compiler should insert code to automatically manage the object's reference count, and delete the object if the reference count goes to zero. |
|
dynamic type declaration |
new |
ref new |
Allocates a Windows Runtime object and then returns a handle to that object. |
|
object lifetime management |
delete identifier delete[] identifier |
(Invokes the destructor.) |
Lifetime is determined by reference counting. A call to delete invokes the destructor but itself does not free memory. |
|
array declaration |
T identifier [] |
Array< T ^>^ identifier ( size ) -or- WriteOnlyArray< T ^>^ identifier ( size ) |
Declares a one-dimensional modifiable or write-only array of type T^. The array itself is also a reference-counted object that must be declared with the handle-to-object modifier. (Array declarations use a template header class that is in the Platform namespace.) |
|
class declaration |
class identifier{} structidentifier{} |
ref classidentifier{} ref structidentifier{} |
Declares a runtime class with default private accessibility. Declares a runtime class with default public accessibility. |
|
structure declaration |
struct identifier {} (i.e., a Plain Old Data structure (POD)) |
value classidentifier{} value structidentifier{} |
Declares a POD struct with default private accessibility. A value class can be represented in Windows metadata, but a standard C++ class cannot. Declares a POD struct with default public accessibility. A value struct can be represented in Windows metadata, but a standard C++ struct cannot. |
|
interface declaration |
(Does not apply) |
interface classidentifier{} interface structidentifier{} |
Declares an interface with default private accessibility. Declares an interface with default public accessibility. |
|
delegate |
(Does not apply) |
public delegate return-type delegate-type-identifier ( [ parameters ] ); |
Declares an object that represents a function pointer. |
|
event |
(Does not apply) |
eventdelegate-type-identifierevent-identifier; delegate-type-identifierdelegate-identifier = ref newdelegate-type-identifier( this[, parameters]); event-identifier+=delegate-identifier;-or-EventRegistrationTokentoken-identifier = obj.event-identifier+=delegate-identifier;-or-autotoken-identifier = obj. event-identifier::add(delegate-identifier); obj.event-identifier-=token-identifier;-or-obj.event-identifier::remove(token-identifier); |
Declares an event object, which is a collection of event handlers (delegates) that are called when an event occurs. Creates an event handler. Adds an event handler.Adding an event handler returns an event token (token-identifier). If you intend to explicitly remove the event handler, you must save the event token for later use. Removes an event handler.To remove an event handler, you must specify the event token that you saved when the event handler was added. |
|
property |
(Does not apply) |
propertyTidentifier; propertyTidentifier[index]; propertyTdefault[index]; |
Declares that a class or object member function is accessed with the same syntax used to access a data member or indexed array element. Declare a property on a class or object member function. Declare an indexed property on an object member function. Declare an indexed property on a class member function. |
|
generics |
(Does not apply) |
generic <typenameT> interface classidentifier{} generic <typenameT> delegate[return-type]delegate-identifier() {} |
Declares a parameterized interface class. Declares a parameterized delegate. |
