Comprehensive understanding COM +

xiaoxiao2021-03-06  47

Comprehensive understanding COM

(Author: Pan Aimin) we can see from a variety of media introduction of Windows 2000, Windows 2000 among the many new functions and features for developers, COM is the most noteworthy of a focal point. In the Windows 2000's beta version, we have seen the appearance of COM , and feel COM will bring our changes in the idea of ​​the program design and development. This article aims to make a basic introduction to COM from the perspective of technology so that developers can better understand COM . COM is not a new version of COM, we can understand it as a new development of COM, or for COM higher-level applications. The underlying structure of COM is still based on CoM, which is almost included in the COM. There is a saying that COM is integrated with COM, DCOM, MTS (Microsoft Transaction Server), which is a certain reason because COM does combine these technical elements. But more importantly, Com advocates a new concept that upgraded the COM component software to the application layer, which is no longer the software structure of the underlying, which makes the component object model in the application through various support of the operating system. On the layer, leave the underlying details of all components to the operating system, so the combination of COM and the operating system is more close, which is the main reason for COM non-equal to Windows 2000 release. We know that COM is an open component standard, which has strong expansion and expansion, from COM to DCOM, and the development process of MTS has also fully explained this. Readers who have experience in COM must feel that although COM has changed the Windows programmer's application development mode, integrate the concept of components into Windows applications, but due to various reasons, many of the superior advantages of DCOM and MTS have not been The majority of Windows programmers know. MTS features many features and features, including transaction feature, security models, management, and configuration, etc., MTS makes COM a complete component architecture on the basis of COM / DCOM. Due to historical reasons, COM, DCOM and MTS are not very harmonious, and it is difficult to form a unified whole. However, this situation will soon end, because Com will effectively unify these three, form a new The powerful component architecture, and bring various advantages of DCOM and MTS to Windows 2000 programmers and users in a more simple manner. This article is divided into four parts, the first part introduces the basic structure of COM ; the second part introduces some system services provided by COM ; the third part tells the COM application development model; the fourth part introduces the characteristics of COM and brief summary. By reading these content, readers can see that COM will bring us some programming concepts, which will change our app, how to change the development model of the application. One .com basic structure COM is no longer limited to COM component technology, it is more focused on the design and implementation of distributed network applications, has become part of the Microsoft system platform strategy and software development strategy. Com inherits COM almost all advantages, while avoiding some of COM implementation. COM is tightly coupled to the operating system, providing a comprehensive service for the application through system services, this section describes the basic structure of COM .

