Active Template Library

Revision as of 13:23, 22 January 2025 by 147.161.132.173 (talk)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

{{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | 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 upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main otherTemplate: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++ allows developers to create a variety of COM objects, OLE Automation servers, and ActiveX controls.<ref>Template:Cite book</ref><ref>Template:Cite book</ref> ATL includes an object wizard that sets up primary structure of the objects quickly with a minimum of hand coding. 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.

HistoryEdit

COM objects can also be created with Microsoft Foundation Classes (MFC), but this leads to larger binaries that require support DLLs.<ref>Template:Cite book</ref> ATL, on the other hand, is a more lightweight alternative in situations where the graphical user interface parts of MFC are not required.<ref>Microsoft MSDN: Recommendations for Choosing Between ATL and MFC</ref>

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.<ref>http://web.archive.org/web/20080130115007/http://blogs.msdn.com/michael_howard/archive/2008/01/29/new-nx-apis-added-to-windows-vista-sp1-windows-xp-sp3-and-windows-server-2008.aspx</ref><ref>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</ref><ref>https://msrc.microsoft.com/blog/2009/06/understanding-dep-as-a-mitigation-technology-part-1/</ref> This problem can be mitigated with DEP-ATL thunk emulation with performance penalty.<ref>http://web.archive.org/web/20090123222148/http://support.microsoft.com/kb/948468</ref><ref>https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute</ref>

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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Since Visual Studio 2013 (ATL version 12), all ATL code is static, eliminating the DLL.<ref>http://web.archive.org/web/20130827013146/http://blogs.msdn.com/b/vcblog/archive/2013/08/20/atl-and-mfc-changes-and-fixes-in-visual-studio-2013.aspx</ref><ref>https://devblogs.microsoft.com/cppblog/atl-and-mfc-changes-and-fixes-in-visual-studio-2013/</ref>

ATL version is defined by ATL_VER macros and can be queried via AtlGetVersion() function.<ref>https://learn.microsoft.com/en-us/cpp/atl/reference/atl-text-encoding-functions?view=msvc-170#atlgetversion</ref>

Support classesEdit

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

Compiler COM supportEdit

Although 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<ref>Microsoft MSDN: _com_ptr_t Class</ref> smart-pointer that decorates the COM interface name with a "Ptr" suffix,
  • _bstr_t<ref>Microsoft MSDN: _bstr_t Class</ref> BSTR wrapper,
  • _variant_t<ref>Microsoft MSDN: _variant_t Class</ref> VARIANT wrapper, and
  • _com_error<ref>Microsoft MSDN: _com_error Class</ref> HRESULT wrapper.

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

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Authority control