Summary 3 of dynamic link library knowledge point (how to load DLL in display mode)

Source: Internet
Author: User

To sum up how to display the Loading Method to load the DLL,

First, create a Win32 project, select DLL, empty project, and add a source file, a module definition file (. Def), as shown in. (The detailed method has been described in the first two articles. If you do not understand it, open the link to view it)

(1) create a project named DLL, add a source file (. cpp), compile the code, and compile the file.



(2) Add a module definition file for the project (detailed in the previous article) (create a new text and change the attribute name) and edit the code, as shown in figure



(3) create a DLL test application (based on the dialog box), Project name: testdll, add a button, properties are as follows, compile it first.


(4) Add a response function for the button and write the following code (the meaning of the Code is described at the end)


(5) copy the compiled DLL file to the application directory (the dllfile is placed in the. exe folder of the test file (the practices have been described in the first two articles ),



(7) Click, run, and run successfully. The DLL is successfully loaded as shown.


Now we will introduce the code meaning in the button message response function.

The function loadlibrary () is used to map executable modules to the address space of processes. In general, it can be used to load DLL. This function is an important function for displaying DLL loading. The parameter is the DLL name. This function has a detailed explanation on msdn. You can refer to the following link for details. This function returns the handle of the loaded DLL. (Click to open the link)

With the DLL handle, we need to obtain the address of the export function to obtain the address. Use this function: getprocaddress (). Parameter 1 is the DLL handle. Parameter 2 is a pointer, the name of the exported function. If the return value of this function is null, the address cannot be obtained. If yes, the export address of the export function is returned.

With the address, we need a function pointer to call the export function to manipulate the function.

Here we will summarize:

When a DLL is dynamically loaded, the client does not need to include the import/export file, but only the. dll file. Static Loading and dynamic loading have their own advantages and disadvantages. First, static loading DLL is relatively simple, but if too many DLL files need to be loaded, it will lead to slow startup programs, so it is better to choose dynamic loading.

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.