Chapter 2: DLL Basics

Source: Internet
Author: User

1. we must understand that an address space consists of an executable module and multiple DLL modules. when a module provides a memory allocation function, it must also provide another function to release the memory.

2. In actual development, you should avoid exporting variables from the DLL, because this is equal to removingCodeSo that the DLL code is more difficult to maintain. in addition, only the compilers used to export C ++ classes are provided by the same manufacturer as those used to import C ++ classes. Otherwise, you should avoid exporting classes from the DLL.

3. dll construction steps:

◆ Create a header file that contains the function prototype, structure, and symbol we want to export in the DLL. To build the DLL, all the DLL source files must contain this header file.

◆ Create a C/C ++ source file to implement the functions and variables to be exported in the DLL module.

◆ When constructing the DLL module, the compiler processes each source file and generates an OBJ module (each source file corresponds to an OBJ module)

◆ After all OBJ modules are mounted, the linker combines the content of all OBJ modules to generate a separate DLL image file. this image file contains all the binary code in the DLL and the global code. static variable.

◆ If the linker detects that at least one function or variable is output from the DLL source file, the linker will generate a lib file. (This lib file is very small, because it does not contain any function or variable, but only lists the symbolic names of all exported functions and variables .)

Use the DLL module.

◆ All source files that reference exported function. variables, data structures, or symbols must contain header files created by DLL developers.

◆ Create a C/C ++ source file to implement functions and variables that you want to include in the executable module. Of course, the code can reference the functions and variables defined in the DLL header file.

◆ When building an executable module, the compiler processes each source file and generates an OBJ module.

◆ After all OBJ modules are created, the linker combines the content of all OBJ modules to generate a separate executable file.

◆ LoadProgramFirst, create a virtual address space for the new process, and map the executable module to the new process address space. Then, the loader will parse the import segment of the executable module, for each DLL listed in the segment, the loader locates the DLL module in the user's system and maps the DLL to the address space of the process.

When an executable module is started, the import segment only contains the DLL file name. The path loading sequence is as follows:

N directory containing executable files.

N Windows directory. You can use getsystemdirectory to change the directory.

N 16-bit system directory

The N window directory is obtained through getwindowsdirectory.

N current directory of the process

Directory listed in N Ptah Environment Variables

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.