What is a COM component?

Source: Internet
Author: User

Com is the abbreviation of Component Object Model.

What kind of software products do users need? This is a multi-choice question, but it is highly efficient and robust. How can a software developer meet users' needs? Upgrade is required
The application does not compromise the backward compatibility with previous versions. System services must be extended without a specific operating system. Object-orientedProgramDesign is obviously a revolutionary change. Object-Oriented Design
We can easily abstract the problematic things to be solved into various types, encapsulate internal actions, and provide only some interfaces. But this does not completely solve our problem. Yesterday I was in programmer magazine.
What Is Oo in the Post-oo age? It should be for components.

COM component (COM component)

Com is a new software development technology developed by Microsoft to make software production in the computer industry more in line with human behavior. Under the com architecture, people can develop various functions
Specific components, and then combine them as needed to form a complex application system. The benefits of this solution are: You can replace the components in the system with new ones, so that you can upgrade and set the system at any time.
Can reuse the same component in multiple application systems; can easily extend the application system to the network environment; COM and language, platform-independent features allow all programmers to make full use of their talents
Write component modules with intelligence and expertise.

Com is a method for developing software components.Components are actually some small binary executable programs that can provide services to applications, operating systems, and other components. Develop custom
COM components are just like developing dynamic, object-oriented APIs. Multiple COM objects can be connected to form an application or component system.
In addition, components can be relinked or compiled at runtime without being relinked.
Programs are removed or replaced. Many Microsoft technologies, such as ActiveX,
DirectX and OLE are built based on COM. Microsoft developers also use COM components to customize their applications and operating systems.

The concept of COM is not only effective in Microsoft Windows. Com is not a big API. It is actually a programming method like structured programming and object-oriented programming. In any operating system, developers can follow the "com method ".

An application is usually composed of a single binary file. After the compiler generates an application, the application will not change until the next version is re-compiled and the new version is released. Changes to the operating system, hardware, and customer needs must be generated after the entire application is regenerated.

This situation has changed. Developers start to separate a single application into multiple independent components. The advantage of this approach is that it can be used with the continuous development of technology
To replace existing components. At this time, applications can gradually improve as new components constantly replace old ones. In addition, you can quickly create new applications by using existing components.

The traditional approach is to split applications into files, modules, or classes, and then compile and link them into a single-mode application. The process of establishing an application with components (called component architecture) is very large.
Different. Similar to a micro-application, a component is a binary program that has been compiled and linked.CodeThe application is packaged by multiple such components. Only one single-mode Application
Binary Code module. Custom components can be connected to other components at runtime to form an application. To modify or improve an application, you only need
To replace it with a new version.

Com, a component object model, describes how to create components and how to use components to create applications.

Advantages of using components:

One advantage of component architecture is that applications can evolve over time. In addition, you can also use components to make it easier and more flexible to upgrade applications, such as application customization, Component Libraries, and distributed components.

The advantages of using components directly come from the ability to dynamically insert or unload them from applications. To implement this function, all components must meet two conditions: first, the components must be dynamically linked;
2. They must hide (or encapsulate) their internal implementation details. Dynamic Links are a crucial requirement for components, while message hiding is a necessary condition for dynamic links.

