Our dreams use COM to retrofit our software

zhaozj2021-02-11  242

* This article is selected from: Visual C / MFC Development Guide

Our dreams use COM to retrofit our software

-

Key words:

Com Ole Active X Container Automation Controle iUnknown Idispatch Self_Contained

Class Factory DCOM COM MTS MSMQ

Insteit

An application is usually constructed of a binary file. When the compiler generates this file, re-edit the next version

The application generally does not change any changes before translying and issuing a new version value. Operating system, hardware and customer needs

The changes must be waited until the entire application is recompiled to be recognized. The entire software industry is like this

The increasing "aging" of the issued software has rushed to the future. Currently, this situation has changed. Developers find

One solution is to divide a single application into multiple separate parts. That is, the component. That is to see the soft parts as an object.

The advantage of this approach is to replace existing components with new components with the continuous development of technology. The application at this time will

It is no longer the previous entity that has been destined before issuance, but can be replaced with the new component.

And tend to improve.

This is not too tempting to us. Everyone knows that we can't issue new versions to users every day.

But one thing you must like it. When you change some implementation functions in the DLL as needed, you don't need to re-edit it.

Translation of the entire program can use new performance. Is it unbelievable.

The impact of using COM models to software will be huge. It is the revolution in the software industry. Who for the programmer of a software, who?

I don't want to use the class like MFC as a class like MFC, instead of facing boring and embedded a deep function.

Dazzling global variables. It takes a lot of time to understand the source program before the change program. COM provides a binary standard

Object-oriented, expandable, reusable communication protocol. If you continue to read, you will find the construction of COM-based testing.

The benefits that the software will bring you will be huge. Take some time, money will get a half-time return.

Each programmer may have this experience: when modifying a large program, due to the complexity of the program itself,

Some functions are very difficult. How can I construct a clear logic, complete structure, and relatively independence?

Is the expanded logic model? Microsoft offers COM, apple has its OpenDoc, IBM has SOM. Software industry

I am walking 20 years ago. Twenty years ago, people have created an integrated circuit block and can be completed with a piece of block.

Small chips for specific work, construct new larger chips to complete new features. This is the problem facing the software industry.

Two new technologies for the most popular in the computer world today are COM and DCOM. Co seems to be a good thing to solve all the shortcomings of all software development.

square. Of course, this doesn't mean that you will die for all after using COM. The software industry is no "silver bomb" myth. Just COM pair

The new issues we face today have a better solution. For example, the development of distributed procedures, the security of transaction processing, cross

Reusability of the platform ------

Advantages of using components:

The advantage of using components is that the application can evolve over time. In addition, using components can be

More convenient and flexible with the upgrade of the program. The component architecture is essentially customized, and users can use them to meet them.

The components must be replaced by the components. Like the class, COM is a software programming constructor, not a mathematics.

model.

One component technology

The evolution of observation component technology is to understand the beginning of COM and DCOM, although object-oriented technology has experienced a complete self

The process of evolving, but component technology acts as an object-oriented technology, but has its own evolution process. Component skills

The main foundation of the evolution is Windows OS. Of course, some other technologies have also played a lot.

1. Custom Control (CUSTOM Control) appears in Windows 3.0. A custom control is a dynamic link library that can output a set of functionally defined functions. However, different from the general DLL is that a custom control can perform characteristic operation.

And can handle the trigger event caused by the user or program input.

2. In 1991, Microsoft's VBX launched, making the important role of small reusable components. But unfortunate

Yes, the VBX package is constrained too much, 16-bit structure, and there is no open interface, limiting the application of VBX.

3. That is, Microsof has developed OLE1.0 specification in the same year. Object Linking and Embedding. OLE1.0

Strive to develop in the direction of the document center, rather than traditional development directions. "Composite Document" is

The product of this thought is stored in a single file in a single format, such as text, graphics, video, graphics, and sound.

method. We are more familiar with Word in the Office kit. But OLE1.0 due to its own complexity, and the implementation

Inaction is immature. It was cold in the market.

4. Microsoft is not intimidated by the difficulty of OLE1.0, but continues to be committed to the improvement and improvement of OLE. Released in 1993

