Jump to content

Active Template Library

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Forderud (talk | contribs) at 19:19, 6 April 2013 (History). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Active Template Library
Developer(s)Microsoft
Written inC++
Operating systemMicrosoft Windows
TypeLibrary or framework
LicenseProprietary

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++ allows developers to create a variety of COM objects, OLE Automation servers, and ActiveX controls.[1][2] ATL includes an object wizard that sets up primary structure of the objects very quickly with a minimum of hand coding. On the COM client side ATL provides smart pointers that deal with COM reference counting.

History

COM objects can also be created with Microsoft Foundation Classes (MFC). However, usage of MFC in general leads to larger binaries that require support DLLs.[3] ATL does not require any support DLLs, and is therefore a more lightweight alternative in situations where not graphical user interface is required.

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 remote code execution security flaw.[4]

Support classes

ATL includes many RAII classes to simplify management of COM types. The most commonly used classes include:

  • CComPtr<T>[5] general-purpose smart-pointer,
  • CComBSTR[6] BSTR wrapper,
  • CComVariant[7] VARIANT wrapper, and
  • CComSafeArray<T>[8] SAFEARRAY wrapper.

Compiler COM support

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

  • _com_ptr_t[9] smart-pointer that decorates the COM interface name with a "Ptr" suffix,
  • _bstr_t[10] BSTR wrapper,
  • _variant_t[11] VARIANT wrapper, and
  • _com_error[12] HRESULT wrapper.

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

See also

References

  1. ^ Grimes, Richard (1998). "ATL and COM". ATL COM (1st edition ed.). Wrox Press. p. 6. ISBN 1-86100-249-1. {{cite book}}: |edition= has extra text (help)
  2. ^ Grimes, Richard (1999). "Building and calling a COM object using ATL". Beginning ATL 3 COM Programming (1st edition ed.). Wrox Press. p. 63. ISBN 978-1-86100-120-7. {{cite book}}: |edition= has extra text (help)
  3. ^ Williams, Mickey (2000). "Active Documents". Visual C++ 6 Unleashed (1st edition ed.). Sams. p. 733. ISBN 978-0-672-31241-0. {{cite book}}: |edition= has extra text (help)
  4. ^ "ATL Security Update". MSDN. Microsoft. 2009-07-28. Retrieved 2011-09-19.
  5. ^ Microsoft MSDN: CComPtr Class
  6. ^ Microsoft MSDN: CComBSTR Class
  7. ^ Microsoft MSDN: CComVariant Class
  8. ^ Microsoft MSDN: CComSafeArray Class
  9. ^ Microsoft MSDN: _com_ptr_t Class
  10. ^ Microsoft MSDN: _bstr_t Class
  11. ^ Microsoft MSDN: _variant_t Class
  12. ^ Microsoft MSDN: _com_error Class