ATL introduction

xiaoxiao2021-03-06  39

1. What is ATL?

Since Microsoft has announced the first COM technology in 1993, the development model on the Windows platform has undergone tremendous changes, and the WINDOWS programming is brought into the component chemical era in the development model of the WINDOWS platform. The majority of developers are extremely inconvenient for the difficulty and cumbersome details of COM development techniques. COM programming is seen as a highly uncomfortable technology, which is expected. Developers hope to have a convenient and fast COM development tool to improve development efficiency and better utilize this technology. In this case, Microsoft has launched the COM SDK, in order to simplify COM programming, improve development efficiency, and have adopted many programs, especially in the Microsoft Foundation Class, add support for COM and OLE. However, with the development of the Internet, distributed component technology requires COM components to be transmitted on the network, and we will save valuable network bandwidth resources. The COM component developed by MFC is not well met, so Microsoft has introduced a new COM development tool ATL in 1995.

ATL is an abbreviation of ActiveX Template Library, which is a set of C template libraries. Using ATL quickly develops efficient, concise code (Effective and Slim Code), while providing maximum code automatic generation and visual support for the development of COM components. For convenience, starting from the Microsoft Visual C 5.0 version, Microsoft integrates ATL into the Visual C development environment. The Visual Studio 6.0 introduced in September 1998 integrates ATL 3.0. At present, ATL has become an important member of Microsoft standard development tools, increasingly attached importance to C developers.

What benefits have ATL bring to developers? This will also start from ATL to the previous COM development method.

Before ATL generated, there are two ways to develop COM components: First, use COM SDK to directly develop COM components, and another way is achieved by COM support provided by MFC. It is the most flexible way to develop COM components directly using COM SDK. By using Microsoft, we can write COM programs directly. However, this difficulty and workload of this development method are very large. On the one hand, the developer is required to have a more in-depth understanding of the technology principles of COM (although the deep understanding of the technology itself is very beneficial to the use of any kind of tool. However, for a complete set of complex technologies such as COM, it is very difficult to master in a short time), on the other hand, directly using the COM SDK to request the developers to realize every detail of the COM application, complete a lot of repetition Sexual work. The result of this is that not only the work efficiency is reduced, but also makes developers have to put many energy into technical details that are not related to the application needs itself. Although this development method is necessary for some special applications, this programming method does not meet the reusability of the component chemical design method, so it is not an ideal development method that the COM SDK is used directly.

The COM support from the MFC is used to develop COM applications that the automation is improved on the basis of using the COM SDK, and the development time is shortened. MFC uses object-oriented ways to encapsulate COM's basic functionality in a C class of several MFCs, developers get COM support functions by inheriting these classes. In order to facilitate the various features of the COM object, there are many predefined macros in the MFC. These macros are functional to implement the definition of the COM interface and the functionality of the object's registration and the like to be used in the COM object. Developers can use these macros to customize the characteristics of COM objects. In addition, support for Automation and ActiveX Control, Visual C also provides corresponding AppWizard and ClassWizard support for these two aspects, which is more convenient for COM applications.

MFC's support for COM and OLE is indeed more advanced than manual writing COM programs. However, the support of MFC is not perfect and thorough, such as the IDL language defined by the COM interface, and the MFC does not support, and there is no flexible support for the new development of COM and ActiveX technology in recent years. This is determined by the basic starting point designed by the MFC. The MFC is designed to develop the object-oriented package developed by the Windows platform. It naturally needs to involve Windows programming, COM is also supported by the MFC as a part of the programming development of Windows platform, but the support of MFC is based on its global target The starting point, so support for COM must obey its global goal. In this respect, MFC's support for COM can meet the requirements of developers.

With the development of Internet technology, Microsoft has vigorously promoted ActiveX technology as an important part of its network strategy, but uses MFC developed ActiveX Control, the code redundancy is large (so-called "fertilizer code fat code"), and must Depending on the MFC's runtime library to run correctly. Although the MFC's runtime library is only related to COM, the ActiveX Control must carry the heavy burden of running moments due to the essence of MFC's inheritance. If you use a static connection MFC running time library, this will make the ActiveX Control code too large, which will occupy a valuable network bandwidth resource when transferring on the network; if you use a dynamically connected MFC running time library, this will ask the browser one side. Must have MFC's runtime library support. In short, MFC is also very flexible in the environment of COM technology.

Solving the problem in the above COM development method is the basic goal of ATL.

First, the basic goal of ATL is to make COM application as much as possible, this basic goal determines that ATL is only supported for COM development. The goal clearly enables ATL to support COM technology. Any link and procedure for COM development, ATL is supported and integrated with many tools related to COM development into a unified programming environment. ATL provides comprehensive Wizard support for the various applications of COM / ActiveX. All of this greatly facilitates the use of developers, enabling developers to focus on logically related to the application itself.

Secondly, ATLs have used their specific basic implementation techniques to get rid of a large amount of redundant code, and the code of the COM application developed using ATL is concise, that is, the so-called "Slim Code". The ATL is implemented as much as possible, even in the inside of its internal C / C development, the alternative portion of the C startup code must have. At the same time, the code generated by the ATL does not need to rely on the huge code module that is required by the MFC program, which is included in the final module is the user's considered to be the most basic and most. These measures enable the COM components developed by ATL (including ActiveX Control) to implement application distributed component structures in a network environment. Third, the various versions of ATL have good support for Microsoft's Based on COM-based components such as MTS, ASP, etc., ATLs are much faster than the new technology. ATL has become a major development tool for Microsoft support COM application, so the new progress in COM technology will be reflected in ATL in a short period of time. This allows developers to use ATL for COM programming to get the same flexibility and powerful features directly using COM SDK programming.

