Windows core Programming---dynamic-link libraries (XX.dll) and static libraries (XX.LIB)

Source: Internet
Author: User


Recently read the memory management and dynamic Link Libraries section of Windows core programming, although some people are judge about the future of windows, but have to admit that the powerful features of Microsoft Windows System, and its deep architectural design ideas, admirable. Through this reading to the library file has a deeper understanding, summed up in this!

Dynamic Link libraries (Linked library):

Windows provides rich function calls to applications that are included in the dynamic-link library. Of these, 3 of the three most important libraries are: Kernel32.dll, Use32.dll, GDI32.dll, as described below:

Kernel32.dll: It contains various functions for managing memory, processes, and threads;

User32.dll: It contains functions for performing user interface tasks such as window creation and message delivery;

GDI32.dll: It contains various functions for drawing and displaying text.


Import Library:
When using a dynamic link library, there are often two files available: An introduction library and a DLL. The introduction library contains the symbolic names of the functions and variables exported by the DLL, and the DLLs contain the actual functions and data. When compiling the link executable file, only need to link to the library, the DLL's function code and data is not copied to the executable file, at run time, then load the DLL, access the DLL exported functions.

Static Library:
Functions and data are compiled into a binary file (usually with an extension of. LIB). In the case of a static library, when compiling the linked executable, the linker copies the functions and data from the library and combines them with other modules of the application to create the final executable file (. EXE file).

When you run a Windows program, it touches windows through a process called dynamic linking. A Windows. exe file has a reference to it using a different dynamic-link library, where the function is used. When a Windows program is loaded into memory, calls in the program are directed to the entry of the DLL function, and if the DLL is not in memory, the system loads it into memory.

When you link a Windows program to produce an executable file, you must link the Specialized import library library that is provided by the programming environment. These import libraries contain the dynamic link library name and reference information for all Windows function calls. The linker uses this information in the. EXE file to construct a table when the loader is loaded, Windows uses it to convert calls to Windows functions.

the difference between a static library and an import library:
The difference between an import library and a static library is that they are essentially different things. The static library itself contains the actual execution code, symbol table and so on, and for the import library, its actual execution code is located in the dynamic library, the import library contains only the address symbol table, etc., to ensure that the program to find some basic address information of the corresponding function.

static links and dynamic Links:

Static linking method: #pragma comment (lib, "Jackery_shh.lib"), static link, loading code will be used by the program's dynamic code or the address of the dynamic code to determine down
Links to static libraries can use static links, and dynamic-link libraries can also use this method to link import libraries

Dynamic linking method: There are three functions designed here, LoadLibrary ()/getprocessaddress () and FreeLibrary () (For specific usage, please participate in MSDN). Note, however, that a program that uses this method does not complete the dynamic link in the first place, but until the dynamic library code is actually called, the loader calculates the logical address of the dynamic code (the part that was called), and then waits a while for the program to invoke another block of dynamic code. The loading program also calculates the logical address of this part of the code, so this way, the program initialization time is shorter, but the performance during the run compared to statically linked programs.

In the process of software development, we often use a dynamic library or a static library written by others or provided by the system, but what are their applicable conditions? Do you use a static library or a dynamic library?

Simply put, static libraries and applications are compiled together and run in any case, while dynamic libraries are dynamic links, as the name implies when the application is launched, so the application fails when the dynamic library is not available on the user's system. Then look at their features:
Dynamic libraries:
1. Sharing: Multiple applications can use the same dynamic library, when launching multiple applications, only need to load the dynamic library into memory once;
2. Development module Good: requires the designer to partition the function better.

Static Library: The code is loaded faster and executes faster, because it will only link the part you need when compiling, and the application is relatively large. However, if multiple applications are used, they will be loaded multiple times, wasting memory.

If you have more than one application on your system that uses the library, compile it into a dynamic library, so that although the load is slow when it starts up, it will save memory when multitasking, and if you have only one to two apps on your system that use the library and use fewer APIs, compile it into a static library. General static libraries can also be clipped and compiled, so the application may be larger, but the speed of the startup will be greatly increased.

Complete, other documentation links: Graphic image 2D algorithm detailed

Windows core programming-unicode and ANSI


Windows core Programming---dynamic-link libraries (XX.dll) and static libraries (XX.LIB)

Related Article

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.