COM component and DLL file differences

Source: Internet
Author: User
Tags ole

Go The difference between COM components and DLLs

2014-8-14 Read 169 comments 0

COM English is the Component Object model (Component object models), which is the standard for Microsoft production software components.

It is a specification for constructing binary-compatible software components that can communicate directly with each other, regardless of the language in which the component is written, as long as the COM specification is followed. The COM specification is proposed mainly to satisfy:

1. Rapid development of the program, can be a large project into several COM components at the same time development.

2. You can insert or unload COM components dynamically.

3. You can hide or encapsulate implementation details inside a COM component.

COM components can be written in different languages, but communication between COM components is done through the interface of the component, com The implementation of the component interface is uniform, and it takes the form of a virtual function table (VTBL). The virtual function table contains a set of pointers to the component functions that we can use to get the memory address of the component function we want to communicate with. a DLL(dynamic-link library) is a collection of modules that contain functions and data. It can export data and can also export functions for other DLLs to call. DLL loading can be done in both static and dynamic links.

1. Static link compiles the DLL module to be linked in binary form into other modules.

2. Dynamic linking means that the calling module loads the DLL at run time, uses the LoadLibrary function or the LoadLibraryEx function to load the DLL into the address space of the process, and calls the GetProcAddress function to get the address of the exported DLL function.

Advantages of dynamically loading DLLs:

1.DLL saves memory and reduces switching. By sharing a single copy of a DLL in memory, multiple processes can use one DLL at a time. In contrast, for each application built with a static-link library, Windows loads a copy of the library code in memory for it.

2.DLL can save disk space. Multiple applications can share a copy of a DLL on a disk. In contrast, every application built with a static link library needs to have the library code linked to the program file image as a separate private copy.

DLL's relationship to com: COM is a specification, a DLL that is implemented as a COM specification can be considered a COM component.

For example, the Active X control project that we built with MFC is described in the interface encapsulation by IDL, so it can be considered a COM component. And from the above description of COM and DLLs you can see that the interface of a COM component is a set of functions with specific specifications, so COM components can not be considered a DLL, but the DLL is not necessarily a COM component.

the biggest difference between COM and DLL is that the DLL is called by the function collection is the programming language related like VC must add extern "C" ... COM is provided to the user in interface way is a binary call specification, is not related to programming language, it uses the IDL interface definition language to describe their own use of class inheritance to implement their own functions and methods. DLL only DLL a situation, the inside can arbitrarily define the function is unrestricted, can only run on this machine and COM has DLL and EXE two existence situation: COM in the DLL must be exported four functions:

Dllgetobjectclass,dllregisterserver, Dllunregisterserver,dllunloadnow These four functions each have a role, some are provided to the COM manager, through the CLSID and IID to use, Some are available for registration machines. COM combined with MTS, is COM +, is the advanced version of DCOM, provides a more powerful and secure distributed COM services, DCOM runs on different machines with proxy and stub to implement the local mapping of the remote interface The two are the same from the execution speed. But start the speed DLL faster than COM!

I think you should know the concept of class libraries and frameworks (most typically MFC), which provide source-level reuse, which means that class libraries are distributed as source code, and that the users of class libraries (for example, we use MFC to develop applications) add implementation code to their projects, and then compile links, This time the source code in the class library becomes part of your application, and in the future if the class library designers re-modify their class libraries, then your application will need to recompile the link to your application, which is cumbersome for upgrades to your application that are already in the hands of the end user. And an end-user on the machine may have many programs using the same class library in the same class, there will be some extra code!
This needs to provide a mechanism to solve the above problem, it is a feasible way to wrap your reusable code in the form of a DLL, to export some classes, global functions, data, etc. that you need to provide to third parties in this DLL, so that you can keep a copy of your DLL on the end user's machine. Other applications can implement code sharing by calling the elicit function in your DLL, so that if you later upgrade your DLL (keeping the interface intact), the end user can just get this new DLL to overwrite the old DLL without changing anything to keep the program up to date, And because there is only one copy of the code, the space used at run time is less than the program developed using the class library.
However, the above approach to using DLLs is flawed, as each compiler joins some of its own unique language features. such as DLL I was developed using Visual C + +, there is exception handling code, and now I use this DLL in Borland C + +, then it will not be able to catch these exceptions, for example, if the DLL exported a class, While this class adds some member variables to the new DLL (that is, the memory of the class is increased), an application that uses the old DLL instead of a new DLL on the end user's machine will have an illegal operation if the link is not recompiled because C + + The compilation model requires the application at compile time needs to know the object occupies the space, originally used the old DLL's application because has not been recompiled the link, it recognizes the original DLL's class object size, the end user machine replaced the new DLL, The old application will have an illegal operation when accessing these new member variables. In fact, DLL has many other flaws!
Based on these, we need a better reuse mechanism (at the binary level), under Windows, a large number of non-COM-owned. Its basic idea is that it realizes the separation between the real interface and the code implementation, and it is not is divided into in-process components (compiled links into DLLs or OCX files, essentially, one interface with no interface) and out-of-process components (compiled linked to EXE files), these components will provide some interfaces for third-party calls. Other knowledge about COM if you want to talk about it is voluminous, you can read the relevant books.

