This time I was thinking about how to use a small program with COM components. I suddenly remembered why I used com during the last interview, instead of using a common DLL? After checking it on Google, many people also asked the same question: using COM to write a program is more troublesome than using a common DLL, but it brings a lot of benefits, especially when developing large software such as AutoCAD, cross-region collaboration is required. "To learn about com, we must first know what the purpose of COM is and what problems it solves. On this basis, Ms provides a variety of extensible COM services and COM programming interfaces. These services and interfaces may not be familiar to a programmer for a lifetime, because the development is so fast. You do not need to be familiar with these interfaces, just like your attitude towards a large number of winapis, and try again later.
All the efforts of COM are to define a protocol for binary interaction. The process is simple and complicated. It is easy for customers who use different languages to write service programs in any language! The language here simplifies the problem, because there are a variety of compilers in each language. How can binary code from different compilers interact?
Taking dll as an example, DLL is an improvement on static connections, bringing about a finer development division of labor and many problems, including how to interact with binary data. This problem is more prominent when the DLL output class. Com provides a very negative and creative solution to solve this problem. In addition, it further introduces how to interact across networks. Then, we propose COM + for Internet server development. The com system integrates a variety of classic design patterns, which can be said to be a more sophisticated C ++.
Com is profound and profound, and several Masters still need half a year of mental fog,
In order to have an open-minded moment. We, the younger generation, need to practice more, but it is never more than COM.
1. COM components classify functions by interfaces for easy organization. dll, especially large DLL, has a large number of functions and is difficult to organize;
2. the COM component is easy to upgrade and maintain, and functions can be expanded. You only need to add interfaces. dll upgrade is difficult and functions cannot be changed at will;
3. the creation and calling of COM has good security, and the DLL does not;
4. the COM component can be easily called between processes, and the DLL is very difficult;
5. the COM component can be easily called in a distributed manner, and the DLL is not possible;
6. COM components have encapsulation, inheritance, and polymorphism object-oriented features, and DLL only has encapsulation;
7. Based on the COM component, a large number of functions are implemented: ActiveX and Ole;
Differences between ActiveX, Ole, COM, ocx, and DLL
People familiar with object-oriented programming and network programming must be familiar with ActiveX, Ole, and COM/DCOM concepts, but the relationship between them is vague to many people. The difference between components and objects should be clarified first. A component is a reusable module that consists of a set of processing processes, data encapsulation, and user interfaces.
Object ). 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 called a container or host) or as an independent process;
2) A component can be composed of one class, multiple classes, or a complete application;
3) Component reuse is a module, and object is code reuse. Currently, popular component models include COM (Component Object Module, object component model)/DCOM (
Distributed COM, distributed object component model) and CORBA (Common Object Request Broker Architecture, public Object Request proxy architecture ). At this point, the topic com related to this article has appeared, while the topic "CORBA" has nothing to do with this article and will not be introduced. Starting from the difference between components and objects, we want to make it clear that com and CORBA are at the bottom of the entire architecture. If you still cannot understand this, let's continue to look at it, finally, you will naturally understand it after looking back.
Now we will introduce ActiveX and Ole
And com. First, let everyone have a general concept. From the perspective of time, Ole was the first to appear, followed by COM and ActiveX. From the perspective of architecture, Ole and
ActiveX is built on com, so COM is the foundation. From the perspective of name, Ole and ActiveX are two trademark names, while com is a pure technical term, this is what we hear
ActiveX and Ole. Since Ole was the first to appear, the "clipboard "(
Clipboard) first solves the communication problem between different programs (the clipboard is used as the data exchange center for copying and pasting operations), but the clipboard transmits "dead" data, application developers have to write and parse code in the data format themselves, so the communication protocol of Dynamic Data Exchange (DDE) came into being, it allows applications to automatically obtain the latest data from each other, but solving the "Data Format" Conversion between each other is still a heavy burden on programmers. Object link and embedding (Object
The birth of linking and embedded, Ole) raised the data exchange of the original application to "Object Exchange", so that the applications not only obtain data but also obtain the application objects of each other, in addition, you can directly use each other's data content. In fact, Ole is Microsoft's composite document technology. Its initial version only targets composite documents, but in later versions, ole2 imports COM. It can be seen that com was born based on the needs of OLE, so although COM is the foundation of Ole, ole was generated before COM. The basic starting point of COM is to allow a software to provide services for another software through a common institution. Com is an Ole
But its first user is ole2, so COM and composite documents have little to do with it. In fact, COM was developed as a technology that was completely irrelevant to composite documents, it has been widely used. In this way,
Microsoft began to use the "color finger" universal platform technology. However, COM is not a product and requires a trademark name. At that time, Microsoft's market experts had chosen Ole as the trademark name, so the COM technology began to be labeled with Ole. Although most of these technologies have nothing to do with composite documents. Microsoft's practice leads to the misunderstanding that ole only refers to compound documents? Or is it not just a single compound document? In fact, Ole is the trademark name of COM, not just a composite document. However, Microsoft may not be able to explain it clearly. It takes considerable effort and time.
As a result, with the development of Internet, Microsoft changed its mind in the spring of 1996 and chose ActiveX as the new trademark name. ActiveX refers to a loosely defined and com-based technology set, while Ole still only refers to composite documents. Of course,
The core technology of ActiveX is com. The biggest difference between ActiveX and Ole is that ole is aimed at the integration between application software and files on the desktop, while ActiveX focuses on providing further network applications and user interaction.
Here, we should have a clear understanding of the relationship between ActiveX, Ole, and COM. com is the most fundamental core technology, so the following focuses on com. It is a novel idea to make the object model completely independent from the programming language. We can understand this in terms of the concepts of C ++ and Java objects. But the so-called com
What is an object? For ease of understanding, we can regard com as a certain (software) packaging technology, that is, regard it as a different part of the software, according to a certain object-oriented form, combine them into processes that can interact with each other and use groups to support databases. COM objects can be written in any language, such as C ++, Java, and VB, and can be implemented using DLL or as an execution file for different process work. When using a COM Object Browser, you do not need to worry about the language in which the object is written, or whether it is executed in a DLL or another process. From the browser side, there is no difference. Such a general processing technique is very useful. For example, the two applications run in coordination by the user can use their common job parts as the interaction between COM objects (of course, the current Ole composite document can also do ). To execute the code downloaded from the web server in the browser, the browser can regard it as a COM object, that is, COM technology is also a standard method for packaging downloadable code (ActiveX controls execute this function ). You can even use com to specify how an application interacts with a local OS, for example, in Windows or Windows
NT uses new APIs, most of which are defined as COM objects. It can be seen that although com originated from the composite document, it can be effectively applied to many software problems. After all, it is a basic technology at the underlying layer. In a word, COM is a language-independent component architecture that allows components to communicate with each other. With the development of computer networks, COM is further developed into a Distributed Component Object Model.
DCOM, which is similar to orb of CORBA, will not be further elaborated in this article. I believe that you will have a clear understanding of the relationship between ActiveX, Ole, and COM/DCOM.
Windows users must be familiar with ActiveX control. It provides a call similar to DLL dynamic link library, however, the only difference between ActiveX and DLL is that ActiveX is not registered and cannot be recognized and used by the system. So what should we do when we get a message that ActiveX is not correctly installed and cannot be used? 1.
Regsvr32 is a regsvr32.exe program under the systemfile folder of windows. It is an ActiveX registration and anti-registration tool provided by windows. It can also be used to easily register ActiveX controls. Its usage is: regsvr32/u/s/n/I
Dllname, where dllname is the ActiveX control file name. It is recommended that you copy the parameter to the system folder before installation to make the following sense:/U-anti-registration control
/S-no matter whether the registration is successful or not, the prompt box/C-console output/I-Skip control options are not displayed for installation (different from registration)/n-do not register the control, this option must be used with the/I option. For example, the author wants to register amovie. OCX control
Regsvr32 amovie. ocx. You only need to use regsvr32/u amovie. ocx for anti-registration. 2. Registration of ActiveX in the registry is nothing more than recording some information in the Windows registry, such
Flash objectcontrol, we can run the regedit.exe registry editing program, use keywords to search, and then export the Registry obtained after the search to a reg registry file, copy the corresponding activex file to the Windows system folder (generally, the activex file name is OCX and installed in the Windows system folder, finally, on the machine where ActiveX is to be installed, double-click to import the exported registry file to complete the installation.
ActiveX, Ole, and COM are some technical standards of Microsoft. Ole grew to ActiveX, and then to com.
OCX, DLL is the extension. ActiveX has two extensions: OCX and DLL. In fact, you can change their extension names.
Com, as an ActiveX update technology, may also contain DLL files or dynamic link libraries. It mainly loads some functions and can be dynamically loaded. In the future, the ideal application model of COM is Web (the condition is that the network speed is fast enough). In the future, there should be no customer application software, the client only has a browser, and the browser is the operating system. The client downloads and uses the browser. Of course, all the downloaded modules have independent functions. The modules with independent functions are COM components, which cannot be used in general DLL.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/tjulmy/archive/2008/06/21/2573097.aspx