Jump to content

Active Template Library

From Wikipedia, the free encyclopedia

Template:Use American English Template:Use mdy dates

{{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other{{#invoke:Check for conflicting parameters|check | template = Template:Infobox software | cat = Template:Main other | logo size; logo_size | logo class; logo_class | logo alt; logo_alt | logo title; logo_title | logo caption; logo_caption | screenshot size; screenshot_size | screenshot upright; screenshot_upright | screenshot class; screenshot_class | screenshot alt; screenshot_alt | screenshot title; screenshot title | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | programming language; programming_language | operating system; operating_system }}Template:Short description The Active Template Library (ATL) is a set of template-based C++ classes developed by Microsoft, intended to simplify the programming of Component Object Model (COM) objects. The COM support in Microsoft Visual C++ (MSVC) allows developers to create a variety of COM objects, OLE Automation servers, and ActiveX controls.[1][2]

ATL is integrated with software wizards supplied with MSVC that facilitate automatic copy-and-paste programming for basic tasks, such as configuring the library's build options and setting up the primary structure of an ATL object definition. On the COM client side ATL provides smart pointers that deal with COM reference counting. The library makes heavy use of the curiously recurring template pattern and multiple inheritance.[1]

History

COM objects can also be created with Microsoft Foundation Classes (MFC), but this leads to larger binaries that require support DLLs.[3] ATL, on the other hand, is a more lightweight alternative in situations where the graphical user interface parts of MFC are not required.[4]

Older versions of ATL (ATL prior to version 7.1, pre-Visual Studio 2005) are incompatible with DEP because it places executable thunks in data heap.[5][6] This problem can be mitigated with DEP-ATL thunk emulation with performance penalty.[7][8]

In ATL version 7 (Visual Studio 2003), which directly succeeded version 3 (Visual Studio 6.0), a number of MFC classes like CString were made available in ATL, or more precisely moved to an ATLMFC common layer which is shared by both libraries. ATL version 7 also introduced attributes in C++ in an attempt to provide something similar to CLI attributes, however these have not been particularly successful, and have been deemphasized in ATL version 8 (Visual Studio 2005); the various wizards no longer generate them by default. Version 7 also introduced new string conversion classes.

On July 28, 2009, Microsoft released a patch to ATL to fix a bug that could allow ActiveX controls created using ATL to be vulnerable to a security flaw permitting remote code execution.[9]

Since Visual Studio 2013 (ATL version 12), all ATL code is statically linked, eliminating the DLL.[10][11]

ATL version is defined by ATL_VER macros and can be queried via AtlGetVersion() function.[12]

Support classes

ATL includes several wrapper classes that encapsulate COM types in order to simplify programs' usage thereof. These classes provide a façade over the management of runtime COM data structures, along with RAII semantics.Template:Sfnp The most commonly used classes include:

  • CComPtr<T>[13] general-purpose smart-pointer,
  • CComBSTR[14] BSTR wrapper,
  • CComVariant[15] VARIANT wrapper, and
  • CComSafeArray<T>[16] SAFEARRAY wrapper.[17]

CComPtr

The CComPtr class template is a generic smart pointer class that is parameterized on the type of COM interface being wrapped. Instances of this class are initialized using an appropriate COM interface pointer, passed as an argument either to the class constructor or the object's overloaded assignment operator.Template:Sfnp

Instances of the CComPtr class always perform reference counting, and there is no ATL analogue to the single-owner unique_ptr smart pointer class as found in the C++11 standard library. Instead, CComPtr can be used for both single-owner and multiple-owner scenarios.[18]

CComSafeArray

The CComSafeArray<T> class template is a wrapper class for the COM SAFEARRAY type, designed to ease handling of safe arrays.[19] The class is generic, being parameterized on the element type of the safe array, although only a subset of C++ types are supported as such.Template:Sfnp

Because it is a type that encapsulates a growable array, the functionality provided by CComSafeArray<T> overlaps with that of the vector sequence container in the standard template library.[20] While STL vectors are more efficient at dynamic resizing, they do not provide the ABI stability ensured by safe arrays as a COM type, which allow the latter to be transferred across module and programming language boundaries.[20]

Compiler COM support

Although not formally part of ATL, MSVC also includes additional C++ RAII classes to simplify management of COM types.Template:Sfnp These compiler COM support classes can be used as replacement for or in combination with ATL, and includes:

  • _com_ptr_t[21] smart-pointer that decorates the COM interface name with a "Ptr" suffix,
  • _bstr_t[22] BSTR wrapper,
  • _variant_t[23] VARIANT wrapper, and
  • _com_error[24] HRESULT wrapper.

Note that as of Visual Studio 2012, the compiler COM support classes does not include a SAFEARRAY wrapper.

See also

References

Citations

Template:Reflist

Bibliography

Template:Refbegin

Template:Refend

Further reading

Template:Refbegin

Template:Refend

Template:Authority control

  1. ↑ 1.0 1.1 Template:Cite book
  2. ↑ Template:Cite book
  3. ↑ Template:Cite book
  4. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  5. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  6. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  7. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  8. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  9. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  10. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  11. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  12. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  13. ↑ Microsoft MSDN: CComPtr Class
  14. ↑ Microsoft MSDN: CComBSTR Class
  15. ↑ Microsoft MSDN: CComVariant Class
  16. ↑ Microsoft MSDN: CComSafeArray Class
  17. ↑ Template:Cite conference
  18. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  19. ↑ Template:Cite magazine
  20. ↑ 20.0 20.1 Template:Cite magazine
  21. ↑ Microsoft MSDN: _com_ptr_t Class
  22. ↑ Microsoft MSDN: _bstr_t Class
  23. ↑ Microsoft MSDN: _variant_t Class
  24. ↑ Microsoft MSDN: _com_error Class