I've been thinking about a small program that needs to take advantage of COM components, and suddenly think about the last time I went to an interview. Why should I use COM instead of a generic DLL when I was developing AutoCAD? To Google, a lot of people asked the same question: "COM to write programs than ordinary DLL trouble, but the benefits are much greater, especially in the development of large software like AutoCAD, need to work across regions. "Learning com, first to know what the purpose of COM is, it solves a kind of problem, on this basis, MS provides a variety of extensible COM services, COM programming interfaces. These services and interfaces I'm afraid a programmer will never know the whole life, because development is so fast. There is no need to be familiar with these interfaces, like a large number of Win API attitude, use the time to check the help.

The various efforts of COM are in the provision of a binary interaction protocol. It's easy to say, it's quite complicated to do, and it's hard to make a service program written in any language by a customer in a different language! Speaking here, the language still simplifies the problem, because each language also has a variety of compilers, how does the binary code of different compilers interact?
In the case of DLL, DLL is a kind of improvement to static connection, bring a finer development division of labor, also bring a lot of problems, in which there is the problem of how to interact with binary. This problem is more pronounced when the DLL output class. COM to solve this problem put forward a very negative creative solution, not only so, further extension, proposed how to cross-network interaction. COM + is then presented for development of Internet servers. The COM system incorporates a variety of classic design patterns, which can be said to be a more capable C + +.

COM profound, a number of masters still need half a year of mental fog, Fang can have enlightened when. We are the younger generation, but also need to cultivate more, but it is not just com "

1, COM components to the function of the interface classification, easy to organize; DLLs especially large DLLs, functions of a large heap, difficult to organize;

2, COM components easy to upgrade maintenance, function expansion, just add interface on the line; DLL upgrade is difficult, function can not be arbitrarily changed;

3, COM Create call has a good security, DLL does not;

4, COM components can easily implement inter-process calls, DLL is very difficult;

5, COM components can easily implement distributed calls, DLL is not possible;

6, COM components have encapsulation, inheritance, polymorphism of object-oriented features, DLLs only encapsulation;

7, on the basis of COM components to achieve a large number of functions: activex,ole, etc.;

The differences between Activex, OLE, COM, OCX, and DLLs

