Lu Si Wei - Pan Ai People :: ATL Type (2)

zhaozj2021-02-11  196

ATL introduction (2) Pan Love

---- (Connected to the previous period)

---- 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 first use C keyword "template" to the definition of a template class. The rear of the keyword is the type of type parameter enclosed by a polar number. It is based on this type of parameters, and the compiler can convert the specificity of the template class into an actual class in the compiler into a new class. The next definition method is similar to the Putong class definition, but only the type of parameters in the functional definition of the class.

---- The next step section describes the usage of the template class:

Typedef mytemp myclassfromtemp;

MyclassFromTemp M;

INT a = m.myfunc (10);

---- Tongmong usually uses a template class to see a name with a keyword "typedef" for the new definition. 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. Give the template class with different types of parameters, it is a set of integration of a set of classes that are similar but different from the body. With the definition of new classes, we can create a class of instances like a generic class, a new object, and call the members of this object.

---- Template class is the latest extension of standard C languages, although its function is very powerful, but want to use a good template class require considerable language and programming experience and knowledge, and incorrectly use template classes and will Bring great side effects on the structure and operational efficiency of the program, the general programming environment and programming books take a cautious attitude towards the use of template classes. The core of ATL is constructed by several templates, and the source code of research ATL can make our use of the template class than the comprehensive recognition.

---- More relaxation techniques with the template, is a very competitive technique in C language. The use of multi-successing techniques can make the programming and implementation of more flexible, but is made by a multi-successive complexity and self-contained questions, it is not commonly limited to the support of the context of various faces. For example, if the SMALL Talk root does not allow multiple success, the same MFC does not support more successful techniques. ---- More completed issues is the "diamond structure". For example, the code below:

Class A

{

......

}

Class B: Public A

{

......

}

Class C: Public A

{

......

}

Class D: Public C, B

{

......

}

---- Conversed from class C and class B by class D, and this will have a disagreement in the statement below:

D * pd = new d;

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

---- By class D pass class C and class B minutes, the class A, the strong transformation of this will make a disagreement.

---- ATL uses two operational symbols added by C latest regions Static_cast_cast, Dynamic_CAST replaces the simplified strong transformation, and the ambiguity of multi-relay band is removed. Use these two operational symbols, we can get the type information of the object in the log in the log. The code on the upper surface can be modified using the following square modes:

D * pd = new d;

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

---- What is the template class and more successful technology becomes the main tool for ATL? The original factor is that the use of a template can be quickly generated in the compiled process, which has a great improvement of a complex technology system in COM. By using a template class, the user can focus on the basic logic of the class developed. After completing the design of your class, by inheriting different classes, generating different template classes, you can quickly implement the functionality of COM, At the same time, a large number of functional redundancy caused by the single inheritance structure is avoided.

---- Total, is because of the design of the template and multi-successment technique in the process of designing, the ATL is made into a small and unique COM development tool, which can adapt to the various needs to develop in COM applications.

Third, ATL basic use

---- This part will focus on the basic use of ATL. By the ATL has been set in the Visual C of Microsoft Visual Studio, it is necessary to use ATL must be installed first in Visual C . In the discussion of the next discussion, there is a basic knowledge of COM, please refer to the copy of the document, this is no longer detailed. The figure given is a map of Visual Studio 6.0 under the Microsoft Windows 98 platform. ---- Using ATL to send a COM application basis to be divided into the following steps:

Create a new ATL process, and the appropriate configuration is performed on the options of the process. Add new ATL classes to newly created works and enable initial configuration work for this class. According to the basic requirements of COM, add new interface definitions to the new ATL class, and real-related interface membership functions. Compile the connection process, the booking COM should be used.

The next step will be based on these steps to introduce the basic use process of ATL.

---- 1. Creating a process

---- First starting Visual C integrates an enclosure, select the "New ..." command under the "File" menu, select the "Project" page in the "New" dialog box, as shown in Figure 1.

Figure 1 Creating a new engineering interface

---- Choose an "ATL COM AppWizard" item, which is an AppWizard wizard entry that creates an ATL process. Then enter the name of the process in the "Project Name" editor box, click the "OK" button to enter the AppWizard dialog box. as shown in picture 2.

Figure 2 ATL COM AppWizard Dialogue

---- The main setting options in the AppWizard dialog box are:

---- ■ Type of COM service program:

---- Dynamic Linking Library finally generates a dynamic linkage (DLL) form of COM service.

---- Executable Application "finally produces a COM service program that can be executed in a programs (EXE);

---- NT Service (NT Service) generates a COM service program running in NT service.


New Post(0)