OLE2.0 specification has introduced a completely object-based service structure, easy to expand, customize, and enhance. This kind of junction

The service available is:

COM

Clipboard (CLIPBOARD)

Drag and DROP

Embedding

In-Place Activation

Linking

Tag (permanent naming) (Persistent Naming)

OLE Automation

OLE Control

OLE Document

Structured Storage (StructRued Storage)

Same data transmission (UNIFORM DATA TRANSFER, UDT)

5. Active X

The word Active X is proposed on the Internet Professional Developer Symposium (Internet PDC), which is only one as one

Species call rather than specific application development technologies. Active the Internet With the rapid development of the Internet

Active X becomes the core of all content defined from the web page to the OLE control. On the one hand, it represents the user to

Small fast reusable components of Microsoft, Internet, and industry new technologies. On the other hand: Active X is represented

INTERNET and application integration strategy.

There is a saying: "Active X is the product of OLE and Internet collision, and the Internet has made it a look today."

Today's Active X includes:

Active X documentation

Active X control

COM

Internet tag

Active X Super Link

Active X Conference

Active X server extension

Active X script

Code signature

HTML extension

Movie

Two-first exploration com

Component Object Models (COM) are binary standards for Windows objects. Provide unified, object-oriented for Windows

, Expandable communication protocol. This means that describes the executable code of an object (code of .dll or .exe file) can be performed by other objects. Even if both objects are written in different languages, they can communicate with COM standards.

Personally, COM is the product of Microsoft developed, and most of the concepts proposed by Microsoft are based on CoM.

COM With Microsoft's growth, Microsoft is also proud of COM. Today, Microsoft products have been issued

Exhibition is a software big family. Office Series, Visual Basic, Visual C , Visual J has become

The standard for Windows programming, in order to exchange data between different applications, to achieve the purpose of resource sharing, urgent

An interface rules and protocol are required. Establish a software module to connect to another software module, then describe it

When this connection is established, the two modules can be communicated by the mechanism to become an interface. COM is based

The binary layer is a language-independent interface specification.

Problems exist in data exchange techniques used in:

* Windows API has too large programming "interface" (more than 350 separate functions)

* VBA cannot be used in Win32 environments

* DDE is a complex system for applications, subjects, and projects.

* DLL is full of application

COM features:

* Provides a standard and language-independent approach to Win32 client EXE load and calling Win32 DLL.

* Provides a general purpose method for another EXE of an EXE control. (Can replace DDE)

* Instead of VBX with Active X.

* Provide a new method for the interaction of the application and the operating system.

* Provide expandability, such as Microsoft OLE DB data interfaces for adapting to new protocols.

* Step-step COM (DCOM) allows an EXE to communicate with another EXE different from.

* COM integrates COM, DCOM, MTS, and MSMQ.

1. Basic Design Ideas of COM:

Usually we describe an object is a number of methods and properties that divide them. By inheriting this mechanism to get the method of use

And attribute access to the purpose of data processing. The COM module no longer allows customers to directly call the object's method (

Including attributes and their constructors, destructuring functions, COM only provides a standard global function to access objects. Thus

Separate customers with services. Use the virtual function table (VTBL) between the customer and the server

The memory structure implements a set of pointers that point to virtual functions.

2. How does COM perform data exchange?

Through the interface.

This interface defines a function call method, standard structure-based data transmission technology, as well as some standard function calls.

The interface is a collection of virtual functions, essentially a collection of functions. It is a C class with no data. Is a pure virtual function, right

Ingredients from this class, and provide function code, other functions get the code by calling these functions, all component objects must

There is a interface called IUNKNOW.

IUNKNOWN interface Purpose: Find other interfaces. It has a queryinterface () function that uses a connection

The port ID returns a pointer to the interface. All other interfaces are inherited from IUNKNOWN, so in the interface used

There is query interface ().

Interface iunknown {

PUBLIC:

Begin_INTERFACE

Virtual HResult StdmethodCallType QueryInterface (Refiid Riid,

Void_rpc_far * _rpc_far * ppvobject) = 0;

Virtual Ulong StdmethodCallType AddRef (Void) = 0;

Virtual Ulong StdmethodCallType Release (Void) = 0; End_Interface};