Supplement: the COM component is created by win
32. It is composed of executable code published in the form of dynamic connection library (DLL) or executable file (exe. Components compiled according to the COM specification can meet all requirements on the component architecture. COM Component
Services can be provided to applications, operating systems, and other components. Custom COM components can be connected with other components at runtime to form an application. COM components can be dynamically inserted or detached.
Application.

Malicious websites can use the COM Component Interface containing vulnerabilities to download and execute Trojans;

To disable the COM component, you can set the kill bit, that is, the IE browser cannot use this component. To put it bluntly, you can set the kill bit
Internetexplorer never calls the disabled COM component when using the default settings, thus disabling the control on the Internet
Explorer. After a vulnerable COM component is disabled, ie cannot call the vulnerable COM component. Hackers can exploit the vulnerable Com group to write web code in IE.
Will not be downloaded.

Possible problems caused by disabling COM components:

When the online playback function is disabled, online videos such as online movies cannot be watched normally;

The components of the online anti-virus function are disabled, leading to the unavailability of the online anti-virus function;

If the components of the online game function are disabled, the online game cannot be played,

If the COM component is disabled, You need to determine the function of the COM component.

How to manually start COM components:

Run -- Regedit -- find the CLSID corresponding to the disabled COM component | Registry Key Value -- Delete the specific value or the entire key.

I have just read the book "COM technology insider" and compiled a FAQ for your reference when learning this book.

This is the first part, including the content of the first three chapters.

Faq1: What is a COM component? Chapter 1 〗

Answer:

COM components are executable code published in the format of Win32 dynamic link library (DLL) or executable file (exe.

COM components are written in accordance with the COM specification

The COM component is a few small binary executable files.

COM components can provide services to applications, operating systems, and other components.

Custom COM components can be connected to other components at runtime to form an application.

COM components can be dynamically inserted or detached from applications

COM components must be dynamically linked

The internal implementation details of COM components must be hidden (encapsulated ).

The COM component must hide the language it implements.

COM components must be published in binary format

The COM component must be upgraded without interfering with existing users.

The COM component can be transparently assigned a location on the network.

COM components declare their existence in a standard way

Faq2: The component is not ......? Chapter 1 〗

Answer:

COM component is not a computer language

The COM component is not a DLL, but the DLL is used to provide dynamic links to the component.

The COM component is not an API function set.

COM component is not a class

Faq3: What is an interface? Chapter 2 〗

Answer:

An interface is a connection between two different objects.

A computer program is connected by a group of functions, which define interfaces of different parts of the program.

The DLL interface is the functions it outputs.

The C ++ class interface is the member function set of the class.

Com interfaces are a group of functions implemented by components that are provided to customers.

In COM, an interface is a memory structure containing an array of function pointers. An array element is a function address implemented by a component.

Faq4: What is the function of the interface? Chapter 2 〗

Answer:

Interfaces are required to connect components to form an application.

In COM, the interface is everything. To the customer, the component is the interface set, and the customer can only deal with the component through the interface.

This interface can protect the system from external changes. This is the embodiment of encapsulation.

The interface enables users to process different components in the same way. This is a manifestation of polymorphism.

Faq5: What is iunknown? Chapter 3 〗

Answer:

Iunknown is an interface.

All com interfaces inherit iunknown.

Iunknown is defined in the unknwn header file of Win32 SDK.

/// Iunknown Definition

Interface iunknown

{

Virtual hresult _ stdcall QueryInterface (const IID & IID, void ** GMM) = 0;

Virtual ulong _ stdcall addref () = 0;

Virtual ulong _ stdcall release () = 0;

}

Faq6: What is the function of QueryInterface? Chapter 3 〗

Answer:

QueryInterface is a member function of iunknown. You can use this function to query whether a component supports a specific interface.

The QueryInterface function returns a pointer to the interface supported by the component.

If the QueryInterface function does not find the interface supported by the component, the return pointer is null.

The QueryInterface function can use if... Then... Else statement, array, hash, and tree.

The QueryInterface function cannot use case statements because the QueryInterface function returns an hresult structure instead of a number.

QueryInterface is also a version mechanism for unblocked processing components. This mechanism allows the new and old versions of components to interoperate.

Faq7: What are the Implementation Rules of the QueryInterface function? Chapter 3 〗

Answer:

The iunknown pointer returned by QueryInterface is always the same.

If the customer obtains an interface, it can always obtain this interface.

The customer can obtain the existing interfaces again.

The customer can return to the starting interface.

If you can obtain a specific interface from an interface, you can obtain this interface from any interface.

Faq8: How is the interface implemented?

Answer:

Com interfaces are implemented using pure abstract base classes in C ++.

A com component can support multiple interfaces.

A c ++ class can use multiple inheritance to implement a component that supports multiple interfaces.

Components support any number of interfaces.

The interface should be immutable. During component upgrade, you should add a new interface instead of modifying the original interface.

The implementation interface should be carefully designed to support various implementations.

Faq9: What is the IID parameter of the QueryInterface function? Chapter 3 〗

Answer:

It is a structure and an interface identifier structure.

The IID identifies the interface required by the customer.

Each interface has a unique interface identifier. Therefore, an interface corresponding to the IID will never change.

The api iid determines the version of the COM component.

Different interfaces have different IDs, including interfaces of different versions.

Faq10: when do I need to create a new COM component version? Chapter 3 〗

Answer:

When a new ID is specified for an existing interface, the condition below should be at least one.

When the number of functions in the API changes.

The order of functions in the interface is changed.

The parameter of a function in the interface is changed.

The order of parameters of a function in the API changes.

The parameter type of a function in the interface is changed.

The Return Value of the function in the interface is changed.

The Return Value Type of the function in the interface is changed.

The meaning of function parameters in the interface has changed

The meaning of the function in the interface has changed

In short, COM is a way to share binary code across applications and languages. Unlike C ++, it advocatesSource codeReuse. ATL is a good example. Code-Level Reuse is good, but can only be used in C ++. It also brings about the possibility of name conflicts, not to mention the constant copying and reuse of code, resulting in Project expansion and bloated.

Windows uses DLLs to share code at the binary level. This is also the key to running Windows programs-reusing kernel32.dll,
User32.dll. However, DLLs is written for C interfaces and can only be used by C or a language that understands C call specifications. ByProgramming LanguageTo implement shared code, rather than by the DLLs
Body. In this case, the use of DLLs is restricted.

MFC introduces another MFC extension DLLs binary sharing mechanism. However, its use is still limited-it can only be used in the MFC program.

Com solves these problems by defining binary standards. That is, com explicitly states that the binary modules (DLLs and exes) must be compiled to match the specified structure. This standard is also accurate
Determines how to organize COM objects in the memory. The binary standards defined by COM must also be independent of any programming language (such as naming modification in C ++ ). Once these conditions are met, you can easily compile
Program language. The binary code generated by the compiler is compatible with the standard. This makes it easier for later users to use the binary code.

In memory, this standard form of COM objects is occasionally used in C ++ virtual functions, so this is why many com codes use C ++. But remember, the language used to write the module is irrelevant because the result binary code is available in all languages.

In addition, COM is not unique to Win32. Theoretically, it can be transplanted to Unix or other operating systems. However, it seems that I have never heard of COM outside of windows.

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.