Software:Active Template Library
| Developer(s) | Microsoft |
|---|---|
| Written in | C++ |
| Operating system | Microsoft Windows |
| Type | Library or framework |
| License | Proprietary |
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.[13] The most commonly used classes include:
CComPtr<T>[14] general-purpose smart-pointer,CComBSTR[15] BSTR wrapper,CComVariant[16] VARIANT wrapper, andCComSafeArray<T>[17] SAFEARRAY wrapper.[18]
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.[19]
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.[20]
CComSafeArray
The CComSafeArray<T> class template is a wrapper class for the COM SAFEARRAY type, designed to ease handling of safe arrays.[21] 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.[22]
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.[23] 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.[23]
Compiler COM support
Although not formally part of ATL, MSVC also includes additional C++ RAII classes to simplify management of COM types.[24] These compiler COM support classes can be used as replacement for or in combination with ATL, and includes:
_com_ptr_t[25] smart-pointer that decorates the COM interface name with a "Ptr" suffix,_bstr_t[26] BSTR wrapper,_variant_t[27] VARIANT wrapper, and_com_error[28] HRESULT wrapper.
Note that as of Visual Studio 2012, the compiler COM support classes does not include a SAFEARRAY wrapper.
See also
- ATL Server
- C++/CX
- OLE Automation
- Standard Template Library
- Windows Template Library
- Microsoft Windows SDK
- List of C++ template libraries
References
Citations
- ↑ 1.0 1.1 Grimes, Richard (1998). "ATL and COM". ATL COM (1st ed.). Wrox Press. ISBN 1-86100-249-1. https://archive.org/details/atlcomprogrammer00grim.
- ↑ Grimes, Richard (1999). "Building and calling a COM object using ATL". Beginning ATL 3 COM Programming (1st ed.). Wrox Press. p. 63. ISBN 978-1-86100-120-7. https://archive.org/details/beginningatl3com00grim/page/63.
- ↑ Williams, Mickey (2000). "Active Documents". Visual C++ 6 Unleashed (1st ed.). Sams. p. 733. ISBN 978-0-672-31241-0.
- ↑ Whitney, Tyler (2016-11-04). "Recommendations for Choosing Between ATL and MFC". Microsoft Learn. Microsoft. https://learn.microsoft.com/en-us/cpp/atl/recommendations-for-choosing-between-atl-and-mfc.
- ↑ Howard, Michael (2008-01-29). "New NX APIs added to Windows Vista SP1, Windows XP SP3 and Windows Server 2008". Michael Howard's Web Log. Microsoft. https://learn.microsoft.com/en-us/archive/blogs/michael_howard/new-nx-apis-added-to-windows-vista-sp1-windows-xp-sp3-and-windows-server-2008.
- ↑ swiat (June 12, 2009). "Understanding DEP as a mitigation technology part 1". MSRC Blog. Microsoft Security Response Center. https://www.microsoft.com/en-us/msrc/blog/2009/06/understanding-dep-as-a-mitigation-technology-part-1/.
- ↑ "Applications Using Older ATL Components May Experience Conflicts with DEP". Microsoft Support. Microsoft. January 29, 2008. http://support.microsoft.com/kb/948468.
- ↑ Bridge, Karl (2021-02-02). "UpdateProcThreadAttribute function (Processthreadsapi.h)". Microsoft Learn. Microsoft. https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute.
- ↑ "ATL Security Update". MSDN. Microsoft. 2009-07-28. http://msdn.microsoft.com/en-us/visualc/ee309358.aspx.
- ↑ "ATL and MFC changes and fixes in Visual Studio 2013". 20 August 2013. http://blogs.msdn.com/b/vcblog/archive/2013/08/20/atl-and-mfc-changes-and-fixes-in-visual-studio-2013.aspx.
- ↑ "ATL and MFC changes and fixes in Visual Studio 2013". 20 August 2013. https://devblogs.microsoft.com/cppblog/atl-and-mfc-changes-and-fixes-in-visual-studio-2013/.
- ↑ Whitney, Tyler; Sharkey, Kent; nxtn; Blome, Mike; Hogenson, Gordon; Cai, Saisang (2016-11-04). "ATL Text Encoding Functions". Microsoft Learn. Microsoft. https://learn.microsoft.com/en-us/cpp/atl/reference/atl-text-encoding-functions?view=msvc-170#atlgetversion.
- ↑ Tavares et al. (2007), p. 99.
- ↑ Microsoft MSDN: CComPtr Class
- ↑ Microsoft MSDN: CComBSTR Class
- ↑ Microsoft MSDN: CComVariant Class
- ↑ Microsoft MSDN: CComSafeArray Class
- ↑ Fertitta, Kirk (September 2005). "Navigating the landscape of IVI". International Automatic Testing Conference. Orlando: IEEE. doi:10.1109/AUTEST.2005.1609236. ISBN 0-7803-9101-2.
- ↑ Grimes (1998), p. 321.
- ↑ Whitney, T.; Laroche, N.; Sharkey, K.; Parente, J.; drvoss; mikeblome; Jones, M.; Hogenson, G. et al. (2019-11-19). "How to: Create and use CComPtr and CComQIPtr instances". Microsoft Learn. Microsoft. https://learn.microsoft.com/en-us/cpp/cpp/how-to-create-and-use-ccomptr-and-ccomqiptr-instances.
- ↑ DiLascia, Paul (August 2003). "C++ Q&A: Finding a Win32 Handle, HTML in CHtmlCtrl". MSDN Magazine (Microsoft) 18 (10). ISSN 1528-4859. https://learn.microsoft.com/en-us/archive/msdn-magazine/2003/august/c-q-a-finding-a-win32-handle-html-in-chtmlctrl.
- ↑ Tavares et al. (2007), ch. 3.
- ↑ 23.0 23.1 Dicanio, Giovanni (March 2017). "Simplify Safe Array Programming in C++ with CComSafeArray". MSDN Magazine (Microsoft) 32 (3). Template:QID. ISSN 1528-4859. https://learn.microsoft.com/en-us/archive/msdn-magazine/2017/march/c-simplify-safe-array-programming-in-c-with-ccomsafearray.
- ↑ Troelsen (2000), pp. 166–170.
- ↑ Microsoft MSDN: _com_ptr_t Class
- ↑ Microsoft MSDN: _bstr_t Class
- ↑ Microsoft MSDN: _variant_t Class
- ↑ Microsoft MSDN: _com_error Class
Bibliography
- Grimes, Richard (1998). ATL COM: Programmer's Reference (1st ed.). Wrox Press. ISBN 978-1-86100-249-5. https://archive.org/details/atlcomprogrammer00grim.
- Grimes, Richard (1999). Beginning ATL 3 COM Programming (1st ed.). Wrox Press. ISBN 978-1-86100-120-7. https://archive.org/details/beginningatl3com00grim.
- Tavares, C.; Fertitta, K.; Rector, B.; Sells, C. (2007). ATL Internals: Working with ATL 8 (2nd ed.). Addison–Wesley. ISBN 0-321-15962-4. http://www.informit.com/title/9780321159625.
- Troelsen, Andrew W. (2000). Developer's Workshop to COM and ATL 3.0. Texas: Wordware. ISBN 978-1-55622-704-2. https://archive.org/details/developersworksh00andr.
- Williams, Mickey (2000). Visual C++ 6 Unleashed (1st ed.). Sams. ISBN 978-0-672-31241-0. https://archive.org/details/visualc6unleashe0000will.
Further reading
External links
