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? Ensure that the backward compatibility with previous versions is not damaged during application upgrade. System services must be extended without a specific operating system. Object-orientedProgramDesign is obviously a revolutionary change. Using an object-oriented design method, we can easily abstract the problematic things to be solved into various types, and encapsulate and hide internal actions to provide only some interfaces. But this does not completely solve our problem. Yesterday I saw in programmer magazine that today is the post-oo era. What WILL oo be like in the future? 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 a variety of unique functional components and then combine them as needed to form a complex application system. The benefits are as follows: new components in the system can be replaced to upgrade and customize the system at any time; the same component can be reused in multiple application systems; the application system can be easily extended to the network environment; COM and language, platform-independent features allow all programmers to make full use of their talents and expertise to write component modules.
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. Developing custom COM components is like developing dynamic and object-oriented APIs. Multiple COM objects can be connected to form an application or component system. In addition, components can be removed or replaced at runtime without being relinked or compiled. 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 replace existing components with new components as technology continues to develop. 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. It is very different from the process in which components build applications (called component architecture. 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. A single-mode application has only one 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 one of the components that constitute the application 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, components must be dynamically linked; second, they must be hidden (or encapsulated) internal implementation details. Dynamic Links are a crucial requirement for components, while message hiding is a necessary condition for dynamic links.
Supplement: COM components consist of executable code published in the form of Win 32 dynamic connection library (DLL) or executable file (exe. Components compiled according to the COM specification can meet all requirements on the component architecture. 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.
Malicious websites can use the COM Component Interface containing vulnerabilities to download and execute Trojans;
Disabling the COM component generally means setting the kill bit, that is, the IE browser cannot use this component. Generally speaking, by setting the kill bit, internetexplorer never calls the disabled COM component when using the default settings, thus disabling the control to run in Internet Explorer. After a vulnerable COM component is disabled, ie cannot call a vulnerable COM component. Hackers can exploit a vulnerable Com group to write web code that cannot be executed in IE, trojans 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 and 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 the shared code, rather than the DLLs itself. 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 also specifies exactly 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, these modules can be easily accessed from any programming 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.