Dynamic Link Library call

Source: Internet
Author: User

1. There are two methods to call a dynamic link library: static call (implicit) and dynamic call (Display ).

1) Static call

In this call method, the. Lib file generated when a dynamic Connection Library is generated must be added to the application.ProgramIn the project, when using the functions in DLL, you only need to describe it and then you can directly call the DLL output function through the function name. The Calling method is the same as other functions in the program. Implicit call does not need to call Load Library () and free library (). When a programmer creates a DLL file, the link program automatically generates a corresponding lib import file. This file contains the symbolic name and optional Identification Number of each DLL export function, but does not contain the actualCode. The LIB file is compiled into the application project as an alternative DLL file.

When programmers compile an application by implicit calling, the calling functions in the application match the exported symbols in the Lib file, and these symbols or identification numbers are written to the generated EXE file. The LIB file also contains the corresponding DLL file name (but not the full path name), and the link program also stores it inside the EXE file. When a DLL file needs to be loaded while the application is running, Windows will find and load the DLL based on the information, and then use the symbolic name or identification number to achieve dynamic links to the DLL function. All DLL files called by the application will be loaded into the memory when the application EXE file is loaded.

2) explicit call

This call method is to explicitly call your own dynamic Connection Library in the application using the load library or the afxloadlibrary provided by MFC, and specify the dll path as the parameter. Loadlibary returns the hinstance parameter, which is used by the application to call the getprocaddress function. After importing the dynamic link library, use getprocaddress () to obtain the function to be introduced. This function converts the symbol name or ID number to the internal address of the DLL, then you can call the introduced function just like using the UDF of this application. Before exiting the application, use the afxfreelibrary provided by free library or MFC to release the dynamic Connection Library.

Explicit calling allows programmers to determine when or not to load DLL files, the operating system does not need to load all the DLL referenced by the application to the memory when loading the application, as long as it loads it when using a DLL, in this way, the time used by the application during initial loading and the memory consumption can be reduced. During the DLL loading process, Windows will follow the search order below to locate the DLL:

① Directory containing the EXE file;

② Current working directory of the process;

③ Windows System directory;

④ Windows Directory;

⑤ A series of directories in the PATH environment variable.

Summary

Using dynamic link library (DLL) in Windows has many advantages. The most important thing is that multiple applications, or even applications written in different languages, can share a DLL file, the real implementation of resource "sharing" greatly reduces the application code execution and makes more effective use of the memory; another advantage of using DLL files as a separate program module, encapsulation and independence are good. When the software needs to be upgraded, the developer only needs to modify the corresponding DLL file. Moreover, if the parameter is not modified after the function in the DLL changes, 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.

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.