The difference between OCX and DLL

Source: Internet
Author: User
Tags ole

Transferred from: http://blog.csdn.net/scucj/archive/2006/06/29/852181.aspx

The difference between OCX and DLL

First, about the DLL introduction

DLL, the dynamic link library, the abbreviation for the Dynamics link libraries, is a collection of modules containing functions and data that can be shared by other applications. DLL, as an executable file that shares a library of functions, encapsulates one or more functions that have been compiled and linked. Multiple processes can use a single DLL at the same time to share a copy of the DLL in memory.   DLLs also help to share data and resources. It and the executable file (. EXE files are very similar, they differ in that the DLL contains executable code but cannot be executed alone, directly or indirectly by the application that needs to use it. 

In layman's words, many applications in the Windows operating system are not a complete executable file, and their proper execution requires the invocation of some relatively independent dynamic-link libraries, or DLL files. An application can call multiple DLL files, and a DLL file may also be shared by several applications, such that DLL files are called shared DLL files.  DLL files are typically present in the C:\Windows\System directory or in the directory or subdirectory where the application resides.

Refer to the dynamic link, first explain the static connection. What is a static connection? During a program link, the compiled binaries need to be linked to the target code, the linker obtains all the referenced functions from the static link library, and the referenced functions are placed with the code in the executable file. Then the static connection of the DLL refers to the linker to copy the code of the referenced library function into the executable module (. dll file or. exe file) that invokes the DLL.


What is a dynamic link?

Dynamic linking is the information required by the system to allow executable modules (. dll files or. exe files) to be included in the runtime, only the executable code that locates the DLL functions. In other words, executable modules (. dll files or. exe files) load these modules at run time (i.e. the required modules map to the address space of the calling process). 



So what are the advantages of dynamic linking versus static connections?

(1) Save memory and reduce switching operation. With dynamic linking, multiple processes can use a single DLL at the same time to share a copy of the DLL in memory. With static linking, each application contains the code of the referenced library function, and Windows must load a copy of the code of the referenced library function in memory for each application.

(2) Save disk space. With dynamic linking, only one copy of the DLL is required on disk. With static linking, each application contains code for the referenced library function.
(3) easier to upgrade. With dynamic linking, when functions in a DLL change, there is no need to recompile or relink the application that uses them as long as the parameters and return values of the functions do not change. With static linking, you need to relink to build the application when the function changes.
(4) Support multi-language programs, as long as the program follows the calling convention of functions, programs written in different programming languages can call the same DLL function.
(5) provides a mechanism for extending the MFC library classes. You can derive classes from existing MFC classes and place them in an MFC extension DLL for use by MFC applications.
(6) Support multi-language program, and make the international version of the creation easy to complete. It is much easier to create an international version of an application by putting resources into a DLL. You can place strings for each language version of your application in a separate DLL resource file and have the appropriate resources loaded for different language versions. 


The DLLs contain the definitions of the following two classes of functions:

Export functions: These functions are called by executable modules (. dll files or. exe files).

Intrinsic functions: These functions are only called from the DLL in which they are defined. DLL also exports data. However, the data is used by the corresponding function.



Dynamic link at load time: The executable module performs an explicit call toThe functions in the DLL can be called in the following ways:
export the DLL function. Create an import library for the DLL, and then link the DLL to the application. When you load an application, the import library provides the information needed to load the DLL and find the exported DLL functions.

Runtime dynamic linking: When the DLL is loaded at run time, the executable module uses the LoadLibrary function or the LoadLibraryEx function. The executable module calls the GetProcAddress function to get the address of the exported DLL function. When linking, Windows searches for a pre-installed set of DLLs, such as the Performance Library (Kernel32.dll) and the Security Library (User32.dll). 


Windows then searches for DLLs in the following order:

1. The directory where the executable program for the current process resides.
2. Current directory.
3.Windows system directory. (The GetSystemDirectory function gets the path to the Windows system directory.) )
4.Windows directory. (The GetWindowsDirectory function gets the path to the Windows directory.) )
The directory listed in the 5.PATH environment variable. Note: The LIBPATH environment variable is not used for search. 

The DLL has a special entry point (DllMain function) that runs when attaching and detaching processes and threads. This behavior allows you to create and destroy data structures as needed. File types with the. ocx,. cpl, and. drv file name extensions are also DLLs, although the file name extension has changed.

You can accomplish the following by creating a DLL:

(1) Divide the program into separate modules that can be loaded on demand.

(2) Store language-specific or region-specific resources.
(3) Enable your own application to use the core code base.
(4) generates an in-process COM object or ActiveX control (OCX).
(5) Use an OLE object as an in-process DLL. This usage can improve the performance of OLE links.
(6) Use the Control Panel to extend or use certain types of drivers.

Second. about ActiveX controls with an. ocx suffix

As mentioned earlier, file types with the file extension. ocx,. cpl, and. DRV are also DLLs.

Now that the ActiveX control is equivalent to the previous OLE control or OCX, a typical control includes the design-time and run-time user interface, the unique IDispatch interface defines the properties and methods of the control, and the only IConnectionPoint interface defines the events that the control can raise. A control can run in a container, so it looks like a DLL from a running point of view. 

Although both ActiveX and OLE are based on the Build object model (Component object model,com), they provide different services to programmers. COM provides a low-level object bundling mechanism that supports interactive communication between objects. OLE uses COM to provide low-level application services, such as the use of connection and embedding mechanisms, to enable users to create compound documents. In contrast, ActiveX provides a finer structure to support embedding controls on network sites, as well as interacting with events. ActiveX optimization is designed to improve time and space efficiency, while OLE is optimized for use by end users and integrated desktop systems applications. ActiveX also brings some technical changes to Internet technology, for example, by significantly reducing the amount of code (Bell) and supporting more commits and asynchronous connections. 

ActiveX is based on OLE and COM, but the various development tools of MS can block out many of the confusing technical details in the COM model. 



The ActiveX component technology includes the following aspects: 

(1) Automation server 

(2) automation controller 

(3) control 

(4) COM object 

(5) document 

(6) container.

ActiveX controls with an. ocx suffix are primarily applied on the web and on the Windows Forms program development. Applications use the Activex/com component to extend the scope of their business logic, transaction processing, and application services.

By the way, the registration and uninstallation method of an ActiveX control with an. ocx suffix, enter the following code to complete the task on the Start menu, run:

regsvr32 path & ' \xxx.ocx ' Registration
regsvr32/u Path & ' \xxx.ocx ' Uninstall

Where path represents the Xxx.ocx, so the path to the directory.

Third, the difference between OCX and DLL

An ActiveX control with an. ocx suffix is a special DLL that is based on OLE and COM, a visual control that has an interactive interface, defines the properties and methods of the control, and defines the response of the event that the control can raise. We usually say that. A file with a DLL suffix is a module collection of functions and data that can be shared by other applications.


---restore content ends---

The difference between OCX and DLL

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.