Windows Runtime C++ Template Library
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
The Windows Runtime C++ Template Library (WRL) is a COM-based template library that provides a low-level way to use Windows Runtime components.
The Windows Runtime is implemented by using Component Object Model (COM) technology. COM depends on reference-counting to manage the lifetime of objects, and other housekeeping techniques, and on testing HRESULT values to determine whether an operation succeeded or failed. To successfully write a COM app or library, you must carefully follow COM rules and techniques.
The Visual C++ component extensions (C++/CX) is a high-level, language-based way to use Windows Runtime components. Both the WRL and C++/CX simplify the writing of code for the Windows Runtime by automatically performing COM housekeeping tasks on your behalf.
The WRL and C++/CX provide different benefits. Here are some reasons you might want to use the WRL instead of C++/CX:
-
The WRL is a compiler-agnostic way to create and consume Windows Runtime APIs. Even if you don't use the Microsoft compiler, linker, and other development tools, you can use WRL to write apps that use Windows Runtime components, or write custom Windows Runtime components that can be used by others.
-
By using the WRL, you can optimize your code for performance or for specific scenarios. C++/CX doesn't expose the underlying COM technology in the Windows Runtime. However, your app or component might require control of the underlying COM code to better create or consume Windows Runtime APIs. When you use the WRL, you can control critical COM directly, but also allow the WRL to control the remaining COM on your behalf. You have complete command.
-
C++/CX represents COM HRESULT values as exceptions. If you’ve inherited a code base that uses COM, or one that doesn’t use exceptions, you might find that the WRL is a more natural way to work with the Windows Runtime because you don't have to use exceptions.
-
Although C++/CX is easy to use, you might prefer not to use "handle to object (^)", ref new, ref class, and its other language features to write your code. WRL provides an alternative for people who want to use a template library and standard C++ to write Windows Runtime code.
-
The purpose and design of the WRL is inspired by the Active Template Library (ATL), which is a set of template-based C++ classes that simplify the programming of COM objects. If you already know ATL, you might find that WRL programming is easier.