Lu Siwei - Pan Ai People :: ATL Type (3)

zhaozj2021-02-11  186

ATL introduction (3) Lu Siwei

---- (Connected to the previous period)

MFC is allowed to support the MFC. Since the ATL supports the basic Windows programming in addition to COM is extremely limited, many programmers are very familiar with the MFC, so the ATL project is allowed to support the use of MFC in the ATL project, which can use the MFC defined class. . This feature gives a lot of convenience to the developer, and specializes in habits for people who use MFCs. It can support the support of the various functions of the MFC, without having to directly use Windows SDK. From another side, in the ATL process, the ATL code light level is lost in the same time. Support MTS. The MTS is the abbreviation of Microsoft Transaction Server, which is a new branch of Microsoft's coming, this is not detailed.

---- After the upper surface is set, you can select the setup of the finished process, and the ATL will create a corresponding process.

---- 2 . Add an ATL class

---- After the creation and setting of the process, the next step is to add a new ATL class to the engine. Visual Studio integrates the wizard tool "ATL Object Wizard" to add a new ATL class. The operation is not complex, just a set of dialog box operated.

---- First, "New ATL Object ..." command under the "Insert" menu of the integrated environment enters the "ATL Object Wizard" dialog box, as shown in Figure 1.

Figure 1 ATL OBJECT WIZARD Dismorge

---- This dialog box is the start interface of the wizard that creates an ATL object. The left side of the dialog said that the basic type of the object to be created, this is the following types:

Object Based COM object type; control (Control) ActiveX Control type ATL object; other (Miscellaneous) auxiliary function, such as the birth of the dialogue, etc .; Data Access data visits, support MTS, etc.

---- The right side of the right side concludes that each type of detail. For the general COM service program, the Simple Object in the object form is used.

---- Select the basic type of the object to be created to create the object, click the "Next" button to enter the next step, enter the object property settings dialog box.

---- Passage property setting is divided into two processes: first is the setting of the object name identification, and then the basic property of the object is set. The first is the name identification setting of the object, as shown in Figure 2. Figure 2 Password Name Ligand Settings Dialogue

---- Enter the name of the object to be created in the object identification editor, the ATL pair will set the C identification and COM identification of the object in the same step by step. The C identity of the object encloses the class name, CPP document name and header name of the object. The COM identification includes the name of the CoClass segment and the real-current main interface in the type library, and the type name and progID in the systematic registration table at the same time.

---- After the name of the name is completed, select the Attribute page (Attribute) to enter the object setting page, as shown in Figure 3.

Figure 3 Contemporary settings dialog box shows

---- The property setting of the object is the most complex part of the ATL to create the most complex part of the process, including the following major parties:

The thread model of the object's thread model is the control of the access method when the COM object is accessed in a multi-threaded environment. By default, the set of suite model APARTMENT is provided by the system through the message queue. Concurrent control. The interface of the INTERFACE COM object is a Dual Interface. The double interface is not in the generals interface (Custom Interface) in the double interface is successively connected from the Automation Based Adjust Idispatch, and the general interface is directly connected from the iUnknown interface. The default interface model is a double interface. Aggregate COM specification does not allow the actual contributing of the object, but it can be reused with his COM object with the polymerous manner. The polymerization model in the ATL object setting can specify the COM object to be created. The default option is a gathering of the object. This option can be hosted in the logo operation of the error to the wrong mispoterrorinfo. This option is not selected by default. The connection point of the conneity of the connection is a COM object system. Select this option to make the COM object to be created with the ability to issue events. This option is not selected by default. The self-contained thread migration of the free thread Marshaller, the refreed MARSHALLER, the simplified thread is in the self-routing model, which is an optimization strategy for simplified objects. This option is not selected by default. ---- Detailed description of any of the above-mentioned options involves some core content of COM technology, and has exceeded the scope of this article, so this article only adds only the default options given by ATL, interested in these contents. The reader can refer to the documentation provided by Microsoft.

---- After completing the above setting, you can complete the creation of an object by pressing the "OK" button. The next step is to add the definition of the member function to the interface of the generated ATL class, and the implementation of the function function of the interface.

---- 3. Adding interface definition, real interface functions

---- After the ATL class definition, we can open the Class View in the Visual C integration of the ClassPACE to check the condition of the rayped class definition (see Figure 4). We can see a new class has been generated, and it has also generated a corresponding interface definition. ATL Object Wizard gave us a class definition .H and .cpp documents, there are IDL files for interface definition. With these items, we can add a member function for the interface, complete the definition of the class. Figure 4 ClassView showing the ATL process

---- First first select the corresponding interface in the Class View, Figure 4 shows the interface IATLTEST, click the right right button to open the menu, as shown in Figure 5. This population menu defines the operation of adding attributes and methods for interfaces. Select the "Add Method" item in it to add a party member for the interface, select "Add Property" to add new attribute members to the interface.

Figure 5 Interface Edit Menu Chart

---- Joining the attributes and methods for dialogging boxes to see Figure 6 and Figure 7. If we have to add a method in your interface, choose the "Add Method" menu command. The fake settings are named ABC, and the return type of method is a HRESULT type of COM. We can also define non-HRESULT back type functions, but this requires the IDL document that needs to modify the interface definition. We define a parameter of the ABC method to a, type is integer. After completing the definition of the method, click the "OK" button to add this method into the interface.

Figure 6 interface of the addition of the interface method

Figure 7 Adding interface attribute interface

---- The addition of property is similar. The property adds the dialogue to the type, name, and attribute of the property. There is a "Attributes" button in the Edit Dialog box of the Attributes and Methods. After a base definition of a property or method is given, click this button to set it with some high-level characteristics of the attributes and methods.

---- Fang Fang Member added, we can check the work made by the ATL for us through the Class View, as shown in Figure 8. First we see that the ATL joins the definition of the method in the definition of the interface. At the same time, in the corresponding ATL class definition, the definition of a corresponding method is also added, and this method is added to the .cpp file, add this method Implement a framework. After that, we only have to add the code logic of the method in this function frame, and the definition and implementation of an interface function is based on the basis. According to this form, we can complete the definition and implementation of the entire COM object. Figure 8 Adding the Class View after the access method

---- After completing the steps, we can use the compiled connection. (Untonged to stay)

---- (author address: Research "of Beijing University Science and Technology Research Institute, 100871; Received: 1999.08)

转载请注明原文地址:https://www.9cbs.com/read-3907.html

New Post(0)