Where addRef () and release () are used to follow those applications that are using interfaces.

All three functions are inherited by all interfaces.

Implementation of the interface:

It can be inherited by multiple inheritance. But the problem encountered with multiple inheritance is: when multiple interface methods symbolic names conflict. Multiple

The interface contains the same name, and the method of different interfaces is different. The compiler only allows programmers to provide a party

Realization of law. It is obvious that the interface is problematic by multiple inheritance.

In the MFC, it is achieved by class nested. The MFC library has a set of macros to automatically implement this process.

The interface_part macro generates a nested class and generates a prototype for a specific interface function and add QueryInterface, addref

And Release prototype.

The Declare_Interface_map macro produces a statement that contains the ID of all class interfaces. CCMDTARGET ::

The externalQueryInterface () function uses this table to get the interface pointer.

3. Another useful interface - class factory (Class Factory)

Class Factory is a class that is used to support special COM interfaces named iClassFactory. IclassFactory

It is derived from iUnknown, its main member function is: createInstance (), what it generates is in COM

We can't call the constructor directly, so I have to make the component to determine how to construct the object, and provide a class factory for this component.

The specific creation process is encapsulated. Use the class factory to create multiple objects. MFC library takes dynamic creation technology

Decisive this problem, a class named ColeObjectFactory can create any classes at runtime. Using DyncReate Macro

Set the standard dynamic creation mechanism. OlecReate macro declares and defines a global object of a ColeObjectFactory class

, Use the specified unique CLSID. In the DLL component, the decomposer DllgetClassObject is set according to Olecreate Macro.

Global variables, find specific class objects, and return to pointers to this object. RegeSteral when the DLL is initialized

Call, in the EXE component, the initialization code calls the static ColeObjectFactory :: registerall function

This function looks for all the objects and calls CoreGisterClassObject to register every object.

The relationship between interface sets, interfaces, interface functions, and attributes.

Personally, the interface set, interface, interface function (method), and attributes have certain correspondences in logical. Pick up

The port set contains multiple interfaces. An interface contains a class of interface functions, each interface function corresponding to a class of properties. Interface letter

The number is what the user is concerned, and the user can change the attribute only if the interface function is used through the interface. Attributes and interface functions are

Abstraction to the component object.

4.Automation & Active X

Automation & Active X is an important part of the Active X component. Active X control is also a small automation service

Worker. Automation let the app tell it what. It reveals properties and methods. If we reveal your own application

All methods and properties of the program, any programming language using the Automation application can be an application

Writing language. I know that there is always a program that is controlled with the most important thing to interact with Automation. Controlled

Applications are called Automation controllers, disclosure methods and properties, called Automation servers. Automation communications actually defines the main relationship. The Lord is an automated client, from the automation component (

Controls). Connect by constructing a component object or establish a connection with existing objects in the already running program

You can initialize the interaction process, and then the client program can call the interface functions in the component program, and will

Some completed interfaces are released.

This means Word, Excel, Access, and VB these support for Automation, can be connected to Auto

Mation compatible components. We can call any controls under Windows with VC (even if it is included in Word or

Other programs can also be written by VC yourself, and use VBA macro to call it.

(1) iDispatch is the core of automation. It collects all internal modules in idispatch :: invoke ()

On the same, like IUNKNOWN and ICLASSFActory, it is completely supported by COM scheduling. From the components

Aspect, we need to have a COM class with an IDispatch interface (including the necessary class factories); from the user

Look, we use standard COM technology to get pointers.

Interface IDispatch: Public IUNKNOWN

{

PUBLIC:

Virtual HRESULT stdmethodcalltype gettypeinfo

Uint itInfo,

LCID LCID,

ITYPEINFO _RPC_FAR * _RPC_FAR * PPTINFO) = 0;

Virtual HRESULT stdmethodcalltype getidsofnames

Refiid RIID,

LPolestr_far * rgsznames,

LCID LCID,

DISPID _RPC_FAR * RGDISPID) = 0;

Virtual HRESULT stdmethcallType Invoke

Dispid DispidMember,

Refiid RIID,

LCID LCID,

Word wflag,

Dispparams_rpc_far * pdispparams,