People who are familiar with object-oriented programming and network programming must not be unfamiliar with the concepts of ActiveX, OLE, and com/dcom, but what is the relationship between them is rather vague for many. Between the specific descriptions of their relationships, we will first identify the difference between the component (Component) and the object. A component is a reusable module that is a business object (Rules object) that consists of a set of processes, data encapsulation, and user interfaces. The component looks like an object, but does not conform to the academic definition of the object. Their main differences are: 1) A component can be used in another application called a container (sometimes referred to as a bearer or host) or as a standalone process; 2) A component can consist of a class, or it can consist of multiple classes, or a complete application; 3) A component is reused for a module. And the object is code reuse. Now, the more popular component models are the COM (Component objiect Module, Object component Model)/dcom (distributed COM, distributed object Component model) and CORBA (Common object Request Broker Architecture, public object request broker architecture). Here, there has been a topic related to this article COM, and CORBA is irrelevant to this article, not to be introduced. The reason from the difference between the components and objects, is to let everyone clear that COM and CORBA is at the bottom of the entire architecture, if temporarily not understand, may wish to continue to look down, and finally look back at the natural understanding. Now you start to explain the relationship between ActiveX, OLE, and COM. First, let everyone have a general concept, from the perspective of time, OLE is the earliest, and then COM and ActiveX, from an architectural point of view, OLE and ActiveX are built on COM, so COM is the basis of, from the name perspective, OLE, ActiveX is a two trademark name, and COM is a purely technical term, which is why you hear more about ActiveX and OLE. Since OLE is the first to appear, from OLE, since the Windows operating system became popular, the "clipboard" (Clipboard) first solved the communication problem between different programs (the Clipboard acts as a data exchange center for copying and pasting), but the clipboard passes "dead" Data, the application developer has to write and parse the code of the data format, so the communication protocol of Dynamic Data exchange (Exchange,dde) comes into being, which allows the application to automatically get the latest data from each other, but solves the "data format" between each other. Conversion is still a heavy negative for programmersResponsibility The creation of the object's link and embedding (Object linking and Embedded,ole) increases the data exchange of the original application to "Object Exchange", so that the program not only obtains the data but also obtains each other's application objects, and can directly use each other's data content, In fact, OLE is a composite document technology from Microsoft, and its original version was aimed only at compound documents, but in subsequent versions of OLE2, COM was imported. As a result, COM was born to the needs of OLE, so although COM is the foundation of OLE, the production of OLE is before COM. COM's basic starting point is to have a software service for another software through a common organization. COM is born in response to Ole's needs, but its first consumer is OLE2, so there is not much relationship between COM and composite documents, in fact, later COM as a completely unrelated to the composite document technology, began to be widely used. As a result, Microsoft has started to "meddle" with common platform technologies. But COM is not a product, it requires a trademark name. At that time, Microsoft's market experts had chosen OLE as the trademark name, so the use of COM technology began to affix the OLE label. Although the vast majority of these technologies are not related to compound documents. Microsoft's approach has made it a misconception that OLE refers to compound documents only? Or does it just mean compound documents? In fact, OLE is the brand name of COM, and nature does not refer to compound documents. But Microsoft itself may not be able to explain that it takes considerable effort and time. So, with the development of the Internet, in the spring of 1996, Microsoft changed its mind and chose ActiveX as the new trademark name. ActiveX refers to a loosely defined, COM-based collection of technologies, while OLE still refers to compound documents only. Of course, the most core technology of ActiveX is COM. The biggest difference between ActiveX and OLE is that OLE is for integration between application software and files on the desktop, while ActiveX is primarily for user interaction with further network applications. Here, we should have a relatively clear understanding of the relationship between ActiveX, OLE and COM, COM is the most fundamental core technology, so the following focus on COM. It is a very novel idea to make the object model completely independent of the programming language. This is something we can learn from the concepts of C + + and Java objects. But what is the so-called COM object? For the sake of understanding, COM can be regarded as a kind of (software) packaging technology, that is, as a different part of the software, in accordance with a certain object-oriented form, combined into a process can be interactive and group support Library. COM objects can be used in C + +, Javaand VB, and any other language written, and can be used as a DLL or as a different process to work on the form of the implementation of the file. A browser that uses a COM object does not need to worry about what language the object is written in, or whether it is executed in a DLL or another process. From the browser side, there is no difference. Such a common processing technique is very useful. For example, two apps that are run by the user can be implemented as interactions between COM objects (and, of course, the OLE compound document now). To execute code downloaded from a Web server in a browser, the browser can think of it as a COM object, which means that COM technology is also a standard way to package downloadable code (which is what ActiveX controls do). Even methods of interacting with the native OS can be specified using COM, for example, in Windows and Windows NT, where new APIs are used, most of which are defined as COM objects. It can be seen that COM, although originated from compound documents, but it is effective for many software problems, it is at the bottom of the basic technology. In a word, COM is a language-independent component architecture that allows components to communicate with each other. With the development of computer network, COM further developed into a distributed Component Object model, this is the DCOM, it is similar to the CORBA Orb, this article will not do further elaboration. I believe you have a clear understanding of the relationship between ActiveX, Ole, and com/dcom through the above narrative.

        people using Windows must be familiar with ActiveX control, which provides a call similar to DLL dynamic-link libraries, However, the only difference between it and the DLL is that ActiveX does not register and is not recognized and used by the system. So, when we get a message that ActiveX is not properly installed and cannot be used, what about installing ActiveX? 1. The Regsvr32 program method has a regsvr32 under the Windows System folder. EXE program, which is the Windows own ActiveX registration and anti-registration tool. It is also very convenient to register the Acitvex control, which is used as: regsvr32/u/s/n/i dllname, dllname where dllname is the file name of the ActiveX control, It is recommended that you copy to the system folder before installing the parameter has the following meanings:/U-Anti-registration control/S-no prompt box is displayed regardless of registration success or not-console output/I-skip control option to install (unlike registration)/n-Do not register control, this option must be used with the/I option, such as author To register a amovie. OCX control, then enter Regsvr32 amovie. OCX, you can only use regsvr32/u Amovie when you want to counter-register it. OCX on the line. 2. Registry method so-called register Acitvex, is nothing more than to record some information in Windows registry, such as Shockwave Flash Object control, we can run regedit. EXE Registry Editor, search with keywords, then export the search to the registry to a reg registry file, and then copy its corresponding ActiveX files to the Windows System folder (the general ActiveX file name OCX, Installed in the Windows System folder), and then double-click Import the registry file you just exported on the machine where you want to install ActiveX to complete the installation.

Activex,ole,com are some of Microsoft's technical standards. OLE Older later developed into an ActiveX, and then later developed into a COM ocx,dll extension. ActiveX has two extensions, OCX and DLL. In fact, you can swap their extension names. COM as an update technology for ActiveX, it is also possible that the extension is a DLL DLL file and possibly a dynamic-link library. It is mainly loaded with some functions that can be loaded dynamically. The future of COM is a more ideal application pattern is the Web (the condition is fast enough), the future of software should not exist customer application software, the customer only browser, browser is operating system, customers while downloading side use, of course, download is a functional independent module. And these independent modules are COM components, the general DLL is not so used.

COM component and DLL file differences

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: 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.