Basic concepts of VC ++ Linked Library (I)

Source: Internet
Author: User

First, introduce some concepts, and then introduce how to create static and dynamic link libraries.


(1) Dynamic and Static Link Libraries

1. Static Library

Functions and data are compiled into a binary file (usually with the extension. Lib ). When releasing a product, you only need to publish the executable file and do not need to publish the used static library. 2. When using a dynamic library, a dynamic library usually provides two files: one imported Library (. Lib) file and one DLL (. dll) file. Although the suffix of the import library is Lib, the import library of the dynamic library is essentially different from the static library file. When a dynamic library is used, you only need to link the imported DLL file when compiling the executable file. The function code and data in the DLL are not copied to the executable file, it is not until the executable program runs, that the required DLL is loaded, the DLL is mapped to the address space of the process, and then the exported function in the DLL is accessed. when the product is released, in addition to publishing executable files, there are also dynamic link libraries to be called by the program. The dynamic link library usually cannot run directly or receive messages. It only works when other modules call functions in the dynamic link library. In actual programming, we can place functions that complete certain functions in a dynamic link library and provide them to other programs for calling.
Note:The above may be a bit difficult. In a simple summary: both static and dynamic link libraries share code. If static link libraries are used, whether you want them or not, all commands in lib are directly included in the final generated EXE file. However, if a DLL is used, the DLL does not need to be included in the final EXE file. During execution of the EXE file, the DLL file can be dynamically referenced and detached. Another difference between a static link library and a dynamic link library is that the static Link Library cannot contain any other dynamic or static Link Library, other dynamic or static link libraries can be included in the dynamic link library.
(2) Three Different DLL types


Visual c ++ supports three types of DLL, which are non-MFC dynamic libraries (non-MFC
DLL), MFC rule DLL (MFC
Regular DLL), MFC extension DLL (MFC
Extension DLL ).
1. Non-MFC dynamic libraryIt refers to a DLL written in C language directly without the use of the MFC class library structure. The exported function is a standard C interface and can be called by applications written in non-MFC or MFC. In VC ++ 6.0, file --> New --> Win32 dynamic-Link Library creates a non-MFC dynamic library. 2. Conventional DLL: Like the following extension DLL, it is written using the MFC class library. One obvious feature of it is that there is a class that inherits cwinapp in the source file (note: although such DLL is derived from cwinapp, there is no 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 ), the application that calls a conventional DLL does not need to be an MFC application, as long as it is an application that can call a class C function, they can be in the visual
C ++, dephi, Visual Basic, Borland C, and other compiling environments use DLL to develop applications. Conventional dll can be subdivided into static link to MFC and dynamic link to MFC. The differences between these two types of conventional DLL are described below. In VC ++ 6.0, file --> New --> MFC
Appwizard [DLL], followed by three options: regular DLL with MFC statically linked is to create a regular dynamic link library, which uses the static link of MFC; regular
DLL using shared mfc dll is used to create a regular dynamic link library, which uses the shared mfc dll; MFC extension DLL is used to create an extended mfc dll. 3. Use Extended DLLUsed for export enhancement
The function or subclass of the MFC basic class. With this type of dynamic link library, it can be used to output a class inherited from the 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. Extended DLL
Unlike 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.