Variant _rpc_far * pvarresult,

Excepinfo _RPC_FAR * pexcepinfo,

UINT _RPC_FAR * PUAARGERR) = 0;

}

Description: The invoke () function is the most important function for calling the function and properties of the Automation server.

(2) Idispatch implementation:

Components can have several ways to implement IDispatch interfaces. The most common practice is to hand over most of the work to Windows

COM DLL, this can be implemented by calling the COM function CreateStddDispatch, or delegate the invoke call

The ITYPEINFO interface, which handles the type library of the component (Type Library). A type library is a table that allows for this table

The client finds the symbolized name of the object method and attribute in the component. MFC supports type libraries, but in iDispatch's implementation

There is no type library. The IdisPatch is implemented by Dispatch Map. The MFC program is fundamentally

Do not call CreateStddDispatch, it does not use the type library to implement IDispatch :: getidsofname. (3) How does the distribution mapping of MFC related to IDispatch and Invoke member functions?

The distribution map has created a data table inside, and the Invoke function in the MFC can read the table. The control program can get

The iDispatch pointer to the class. And use a pointer array as a parameter to call Invoke. Execution of the MFC INVOKE function

The body will use the class distribution map to decode the supplied pointer, and a member function can be called.

(4) About Variant Type:

Automated customers and components have been used in the Variant type. It is a general data type and is 64-bit data. IDSPATCH:

: INVOKE uses it to deliver parameters and return values.

Begin_Dispatch_map (CWWDDCTRL, COLECONTROL)

// {{AFX_DISPATCH_MAP (CWWDDCTRL)

DISP_PROPERTY_NOTIFY (CWWDDCTRL, "WDLOWLINE", M_WDLOWLINE, ONWDLOWLINECHANGED, VT_R4)

DISP_PROPERTY_NOTIFY (CWWDDCTRL, "WDCAPTION", M_WDCAPTION, ONWDCAPTIONCHANGED, VT_BSTR)

DISP_PROPERTY_NOTIFY (CWWDDCTRL, "WDXMean", M_WDXMean, OnWDXMeanChanged, VT_BSTR)

DISP_PROPERTY_NOTIFY (CWWDDCTRL, "WDYMEAN", M_WDYMEAN, ONWDYMEANCHANCHANCHANGED, VT_BSTR)

DISP_Function (CWWDDCTRL, "SetwDObject", SetwDObject, VT_EMPTY, VTS_I4)

Disp_function (cwwwddctrl, "setwdproper", setwdproper, vt_empty, vts_i4)

Disp_function (cwwwddctrl, "deletelist", deletelist, vt_empty, vts_none)

DISP_Function (cwwwddctrl, "addwdvalue", addwdvalue, vt_empty, vts_r4)

Disp_function (cwwwddctrl, "setambie", setambie, vt_empty, vts_r4 vts_r4 VTS_R4)

END_DISPATCH_MAP ()

2.Active X control

A typical space includes a user interface for design and run, unique iDispatch interface defines the method of controlling controls and genus

Sex, unique iconnectionPoint interface is used for events that can be triggered. In addition, a control can also include

The entire life cycle is supported, as well as support for user interface features such as scraps, drag and drop. From the structure, one

The control is a large number of COM interfaces that must be supported to utilize these features. Active X control is always placed in the capacity

In the server, the space extension is .ocx, but from the perspective of the running module, it is just a standard Windows

DLL file.

Attributes and events are communication usage events between applications and control communication in containers, containers and controls. for

ActiveX control, the event is an IDispatch interface that appears at the container. The underlying mechanism of the event is called the connection point. A connection

The point is the type description of the interface required to communicate with the container, the connection point is not limited to the IDispatch interface, which can also be used any COM

Realization, the control is only the first to take them. ActiveX is an independent object that can arouse and process messages, with unique properties, and multi-threaded

Force, and support two-way communication and messaging between the remaining containers. The most wonderful place inactive x control is to be programmable.

Sexual and gram reusability. It is open to the external environment, which can be used by various programming Hefei programming environment. There are three controls.

Attribute set. (Attribute, object, method)

* This article is selected from: Visual C / MFC Development Guide

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

New Post(0)