ATL introduction (2)

Source: Internet
Author: User

----(Last issue)

---- In the C ++ language, the fixed lattice of the model board class is as follows:

template < class T >class MyTemp{      MyTemp< T >( ) { };      ~MyTemp< T >( ) { };     int MyFunc( int a) ;} … …Int MyTemp< T >::MyFunc( int a){}

---- The first step is to use the C ++'s "template" to declare the definition of a template class. The value behind the key is a class parameter enclosed by a tip. Is the root data parameter of this class type, the compiler can transform the specific definition of the model board class into the definition of an actual class in the compilation process, generates a new class. The following definition method is similar to the general class definition ten points, only the description of the class parameter must be included in the Function Definition of the class.

---- The process section below describes the usage of the model board class:

typedef MyTemp< MyClass > myclassfromtemp;myclassfromtemp m;int a = m.Myfunc(10);

---- We often start to see it when using the dashboard class, use the key "typedef" to take a name word for the newly defined class. In the preceding process segment, the false "myclass" is a class defined by the user, by passing the name of this class as a class parameter to the model board class, we can create a new class, the rows of this class are based on the definition of the model board class. For example, if it has a model board class definition, at the same time, this class is a kind of modification to the model board class line. This kind of modification is implemented by using the class parameter provided by the user. If the model board class is assigned with different class parameters, the Union of a group of classes with rows as the frame but with rows as different will be obtained. With the definition of a new class, we can create an instance of a class like a generic class, that is, a new pair, and calls the number of members of this pair.

---- The dashboard class is the latest expansion of the quasi-C ++ language. Although it has a great performance, however, to make good use of the model board class, we need to have a lot of experience and knowledge about the language and programming, by mistake, the model board class will bring a lot of sub-work to the structure and operation efficiency of the Process Order, because of this general programming environment and programming books on the use of the model board class are carefully used. The core of ATL is constructed by dozens of model board classes, by researching the source code of ATL, we can recognize the usage of the model board class more comprehensively.

---- The same as the model board, the multi-inheritance technique is an extremely controversial Technique in the C ++ language. Multiple inheritance techniques can be used to make the design and implementation of the procedure more lively, but yes, some Questions about the complexity of Multi-inheritance and self-thinking, so that the support that is achieved in the language environment of various aspects to the image is not always limited. For example, the root node of small talk does not allow many inheritance, and the same type of MFC does not support multi-inheritance.

---- The biggest question that many inherit is the "diamond structure ". For example, the following code:

class A{    ......};class B : public A{    ......};class C : public A{   ......};class D : public C,B{   ......}

---- It is inherited from Class C and Class B when class D is the same, because the syntax below will produce ambiguity:

D* pD = new D;(A*)pD- >Func(...);

---- Because Class D inherits Class A through class C and Class B, the forced conversion in this class will produce different meanings.

---- ATL uses the two operators static_cast and dynamic_cast added to the latest C ++ rule to perform forced conversion of the simplified ticket, remove the difference of Multi-inheritance. Using these two operator numbers, we can get the class information of the object in the object operation process. The above code can be replaced by the following method:

D* pD = new D;static_cast< A* >(static_cast< B* >(pD))- >Func(...);

---- Why does the model board and multi-inheritance technology become the main work tools of ATL? The original reason is that the model board can quickly generate a class with user-defined functions in the compilation and translation process, this is a complex technique like COM, which has greatly improved the real-time efficiency. By using the module board, the user can compile the essence set on the basis of the self-developed class, after you have completed the design of your own classes, you can generate different template classes by following different classes, in this way, you can quickly implement the functions of COM, and avoid the large amount of work that is constructed by using a single inheritance.

---- In general, it is from the use of model boards and multi-inheritance techniques in the design and implementation process, so that ATL becomes a small clever com development work, can meet the needs of developers for the COM should be used.

Iii. Use the ATL Base

---- This part introduces the base usage of ATL. Because Atl has been integrated into the visual C ++ development environment of Microsoft Visual Studio, Visual C ++ must be installed first to Use ATL. In the discussion below, you can refer to the documents with the reference knowledge of COM, which is not detailed here. The diagram is a usage diagram of Visual Studio 6.0 on the Microsoft Windows 98 platform.

---- Enable the use of ATL to open a com application. The base can be divided into the following steps:

  1. Create a new ATL job and configure the job items as appropriate.
  2. Add a new ATL class to the newly created job, and perform some initial configuration work for the class.
  3. According to the base of the COM application, add a new access definition to the new ATL class, and implement the corresponding access number as a member letter.
  4. Compilation and translation of the connection process, note book COM should be used.

The following describes the basic usage of ATL based on these steps.

----1. Create a job

---- Start the Visual C ++ set to open the environment, and select "new..." under the "file" menu... in the "new" dialog box, select the "project" page, as shown in figure 1.


Figure 1 create a new job Interface

---- Select "atl com Appwizard". This is the Appwizard import port for creating an ATL job. Then, enter the name of the job in the project name edit box, click "OK", and enter the Appwizard dialog box. As shown in figure 2.


Figure 2 Definitions of atl com Appwizard statements

---- In the Appwizard dialog box, the main configuration items are as follows:

---- ■ Class type of the COM Service schedule:

----Dynamic Connection Library)The final production generates an dynamic connection library (DLL)-type COM Service Order;

----Executable Application)The final production generates a COM Service Order that can execute a sequential class (exe;

----NT Service)Generate a COM Service order that is run by the NT server.

---- ■ Allow embedding proxy/stub code. After the midl files provided by Microsoft are translated into IDL files, the proxy/stub code generated for image tuning is used. In the traditional method, the code of this Division code is separated from the code of the COM Service Order, however, it is the COM Object Service under the multi-line environment supported by the new COM standard, because the support for proxy/stub is also required in the COM Service schedule of the dynamic connection database. In order to support data transfer over the network, ATL allows users to select and include proxy/stub code in the generated DLL code. This option cannot be selected under the EXE and NT server class com applications. ◎ (To be continued)

---- (Author's site: Beijing University Computer Science and Technology Research Institute, 100871; Draft date: 1999.08)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.