COM principle and application----naming and binding technology

Source: Internet
Author: User
Tags ole

1. How to create COM objects

Clients can create COM through the CoCreateInstance function, and must know some basic things about the object before it is created, such as the CLSID of the object or the ProgID of the object.

Another object creation method is created by a moniker (moniker), which is the use of object naming and binding techniques (i.e., name technology).

2, the status of the name technology

Name technology is not the basic core of COM, but it is also an important part of COM architecture, which provides a more flexible link for client programs and component programs. The success of OLE makes the name technology widely used, and in the continuous development of OLE and COM, the name technology has played its powerful extension features, the asynchronous moniker implementation makes it go beyond OLE application scope, can better apply to the network environment, especially the Internet network, Embodies the strong vitality of the name technology.

Name technology allows clients to access component objects in a symbolic manner without having to access COM objects through the CLSID and the class factory. Name Technology not only provides a symbolic representation of COM objects, but it fully embodies some important concepts of object-oriented software system, and even can learn it as a technology of software architecture.

3, COM name technology includes two aspects: naming technology and binding process

4. Name Object

The core of the name technology is the moniker, COM uses the term "moniker" to represent the moniker, which is itself a COM object. The moniker provides a symbolic representation of the component object, and it also encapsulates the component objects in a comprehensive way, and the client simply creates the corresponding moniker and then uses the binding function of the moniker to get the Component object. A moniker can automatically make a Component object run from the passive state, so the moniker is also known as a permanent smart name (persistent intelligent names).

The moniker encapsulates all state processing of the Component object, so the client can process the moniker in a uniform way, even if the new Component object is referenced, and the client code does not have to make any changes.

5. File name and name object

A file moniker is a basic moniker, and the file name is also pointed to the actual file by the symbolic string name. The file name represents a disk file, the filename itself is not an object, it represents only the path of the file object, so the filename does not have an intelligent attribute.

The permanent state of a COM object can be an entire file, or it can be part of a file.

Although the moniker plays the same role as the filename, the function of the moniker is much more powerful. First, it expresses a much broader range of objects, in addition to the general file object, it can also express some of the contents of the file, second, the moniker has an intelligent feature, that is, it can be dynamic objects automatically into the running state, the moniker found with the permanent status associated with the running code, and start the code, The process of using the initialization of an object to get the object into operation is the binding operation of the moniker.

6. The binding process of the name object

The moniker implements the standard COM interface imoniker, and the client program obtains the component object through the IMoniker interface.

Client access to component objects by moniker can be divided into two steps: First, get the moniker; second, perform the binding operation of the moniker (the function bindtoobject the IMoniker interface), and the result of the binding process is the interface pointer to the Component object.

There are two ways for clients to get moniker: First, invoke COM API functions such as MkParseDisplayName and Createfilemoniker; second, the interface member functions of other objects are passed over, or through other data transmission mechanisms, such as through the Clipboard or drag-and-drop operation.

7, IMoniker

(1) Name management function: IsEqual, Hash, IsRunning, GetTimeOfLastChange.

(2) Binding function: BindToObject, bindtostorage.

(3) Compound moniker management functions: Reduce, Composewith, Enum, Inverse, Commonprefixwith, Relativepathto, Issystemmoniker.

(4) Name analytic function: GetDisplayName, MkParseDisplayName.

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.