What is DDL?

Source: Internet
Author: User
Tags microsoft c

What is DLL?

DLL is a library that contains code and data that can be used by multiple programs at the same time. For example, in windows, comdlg32 DLL executes common functions related to the dialog box. Therefore, each program can use the functions included in the DLL to implement the "open" dialog box. This helps promote code reuse and effective memory usage.

By using DLL, the program can be modularized and composed of relatively independent components. For example, an accounting program can be sold by module. Each module can be loaded into the main program at runtime (if the corresponding module is installed ). Because modules are independent from each other, the program loading speed is faster, and the module is loaded only when the corresponding functions are requested.

In addition, it is easier to apply updates to each module without affecting other parts of the program. For example, you may have a salary calculation program, and the tax rate is changed every year. After these changes are isolated into the DLL, you can apply updates without re-generating or installing the entire program.

The following table describes some files implemented as DLL in Windows:

�� 1
 

ActiveX Control (. ocx) File
An example of the ActiveX control is the calendar control, which enables you to select a date from the calendar.

�� 1
 

Control Panel (. CPL) File
An example of the. Cpl file is an item located in the control panel. Each item is a dedicated DLL.

�� 1
 

Device Driver (. DRV) File
An example of a device driver is a printer driver that controls printing to a printer.

Since Microsoft launched a 16-bit Windows Operating System Since then, every version of Windows operating system has been very dependent on functions and Data In fact, almost all content in Windows is represented by DLL in one or another form, for example, the displayed fonts and icons are stored in the gdi dll, the Code required to display Windows desktops and process user input is stored in a user DLL Programming A large number of API functions are also included in the kernel DLL.

Using DLL in a Windows operating system has many advantages. The most important thing is that multiple applications Program Even applications written in different languages can share a DLL file, truly achieving resource "sharing", greatly reducing the code executed by the application and making more effective use of the memory; another advantage of using DLL is that the DLL file is used as a separate program module with good encapsulation and independence. Software When upgrading, developers only need to modify the corresponding DLL file, and when the function in the DLL changes, as long as it is not a parameter change, the program code does not need to be re-compiled. This is very useful in programming and greatly improves the efficiency of software development and maintenance.

Since DLL is so important, it is a problem that programmers have to solve to find out what is DLL and how to develop and use it in windows. This article To solve these problems, we use a simple example, that is, to implement the maximum and minimum integer functions in a DLL, and fully parse Compile the environment to program and implement the DLL Process The program code used in this article is passed in the Windows 98 System and Visual C ++ 6.0 compiling environment.

Ii. dll Concept

DLL is a library file that contains a number of functions, classes, or resources. functions and data are stored in a DLL (server) and exported by one or more customers. These customers can be applications or other DLL. The dll library is different from the static library. In the case of a static library, functions and data are compiled into a binary file (usually with the extension *. lib ), when processing program code, the visual C ++ compiler restores these functions and data from the static library and combines them with other modules in the application to generate executable files. This process is called "static link". In this case, because all the content required by the application is copied from the library, the static library itself does not need to be released together with the executable file.

In the case of a dynamic library, there are two files, one is imported into the database (. lib) file. One is a DLL file. The imported file contains the name and location of the function exported by the DLL. The dll contains the actual function and data, the application uses the Lib file to link to the required DLL file. The functions and data in the library are not copied to the executable file. Therefore, in the executable file of the application, stores not the called function code, but the memory address of the function to be called in the DLL, in this way, when one or more applications are running, the program code is linked to the called function code, thus saving memory resources. From above Description It can be seen that the DLL and. Lib files must be released along with the application, otherwise the application will produce errors.

Microsoft's Visual C ++ supports three types of DLL: Non-mfc dll (non-MFC dynamic library), regular DLL (conventional DLL), and extension DLL (Extended DLL ). Non-mfc dll refers to a DLL written directly in C language without the use of the MFC class library structure. The exported function is Standard Can be called by non-MFC or MFC applications. Regular DLL: similar to the following extension DLLs, it is written using the MFC class library. One obvious feature of this DLL is that there is a class in the source file that inherits cwinapp (note: although such DLL is derived from cwinapp, it does not Message Loop ), the exported function is a C function, C ++ class, or C ++ member function (do not confuse the C ++ class with the Microsoft C ++ class of MFC ), applications that call conventional DLL do not need to be MFC applications, as long as they can call C-like functions, they can be used in Visual C ++, dephi, Visual Basic, Borland C, and other compiling Environments Development Application.

Conventional dll can be subdivided into static link to MFC and dynamic link to MFC. Below Introduction. Compared with conventional DLL, extended DLL is used to export functions or subclasses that enhance the basic class of MFC. This type of dynamic link library can be used to output a class inherited from MFC.

The extension DLL is created using the dynamic link version of MFC, and is called only by applications written in the MFC class library. For example, you have created a derived class from the ctoolbar class of MFC to create a new toolbar. to export this class, you must put it in an extended DLL of MFC. Extension DLL is different from conventional DLL. It does not have a class Object inherited from cwinapp. Therefore, developers must add initialization code and end code to the dllmain function in the 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.