1.Windows DNA Policy Before introducing the COM structure, let's take a look at Microsoft's Windows DNA (Distributed Internet Application Architecture policy "because COM will play an important role in the DNA policy. Windows DNA is a collection of technical extracts that Microsoft's years have accumulated technology and form a complete, multi-layer structure, which makes Windows truly become an enterprise application platform. Readers who are familiar with MTS must know that Microsoft proposes the concept of multi-layer software structure on the basis of MTS. In terms of big aspects, a business application or distributed application can be divided into a performance layer, a business layer, and a data layer. The performance layer is the application's client portion, which is responsible for interacting with the user; the business layer constitutes the application's business logic rules, which is the core of the application, usually consists of some MTS components; the data layer is a background database, which can be in dedicated The data server can also be on the same server with the business layer. The MTS is primarily located in the middle of the intermediate layer, which provides a unified environment that runs and managed for business components. Figure 1 (a) shows the technical composition model of this multi-layer structure. Windows DNA is a simplified three-layer structure as shown in Figure 1 (b). (a) Three-layer structure technology composition model (b) Windows DNA structure

figure 1

Under existing system platforms and software development tool conditions, in order to achieve multi-layer structural enterprise applications, we must use various separation technologies, developers to learn every software technology, including some of the Win32 APIs and systems. service. Figure 1 (a) Lists some software or techniques that may be used, learning these knowledge itself is not a relaxed thing, let alone develop outstanding applications. The programmers who have used these technologies on the Windows platform must have a deep understanding. Figure 1 (b) makes more concise, this is a structural model that has not been implemented, but Microsoft is working in this direction. In the performance layer, we now develop applications, or use Win32 API to develop customer applications, or use HTML or DHTML to directly use the browser as a customer application. In the DNA structure, Forms is just a technology framework, which will combine Win32 GUI and Web API and develop in the direction of DHTML, we can see some of Forms from the structure model of the released Microsoft Internet Explorer 5. Ni. In the data layer, Storage is just a kind of method, but Microsft has transferred the database interface from ODBC to ADO and OLE DB, which will eventually promote the unity of data layer interface technology. In the middle business layer, COM has become a reality, and it integrates many technologies that are originally scattered in the form of system services, and provides a simple programming model to provide services to the application. COM is the core of the DNA structure, which will become the basic tool for enterprise applications or distributed applications. With the world of Windows 2000, the DNA structure will gradually be clear, eventually bringing us a new application software model. 2. The basic structure of COM COM is not complicated, simply, it combines COM and MTS programming model, and add some new features. From the perspective of COM, COM initially serves as component technology on the desktop operating system platform, mainly OLE services. However, with the release of Windows NT and DCOM, COM extends the component technology into the distributed application area through the underlying remote support, fully embodies the expansion capability of COM and the advantages of the component structure model. MTS adds many new content to COM, which makes up for some of COM and DCOM, which focus on components management and configuration environments at one end of the server. COM further unity COM, DCOM and MTS, forming a component technology that is truly suitable for enterprise applications. The structural relationship between COM, DCOM, MTS, and COM is shown in Figure 2. Figure 2 COM composition structure

COM not only inherits many of COM, DCOM, and MTS, but also adds some services, such as load balancing, memory database, event model, queue service, etc. Com new service provides a strong feature for COM applications, the application based on COM can directly use these services to obtain good enterprise application features, this article will focus on these services. COM also provides a better component management environment than MTS, as shown in Figure 3. The COM Manager (COM Explorer) also has the MMC (Microsoft Management Console) standard interface. Corresponding to the package (Package), COM is called COM applications, each COM application also includes one or more COM components and role information related to the application. With the COM management program, we can set the COM application and the property information of the COM component, such as the transaction characteristics, security features, etc. of the component. As shown in Figure 4. Figure 3 Schematic of the operation of COM management program

Figure 4 Property Configuration Schematic of COM Components

We know that COM and MTS save all configuration information of the component in a Windows system registry, however, the COM is different, it saves most of the component information in a new database, called COM directory (COM CATALOG). The COM directory consists of unity of COM and MTS's registration model and provides a management environment specifically for components. We can check or set up COM directory information through a COM management program, or you can access COM directory information over a set of COM interfaces provided by COM . COM provides many new services and a consistent management environment. On the other hand, it supports Declarative Programming Model, that is, developers can develop component programs as common as possible, put some Details are left to the configuration time again. For example, we develop a COM component that supports load balancing features, but we don't determine if we use load balancing characteristics when developing components, and makes it supported to support load balancing features. Some applications may require load balancing features, and some applications may not require, we can configure component's properties to support load balancing characteristics through the COM Manager. The MTS security model is actually a typical illustrative programming technology that leaves the security role information of the component to the configuration time and then gives the exact definition, not the programming time. COM inherits the security model of MTS. Using COM services and management tools, and some development tools subsequently released, developing a COM component is much easier than developing a COM component, because the COM component is actually based on the application based on COM system services, we can avoid The underlying tedious detail processing. With COM system services, we also make our components or applications more standardized while getting reliability, reflecting the polymorphism of components or applications in a wider range. 3. How is the managementability and configurability of the object environment COM components? Like the MTS component, COM provides an object environment for each object, and the COM system can assign an environment object to it when creating a COM object. This technology is also called intercept, below Steps can further explain the concepts of interception: (1) Component objects specify some basic requirements by illustrative attribute; (2) When the client calls the CoCreateInstance function, the COM system checks if the customer code is running in class with the object class. In a compatible object environment; (3) If the customer code is compatible with the object class, you don't have to use the intercept technology, create the object and return the interface reference of the object; (4) If it is not compatible, then the CoCreateInstance function handover To a environment compatible with the object class, then create an object and return a proxy object; (5) During the future interface method call, the proxy object is to do some processing before calling and calling, so that the method's operating environment can be Meet the requirements of the object. COM introduces the concept of Context, which refers to the shared object collection of the same set of operations. Since different object classes may use different configuration information, one process usually contains one or more environments, which are not compatible with each other. All objects without configuration information reside in the caller's environment.

Each environment has an object, an object environment, and an object running in this environment can get this object environment through the CogetherObjectContext API function, using an IObjectContextInfo interface of an object environment to access properties information. COM object references to the object interface pointer of the customer is related to the environment, so we cannot simply introduce object reference from an environment to another environment. When a customer calls an object in another environment, the middle must pass the agent object and the stub code, and the call is taken by the agent object, which is responsible for environmental switching, which is similar to the COM cross-circuit column (Marshaling). As shown in Figure 5. Figure 5 Schematic diagram of cross-environment call

As we can see from Figure 5, the environment is very similar to the apartment in the COM thread model. When the object reference (ie, the object interface pointer) is passed from an environment, it is also column (Marshaling) Treatment, that is, call Comarshalinterface and CounmarshalInterface functions. This will ensure that the customer code and objects are performed in their own environment, which is important for applications that support transaction characteristics, security features, or other special requirements. Although cross-environments must pass the agent and settled code, this does not mean that the thread switching is required, which is an important difference between the environment and suite. During the inter-inter-inter-set call, the main factor affecting performance is thread switching, rather than the parameter column set (UNMARSHALING), so crossing environmental calls may be much higher than the efficiency of cross-envelopment. COM introduces environmental concepts, but the concept of the suite still exists, the difference between the two is the basic unit of the thread model, and the environment is the basic boundary of the column mechanism. The environment and suite do not contain a relationship, and an object in an environment can run in different suits. At this time, the cross-envelopment call must also pass the agent object; a suite can also contain multiple environmental objects, at which time cross-environment is also required. After proxy.

From the above to COM , we can see that the underlying structure of Com is still based on CoM, but in the application method, more inherits the MTS process mechanism, including the object environment, security model, configuration management, etc. of MTS. But COM is not a simple package for COM and MTS, which also introduces many new content, which is these new features make Com more suitable for component object models for enterprise applications. These new features are reflected in a set of system services. The next section describes these system services. II.COM system service introduction Com system service fully reflects the Characteristics of Com , through these system services, we can easily develop multi-layer structures, because these system services themselves have met some of the basic applications. Claim. Com provides many new features in the form of system services, which has many benefits, first, customer or component programs can directly utilize these system services, avoiding the underlying detail processing, reducing development cost, reducing code quantity, while It also reduces the possibility of mistakes; secondly, some system services involve more complex logic, may access system resources of the underlying system, it is difficult to implement these system services; in addition, using system services can enhance reliability, Because these system services have been strictly tested, the application system needs to be expensive to obtain the same reliability. COM system services have inherited from MTS, and some are new. This part focuses on the initial introduction of new system services, including queue components, load balancing, memory databases, and event services, and finally introduces other system services that have been introduced in MTS, but Com and enhanced system services, including transactions , Object pool, security model, and management characteristics. 1.Com Queuing Components We know that interactions between COM customers and remote components are based on RPC connections. The client connects to a component object, requests the specified interface, and then performs synchronous calls through the interface pointer. Although COM also allows asynchronous calls, customers and components must be consistent, and the call must be performed within the connection validity period. COM In addition to supporting this RPC connection, it also supports another running mode. We call the message-based communication process that can effectively leave the customer with the component's survival. This mode is implemented by a COM queue component service, and FIG. 6 is a basic model structure of the queue component.

Figure 6 The queue component model structure diagram queue component does not use a direct RPC connection, but uses the underlying message system MSMQ (MicroSFT Message Queue Server). Through the underlying queue mechanism, the living cycle of the client and the component can be separated at different point in time. The client no longer calls the component object directly, which uses the message mechanism to communicate with the component object, even if the component object is not running, the client program can still perform the operation. COM applications can support synchronization and asynchronous calls in transparent mode. When the client and component program have established a connection, the customer directly calls the components in synchronous mode; if the customer is not established directly, the customer is asynchronous. Communication with components. If the component object is identified as "queue", it supports the queue mode, so a proxy object called "COM Recorder" automatically records the call request of all the components into a permanent queue, the queue is saved. On the client; after the client is connected to the network, "COM player" on the server is located from the permanent queue to perform the true call operation. The queue component is unified in a single programming model in a transparent manner in a single programming model, so the COM application system does not require additional work to get an asynchronous feature. We can still develop components and client programs in a usual way, but due to the speciality of the queue, the components must meet two restrictions: First, the interface member function of the component can only have input parameters, and cannot include output parameters, these The input parameter will be passed to the MSMQ message; second, the return value of the component interface member function cannot be related to the application, it does not identify information related to the application. During the asynchronous interaction of the queue component, the client creates a component object, which actually creates a logger agent object, all calls are performed by the logger, record the call request, then pass MSMQ to the server Components, players on the server perform these method calls. The difficulty of using this asynchronous method is how the client gets the return information, which contains several possible situations and a solution: First, the customer does not care about the execution; second, we can use the response queue to implement the customer program; Third, customers can also pass some of their feature information to component objects so that component objects notify customer application in the same way asynchronously. What kind of solution to choose depends on the need for the application, we can flexibly use various technologies. Queue components are very meaningful for distributed applications, especially in the slow network, which ensures that the application system can run reliably. In the case where the application system contains a large number of customer nodes but the number of servers is relatively small, the client application can put their request in the queue, and then process these requests when the server load is light, the queue mechanism is also from another angle. A load balance and scalable characteristics of the application system are implemented. 2. Com Event Model COM not only defines the communication process of the customer calling component object, but it also defines the reverse communication process, which is the CONNECTABLE OBJECT mechanism. The component object defines all features of the outgoing interface. The client implements the interface. After the client is connected to the object, the client establishes the reverse connection between the client receiver object by the connection point object. In fact, the connection point object is the client of the receiver object. Coiled objects have a great advantage, its extension ability is very strong, almost always meet the needs of the application.

However, from the actual application, there are some shortcomings in the following aspects: First, the event source and the client are tightly bound together, and the two program code depends on the definition of the interface, we must The compilation moment knows the other party's information; second, source objects need to write a large number of code to support this mechanism, especially in order to support multi-channel events; third, the design pattern of the connection point interface does not take into account the characteristics of the distributed environment, It is not very effective in distributed environments. The COM event model improves the COM's connectionful object mechanism, which uses multi-channel publishing / subscription (MulticaSting Publish / Subscribe event mechanism, which allows multiple customers to "subscribe" events, which are published by various component objects ". COM Event Service Maintains an event database, the database contains various events, publishers, subscribers, and all subscription information. When the Publisher motivates the event, the COM Event Service checks the subscription information related to the event database and then notifies the corresponding subscriber. The basic structure of the COM event model is shown in Figure 7. Figure 7 COM Event Model Structure Diagram

The COM event model passes the entry event information of the source object through the event class so that it can match the client's entry event method, which is very similar to the COM connectable object mechanism, so old-fashioned COM components and client programs. New COM event model can be conveniently used. The COM event model is separated by the central service and central management of the Publisher and the subscriber, which uses the event class as an intermediate object between the publisher and the subscriber, and the publisher must publish information through the event class. The event class is an object provided by the COM event service, which implements an event interface, so for the publisher, it plays the role of the subscriber. When the publisher wants to stimulate the event, it creates an event class object, calls the corresponding event method, then releases the interface of the object. The COM event service will determine how to inform the subscriber and decide when to notify the subscriber. Like the queue component, the publisher and subscriber's survival time can be separated. In this sense, all event interface functions can only contain input parameters. The subscriber subscription event is also very convenient, and it only wants to create a subscription object through the COM Event Service and register in the event database, and it will receive an event notification from the publisher. The COM event system not only provides an event service for the application, but also provides event services for the internal implementation of the operating system, for example, it is also used to implement the underlying system event notification service (SENS) of Windows 2000, including user login events, network connection Events, etc. We can create and register a subscriber to receive these system events. This is an application of the Com event system, of course, receives such system events must meet certain security policies. 3. Load Balancing Load Balancing is a high-level demand for distributed applications. If there is no good tool support, then the load balance needs to pay great consideration. We can use DCOM and MTS configuration features to implement static load balancing, but to achieve real dynamic load balancing is not easy, we are difficult to pass object creation requests to the lightest machine according to the current system's load state, we must Write a lot of code to indirectly support this feature. COM provides a load balancing service that can achieve dynamic load balancing in a transparent manner. However, in order to make the component support load balancing, we must first define an Application Cluster, which means that a set of machines that have already installed the server-side components (up to 8 machines), then we configure a machine configuration Become a load balancing router (Router), the load balancing router passes the creation request of the object to a machine in the application cluster. COM Load Balancing is run on the router machine in the form of NT system services. When the SCM (Service Control Manager) receives a remote creating object request, it passes the request to the lightest machine. A difficulty of achieving load balancing is how to determine which machine in the application group is the lighter load. The COM load balancing engine uses the default load balancing algorithm, which calculates the load balancing parameters according to the response time called by the method of each object instance on each machine, which is not necessarily the best algorithm, but for large Most applications are already enough. COM also allows applications to use custom load balancing engines. The object creation process in the COM load balancing application model is shown in Figure 8. Figure 8 Schematic diagram of object creation in load balancing mode

The client can still create a remote object in a usual manner, specify a router machine name in the CocreateInstanceEx function. After the creation is successful, it gets the object instance it gets on the most light load. The router checks the COM directory, see if the request created component object supports the load balancing, if yes,, according to the routing algorithm, route the created request to the lightest server. Then, after using the server in the application cluster, it creates an object after the server is created, and the object reference is directly returned to the client. Therefore, once the object has been successfully created, the connection between the customer and the object is done, without having to pass the router. The load balancing characteristics of the COM application do not need to write code to support, the client and component programs can be implemented in a usual manner. Therefore, obtaining the load balancing characteristics is not a behavior of programming and development, but a configuration behavior that implements the load balance of distributed applications. Of course, when we write load balancing components, we must avoid using information related to the current machine environment, such as the current machine name or dependent on a file under a path on a local machine, and so on. 4. Memory Database (IMDB) COM The memory database (IN MEMORY DATABASE) service is a new service that is used to save the application's non-permanent status information. We know that for data-centric applications, in order to improve the operating efficiency of the system, it should make more data to reside in memory, especially if the customer program is frequently accessed. IMDB is a database system that resides in memory transaction feature that provides fast data access for COM applications. The basic function of IMDB is to optimize data query and data acquisition, which can load data tables in the background database system, or load non-permanent data information for applications. The most typical example of using IMDB is a web application that places the data information that customers access frequently in IMDB so that hundreds of customers get a quick response. Because physical memory capacity is getting bigger (2GB physical memory installed on the machine), and the price is getting cheaper, so through IMDB, we can increase the response speed of the system, and to access frequently Data from the data layer to the business layer can effectively reduce network traffic. Figure 9 shows the basic structure based on IMDB-based web application. Figure 9 Schematic diagram of web application based on IMDB

The IMDB interface is OLE DB and ADO, so component objects can access IMDB through these standard interfaces. Since IMDB is a database in memory, IMDB is only valid for COM components on this machine, that is, IMDB does not support distributed concepts, and multiple IMDB machines cannot be loaded into the same data table, if multiple components want to share IMDB Information, then these components must run on the same machine. IMDB runs on the server in the form of NT system services, and when the service is started, IMDB puts all specified data tables into the shared memory from the background database. IMDB loads data in units of units in the entire data. If memory is not enough, you can't install the entire table, then IMDB will generate errors. Component objects Access the data table in the IMDB through the proxy object within the process. Because IMDB is as fast as possible, it does not implement the SQL query processor, so we cannot use the SQL command to access the IMDB data, and can only access the IMDB data through standard ISAM technology, that is, we must access data by indexing. IMDB can not only buffer data tables, it can also manage non-permanent status information for application systems. If you need to share a lot of information, select IMDB is an ideal solution. 5. Several system services to other services Before introduced, COM add new services for distributed applications, and other services that are originally provided in MTS, which forms a COM underlying service system. We know, COM has provided basic communication procedures between component objects and client programs, including object creation, cross-process mechanism, interface management, etc., and the underlying service provided by Com focuses on some high-level applications, especially Some features that build large software systems or distributed software systems need to support. Some of the services that COM enhanced on the MTS is a brief description. (1) Transaction characteristics. The transaction allows components to form a set of independent operations a whole operation, and the transaction is either success or fail. COM still supports the MTS's transaction semantics, completes transaction operations through SETABORT or SETCOMPLETE. COM also supports other transaction mode, if an object is labeled "AuTabort", then during the transaction operation, the system automatically calls setAbort. Similarly, if an object is labeled "AutoComplete", then the system will automatically call SetComplete unless this method is invoked. And COM also supports Byot (Bring Your Own Transaction), which allows COM components to participate in non-MTS transactions to handle environmental management. (2) Safety.

The safety model of the COM still uses the role-based security model of MTS to access the application according to the user's role. This security model requires developers and managers to complete, in the development phase, developers are responsible for defining various roles, and when implementing component functions, users only allowing users can perform these functions; in the configuration phase, administrator Responsible for specifying the user account for all characters. COM expands the MTS security model that allows developers and administrators to designate security control levels at first-level levels, in the MTS security model, we can only specify security roles at the MTS package level. With COM object environment information, COM security model is more meticulous, for example, it allows developers to control each interface, or how each method is played, and so on. (3) COM object pool.

The object pool refers to the instance of the object in memory so that these objects can be used immediately when the customer requests to create an object. Like IMDB, the object pool is entirely due to the reason for the efficiency, used to establish a large application system. The concept of the object pool has been introduced in MTS 2.0 because three member functions of the IObjectControl interface of the MTS component activate, deActivate, and Canbepooled are used for the management of the object pool. However, MTS 2.0 actually does not support the target pool, that is, regardless of whether the object supports the object pool cache operation, its IOBJECTCONTROL :: CANBEPOOLED function will never be called. COM inherits the concept of the MTS object pool and truly realizes the function of the object pool. (4) Management services. In the first part of this article, we have seen the COM management program that replaces the MTS Explorer and the DCM Configuration program (DCMCNFG.EXE). For multi-layer structures, the COM management program is an indispensable tool, the basic configuration of the application system and the transaction characteristics need to be implemented by the management program. Since the MMC interface is simple, intuitive, the administrator can configure all application systems without having to learn other management tools. And the COM management program supports scripting languages, so developers and administrators can create some scripting code to automate management. Com also introduces a new "AppLid", which is a 128-bit GUID that identifies a CLSID that is associated with a set of attribute values. With "AppLid", administrators can configure and maintain multiple versions for application.

This part focuses on the COM 's various system services, especially several new system services, which makes COM more suitable for distributed applications. Some system services do not need COM applications to be programmed, such as load balancing and queue component services, etc., and some services can simplify programming models, such as event services; other services can be used to improve system performance, such as memory Database, object pool, etc. Third .com application development In the introduction of the basic concepts of COM and after system service, the third part we discussed some of the issues developed by COM applications. First we discuss the changes from COM to COM for application development model, then introduce attribute-based C programming languages. 1. An important feature of Application Development Support COM specification is that it defined COM interfaces have nothing to do with development language, so we can implement COM objects or use COM objects in various development languages. This is true. However, we can find that although COM and C binary structures are close, we don't relax in the C language, write a C class and achieve a big difference between a COM object, even if you use MFC or ATL Such a library or template library, we still need to learn some of the underlying knowledge of COM, otherwise it is difficult to write the correct component program. Readers who have used Visual Basic 6.0 must have this experience, writing automation in VB6 (Automation) component is very simple, as long as "Class Module" is written according to conventional methods, COM components can be implemented. The VB6 compiler assumes all the underlying detail processing tasks. For programmers, just some "class module". Although this development model limits the programmer's control, for most cases, VB6 does not lose a development environment that quickly implements COM components. After COM , its development model will also have some transformation, especially for the Visual C programmer, in the compile time programmer can set the properties of the COM component in the code, such as CLSID, PROGID, thread model As well as dual interface, if you do not specify these properties, the compiler will use the default. We used to enable COM components to support certain non-default features, we must implement these features by writing code, so programmers must understand all kinds of characteristics very clearly to write the correct code, this is also achieved. A difficult point in COM components. The COM is closely integrated with the operating system. On the other hand, COM will be combined with the compiler, which will expand some syntax of C , so that we can describe the COM characteristics in the code, and then directly by the compiler Support for these features, thereby reducing programmers' workload, increasing the production efficiency of COM components. In the code, the descriptive statement is used to indicate the compiler generate metadata (Metadata) related to the COM component, and the COM running system will use these metadata to manage COM components. In a sense, we can think that metadata is some type library information, so the C development system that actually supports the C development system of the COM component will combine the syntax of the IDL / ODL with C syntax. Here, we will see this when the property-based programming model. Fully supporting the development tool for COM components to wait until Windows 2000 release, can be implemented in the next version of Visual Studio.

As a compatible solution, in the current Visual C version, the compiler still only supports the original C syntax, when it encounters the illustrative description information during the pre-processing, it gives these attribute information to attributes The analyzer destabuses, the property analyzer is a compilation extension module, which converts the property information into C code, then send it back to the compiler, compile these source code to the target code. Other information generated by the attribute analyzer, such as type information, also being encapsulated in the final code. The structure of the compiler is shown in Figure 10. Figure 10 Schematic diagram of compilation process of COM components

2. Attribute-based C programming language-based programming models will directly write the property information of the COM component to the C source code, the instructions of the compiler generate COM components, so that the programmer does not have to write the underlying processing code because of these codes Almost all components are similar, so letting development tools directly produce these codes to avoid duplication of labor. This approach is more direct than the MFC macro and the template class of ATL. Attributes do not affect basic C semantics, and the syntax of the attribute is relatively simple. Attributes can be used in front of any illustrative statement, such as a declaration of a C class, and the declaration of variables can specify its properties in front of them. It should be noted that usually we are not specified in the type or instance definition statement. The following code illustrates the usage of the property:

[UUID ("346BF467-3467- D211-23C6-0000000000"), Helpstring ("ImyInterface Interface"),] Interface ImyInterface: IUNKNOWN {HRESULT FUNC1 ([in] long, [out, retval] long *); HRESULT FUNC2 ( [in] long, [out, retval] long *);

[Coclass, Progid ("Mycomp.Myobj.1"), UUID ("346BF468-3467- D211-23C6-0000000000"), Helpstring ("Myobj Class")] Class CMYOBJ: PUBLIC IMYINTERFACE {public: cmyobj ();

// ImyInterface public: HRESULT FUNC1 ([in] long, [out, retval] long *); HRESULT FUNC2 ([in] long, [out, retval] long *);

...};

If the reader is familiar with the IDL or ODL syntax, the description of the attribute in the above example must be very clear. Visual C properties analyzer analyzes attribute keywords and generates corresponding C source code (actually ATL code). The following table lists some common attribute keywords supported by the property analyzer. Table 1 Common Properties Keyword List

Attribute keyword

Description

CoClass

Add COM characteristics support to generate the corresponding IDL file.

Dual

Mark an interface as a dual interface, support two access methods: vtable or idispatch.

Emitidl

Indicates that all of the following attribute information is written to the IDL file.

id

Specifies the distribution ID (DISPID) of the method in the automation interface.

IN / OUT

Specify the direction of delivery of the parameters.

PROGID

Specify the ProgID of the component.

RetVal

Indicates the return value of this parameter as a method. Threading

Specify the thread model of the component.

UUID

Specify the GUID logo of the class, type library, or interface.

Module

Specify the information of the component program, including the program type, file name, type library Guid, version and other information.

Programming models Based on the Visual C programmers provide shortcuts, which avoids MFC complicated macro definitions and ATL's template classes. The properties programming model also includes other semantics or syntax, such as event definitions, object constructs, etc., we will be able to see these changes in the new version of Visual C or COM SDK. IV. Summary Although COM is still based on COM and MTS, because of its reason, COM has increased more content. Compared with COM, Com combined with Windows operating system is more close. In turn, the Windows operating system is also more dependent on COM ; compared with MTS, Com is more suitable for distributed applications, which provides many large distributions Some features that the application can be used. From the current development trend of the current computer hardware and the Windows operating system, COM is likely to promote an important technical pillar of the Windows 2000 operating system, while COM and Windows 2000 are united to enable enterprise applications directly into the distributed application area, which is our current A development direction that can already be felt. Several main features of COM are listed below: (1) Real asynchronous communication. The COM underlying provides queue component services, which allows customers and components to work together at different points, and the COM application can obtain such features without increasing the code. (2) Event service. The new event mechanism makes the event source and event receiver more flexible, using the system service to simplify the event model to avoid trivial details of the COM connection object mechanism. (3) Scalability. The scalability of COM is derived from multiple aspects, dynamic load balancing, and memory databases, and the target pool and other system services provide technical foundation for the scalability of COM , and COM scalability principle and multi-layer structure scalable characteristics. Consistent. (4) Inherited and developed the characteristics of MTS. From COM to MTS, it is a conceptual leap, but it is not mature, and Com is perfect and implements many of the concepts and features of MTS. (5) Manageable and configurability. Management and configuration is the behavior after application system development. Today, in today's continuous increased today, COM applications will help software vendors and users to reduce this in this regard. (6) It is easy to develop. Com application development complexity and difficulty will determine the success of COM , although the COM development model is more simplified than the previous COM component development, but truly improved development efficiency still needs to with some excellent development tools. Com marks a new height of Microsoft component technology that is no longer limited to desktop systems on a machine, which points the target to a broader enterprise network, and even Internet international interconnect networks. Com and multi-layer structural models and Windows operating systems provide a complete solution for enterprise applications or web applications. This article is written before Windows 2000 and COM release, the final COM faces and features may have something to pay. Due to various reasons, the system services described in the second part are not necessarily implemented in the final released Windows 2000, but the subsequent version will gradually implement all of these services; the development method introduced in the third section may be in Microsoft's next-generation development tools There will be changed in the middle, but we can make awareness of this development model and make a good idea in advance.

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

New Post(0)