The purpose of this paper is that it is desirable to make readers in a limited space to have a preliminary understanding of the use and basic principles of ATL. For the majority of COM developers to better use ATL development to throw jade. Two. ATL basic technology

Although developing COM applications using ATL is a very simple thing, but there is a complex technique behind an easy-to-use interface of ATL. In the face of a large number of code generated by ATL, we can develop COM applications even if we don't understand the meaning of these codes, but if we have to fully explore the potential of ATL, develop more flexible, powerful COM applications, must The basic techniques used by ATL have aware of the basic techniques. Studying the essence of ATL is the ATL source code provided by Visual C . This part of this article is only a brief introduction to the most basic technologies used in ATL.

Simply put, the basic technologies used in the ATL include the following aspects:

COM Technology C Template Technology (Template)

C multi-inheritance (Multi-inheritance)

COM technology is the basis of understanding ATL, using ATL development to have a minimum understanding of the basic concept of COM technology. Since COM is a very complex and huge technical system, it is limited to the parameters of this article, and details will not be described here. For the COM basic concepts mentioned herein, do not do too much, please refer to the reference books.

The template for the most core implementation technology of ATL is an extension of standard C language, but in most C programming environments, people rarely use it, because the template's function is very strong, but its internal mechanism is more complicated. It is necessary to use more C knowledge and experience to be flexible. The function classes such as COBJECTARRAY in the MFC are defined by templates. Fully pass the template to define the overall class structure of the program, ATL is the most successful.

The so-called template class is simply related to the abstraction of the class. We know that the C language class defines the way constructor (herein the C object instead of the COM object), the object is an instance of the class, and the template class defines the construction of the class, which is generated using the template class definition. It is different. Therefore, it can be said that the template class is "class".

The definition format of the template class in the C language is as follows:

Template

Class myTemp

{

MyTemp () {};

~ MyTemp () {};

Int Myfunc (INT A);

}

..........

INT MyTemp :: MyFunc (INT A)

{

}

First use the C keyword "template" to declare a template class definition. Behind the keyword is the type parameters enclosed with a sharp bracket. It is based on this type of parameters, and the compiler can convert the specific definition of the template class into a definition of the actual class in the compilation process, which generates a new class. The next definition method is very similar to the ordinary class definition, just with a description of the type parameters in the function definition of the class. The following block illustrates the usage of the template class:

Typedef mytemp myclassfromtemp;

MyclassFromTemp M;

INT a = m.myfunc (10);

Usually, when using the template class, use a keyword "typedef" to take a name for the newly defined class. In the above block, "MyClass" is assumed by the user-defined class, by passing the name of this class as the type parameter to the template class, we can create a new class, this class's behavior will be defined by template class Based, for example, it has all member functions defined by template class, and this class is another modification of template behavior, which is implemented by the type parameters provided by the user. The template class is given by different types of parameters, and a set of classifications of behavioral frames is similar but specific behavior. With new classes, we can create a class instance, namely a new object, and call the member functions of this object.

The template class is the latest extension of the standard C language. Although its function is very powerful, you need to use the template class to require considerable language and programming experience and knowledge, and incorrectly use the template class and the structure of the program. And the operational efficiency brings great side effects, so a general programming environment and programming books take a cautious attitude towards the use of template classes. The core of ATL is made up of dozens of template classes. By studying the source code of ATL, we can make our use of template classes a more comprehensive understanding.

Multi-inheritance technology is the same as template, which is a very controversial technology in the C language. Using multi-inheritance technology can make the program's design and achieve more flexible, but due to multi-inheritance complexity and some problems on their own concept, it is very limited in the support of various object-oriented locale. For example, Small Talk does not allow multiple inheritance, and the same MFC does not support multi-inheritance technology.

Most inheritance is the so-called "diamond structure". For example, the following code:

Class A

{

.....

}

Class B: Public A

{

..

}

Class C: Public a

{

.....

}

Class D: Public C, B

{

........

}

Since class D is inherited from class C and B, ambiguity will occur in the following statement:

D * pd = new d;

(A *) PD-> func (...);

Since class D inherits class A by class C and class B, the forced conversion here will be ambiguous.

ATL uses two operational symbols added in C 's latest specifications STICAST, DYNAMIC_CAST instead of simple forced transformation, eliminating the ambiguity of multi-inheritance. With these two arithmetic symbols, we can get the type information of the object during the object operation. The above code can be modified in the following manner:

D * pd = new d;

Static_cast (static_cast (pd)) -> func (...);

Why is the template class and multi-inheritance technology become the main tools of ATL? The reason is that the template can quickly generate a class with a user-customized function during the compilation process, which is greatly improved for COM's complex technical system. By using template classes, users can focus on the basic logic of their own class, after completing their own class, by inheriting different classes, generating different template classes, can quickly implement COM functionality At the same time avoid a large number of functional redundancy caused by a single inheritance structure. In summary, it is because the template class and multi-inheritance technology is used in the design implementation, and ATL has become a small and flexible COM development tool, which can adapt to the various needs of developers to develop developers.


New Post(0)