Possible problems with the understanding of COM (Component Object model) and the advantages of components and benefits

Source: Internet
Author: User

What kind of software products do users need? This is a multiple-choice, but efficient, robust is sure to be selected. What does a software developer do to satisfy a user's needs? You must ensure that the upgrade application does not break backward compatibility with previous versions. You must extend the system service without relying on a specific operating system. Object-oriented programming is clearly a revolutionary change. Using object-oriented design method, we can easily abstract the problem things to be solved into various classes, and hide the inner actions, and provide only some interfaces. But this does not completely solve our problem. I saw it in the programmer's magazine yesterday, and now it's the post-oo era, what's the future of OO? It should be a component-oriented bar.

COM Component (COM component)

COM is a new software development technology developed by Microsoft for the software production of computer industry which is more in line with the human behavior mode. Under the COM architecture, people can develop a variety of functional components, and then combine them as needed to form a complex application system. The benefits are manifold: the components in the system can be replaced with a new one so that the system can be upgraded and customized at any time, and the same component may be reused in multiple application systems, and the application system can be easily extended to the network environment; COM and language, Platform-independent features enable all programmers to give full play to their talents and expertise to write component modules; and so on.

COM is a way to develop software components. Components are actually small binary executable programs that can provide services to applications, operating systems, and other components. Developing a custom COM component is like developing a dynamic, object-oriented API. Multiple COM objects can be connected to form an application or component system. and components can be removed or replaced at run time, without being relink or compiled by the application. Many of Microsoft's technologies, such as ActiveX, DirectX, and OLE, are built on COM. And Microsoft developers are also using a lot of COM components to customize their applications and operating systems.

COM contains concepts that are not only valid under the Microsoft Windows operating system. COM is not a large API, it is actually like structured programming and object-oriented programming methods, but also a programming method. In any operating system, developers can follow the "COM method".

An application is usually made up of a single binary file. After the compiler builds the application, the application generally does not change until the next version is recompiled and the newly generated version is released. Changes to the operating system, hardware, and customer requirements must wait until the entire application is regenerated.

The situation has changed now. Developers began separating individual applications into separate, discrete parts, and components. The advantage of this approach is that it can replace existing components with new ones as technology continues to evolve. Applications at this time can evolve as new components replace older components. and using the existing components, users can also quickly establish a new application.

The traditional approach is to split the application into files, modules, or classes, and then compile and link them into a single-mode application. It differs greatly from the process in which the component builds an application, called the component architecture. A component is similar to a micro-application, which is a binary code that has been compiled and used by the link, and the application is packaged with multiple such components. Single-mode applications have only one binary code module. Custom components can be connected to other components at run time to form an application. When you need to modify or improve an application, simply replace one of the components that make up this application with a new version.

COM, the Component Object model, is a specification of how to build a component and how to build an application through a component, explaining how to dynamically update components alternately.

Advantages of using components:

One advantage of the component architecture is that applications can evolve over time. In addition, the use of components has the advantage of making the upgrades more convenient and flexible for applications, such as customization of applications, component libraries, and distributed components.

The advantages of using components come directly from the application that can be inserted or unloaded dynamically. To achieve this, all components must meet two conditions: first, the components must be dynamically linked, and secondly, they must hide (or encapsulate) their internal implementation details. Dynamic linking is a critical requirement for components, and message hiding is a necessary condition for dynamic linking.

Supplemental: COM components are composed of executable code that is published in the form of a win 32 dynamic Connection Library (DLL) or executable file (EXE). Components that follow the COM specification will be able to meet all requirements for the component architecture. COM components can provide services to applications, operating systems, and other components, and custom COM components can be connected to other components at run time to form an application; COM components can dynamically insert or unload applications.

Malicious Web sites can take advantage of the vulnerability of the COM component interface, download Trojan, and execute;

Disabling a COM component generally refers to setting the kill bit, ie browser can not use this component, popular: By setting the kill bit, you can make InternetExplorer use the default settings will never invoke the disabled COM components, thus preventing the control in the Internet Run in Explorer. After disabling the vulnerable COM component, IE cannot invoke the vulnerable COM component; The hacker uses the vulnerable COM group, the code written in the Web page can not be executed in IE, Trojan, etc. will not be downloaded.

Disabling a COM component can cause problems:


The components of the online playback feature are disabled, which can cause online videos such as online movies to not be viewed properly;

Online anti-virus components are disabled, will lead to online anti-virus can not be used;

The components of the online gaming feature are disabled, which can cause online games to not play,

After the COM component is disabled, it needs to be judged by the specific COM component functionality.

To manually start the COM Component action method:

Run--regedit--find the corresponding clsid| registry key value for the disabled COM component--delete the specific value, or the entire key.

Just finished reading the "COM Technology Insider" a book, organized a FAQ for everyone in the study of this book reference.



This is the first part, which contains the contents of the first 3 chapters.


FAQ1: What is a COM component? Chapter I.

Answer:

COM components are composed of executable code published in the form of a WIN32 dynamic-link library (DLL) or executable (EXE).

COM components are written in accordance with COM specifications

COM components are small binary executables

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

Custom COM components can be connected to other components at run time to form an application

COM components can dynamically insert or unload applications

COM components must be dynamically linked

COM components must hide (encapsulate) their internal implementation details

The COM component must hide the language it implements

COM components must be published in binary form

COM components must be upgraded without interfering with existing users

COM components can be transparently reassigned on the network

COM components declare their presence in a standard way



FAQ2: component is not ...? Chapter I.

Answer:

COM components are not a computer language

COM components are not DLLs, but are capable of providing dynamic links to components using DLLs

A COM component is not a set of API functions.

COM component is not a class

FAQ3: What is an interface? Chapter II

Answer:

An interface is the provision of a connection between two different objects.

A computer program is connected by a set of functions that define the interfaces of different parts of the program.

The interface of a DLL is the function that it outputs.

The interface of a C + + class is the set of member functions for that class.

The interface in COM is a set of functions that are implemented by the component and provided to the customer.

In COM, an interface is a memory structure that contains an array of function pointers, and the array element is a function address that is implemented by the component.



FAQ4: What is the function of the interface? Chapter II

Answer:

There is an interface for how components connect them together to form an application.

In COM, the interface is everything, to the customer that the component is the interface set, customers can only through interfaces and components to deal with.

Demonstrates that the interface protects the system from external changes. This is the embodiment of encapsulation.

Interface enables users to work with different components in the same way. This is the manifestation of polymorphism.

FAQ5: What is IUnknown? Chapter III

Answer:

IUnknown is an interface.

All COM interfaces inherit IUnknown.

The IUnknown definition is in the UNKNWN header file in the WIN32 SDK.

Definition of IUnknown

Interface IUnKnown

{

Virtual HRESULT __stdcall QueryInterface (const iid& iid,void **PPV) = 0;

Virtual ULONG __stdcall AddRef () = 0;

Virtual ULONG __stdcall Release () = 0;

}



What is the role of the Faq6:queryinterface function? Chapter III

Answer:

QueryInterface is a member function of the IUnknown that customers can use to query whether a component supports a particular interface.

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

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

The QueryInterface function can be implemented using IF...THEN...ELSE statements, arrays, hash lists, and trees.

The QueryInterface function cannot use the case statement because the QueryInterface function returns an HRESULT structure rather than a number.

QueryInterface is also a mechanism for disposing of component versions without encapsulation. This mechanism allows the new and old versions of components to interoperate.

What are the implementation rules for the Faq7:queryinterface function? Chapter III

Answer:

The IUnknown pointers returned by QueryInterface are always the same.

If the customer gets an interface, it always gets this interface.

Customers can again get the interfaces they already have.

The customer can return to the start interface.

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

FAQ8: How is the interface implemented?

Answer:

COM interfaces are implemented in C + + with pure abstract base classes.

A COM component can support multiple interfaces.

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

A component can support any number of interfaces.

interface should have invariance. Instead of modifying the original interface when the component is upgraded, add a new interface.

A well-designed interface is designed to enable it to support a variety of implementations.

What is the parameter IID of the Faq9:queryinterface function? Chapter III

Answer:

It is a structure, 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 interface IID determines the version of the COM component.

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

FAQ10: When do I need to build a new COM component version? Chapter III

Answer:

When you specify a new ID for an existing interface, you should have at least one set of conditions below.

When the number of functions in the interface changes.

The order of functions in the interface has changed.

The parameters of a function in an interface change

The order of the parameters of a function in the interface has changed

The type of the parameter of a function in an interface changes

The return value of the function in the interface has changed

The return value type of the function in the interface has changed

The meaning of the function in the interface changes

The meaning of functions in an interface has changed

Simply put, COM is a way to share binary code across applications and languages. Unlike C + +, it advocates source code reuse. ATL is a good example. Source-level reuse is good, but only for C + +. It also brings the possibility of name collisions, not to mention the continual copying and reuse of code that leads to engineering bloat and bloat.

Windows uses DLLs to share code at the binary level. This is also the key to the operation of Windows programs-reuse Kernel32.dll, user32.dll and so on. But DLLs are written for C interfaces and can only be used by C or the language that understands the C call specification. The programming language is responsible for implementing shared code, not the DLLs itself. In this way, the use of DLLs is limited.

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

COM solves these problems by defining binary standards, where COM explicitly states that binary modules (DLLs and exes) must be compiled to match the specified structure. This standard also sets out exactly how COM objects are organized in memory. The binary standard for COM definitions must also be independent of any programming language (such as named adornments in C + +). Once these conditions are met, it is easy to access these modules from any programming language. The compiler is responsible for the resulting binary code compatible with the standard. This makes it easier for later people to use these binary codes.

In memory, this standard form of COM objects is occasionally used in C + + virtual functions, so that's why many COM code uses C + +. But remember, the language used to write the module is irrelevant because the resulting binaries are available for all languages.

In addition, COM is not Win32 specific. Theoretically, it can be ported to UNIX or other operating systems. But I never seem to have heard of COM outside of Windows.

Related Article

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.

Tags Index: