What is DLL?

Source: Internet
Author: User
Tags microsoft website
What is DLL? View the products used in this article

If (! Loadtocnode) {var loadtocnode = function (){}}

This page

  • Summary
  • Introduction
  • More information

      • what is DLL?
      • DLL advantages
      • DLL dependencies
      • DLL troubleshooting tool

        • dependency Walker
        • DLL universal problem solver
        • DLL help database
      • DLL development

        • DLL type

          • dynamic link during loading
          • dynamic link during running
        • DLL entry point
        • export DLL Functions
        • example DLL and application
      • . NET Framework Assembly
  • Reference

VaR sectionfilter = "type! = 'Notice' & type! = 'Securedata' & type! = 'Queryword '";
VaR tocarrow = "/library/images/support/kbgraphics/public/en-US/downarrow.gif ";
VaR depthlimit = 10;
VaR depth3limit = 10;
VaR depth4limit = 5;
VaR depth5limit = 3;
VaR tocentryminimum = 1;

Show all
| Close all

If (kb_page_object)
{
Kb_page_object.kb_imageexpandhovertext = 'expand this image ';
}

Summary

This article describes what is a dynamic link library (DLL) and various problems that may occur when using DLL. Then, this article describes some advanced issues that should be considered when developing your own DLL. What is d...

Loadtocnode (1, 'summary ');

This article describes what is a dynamic link library (DLL) and various problems that may occur when using DLL.

Then, this article describes some advanced issues that should be considered when developing your own DLL. This article describes the Dynamic Link Method, DLL dependency, DLL entry point, export DLL functions, and DLL troubleshooting tools.

At the end of this articleProgramSet as a comparison.
Back to TopIntroduction

For Microsoft Windows operating systems listed in the "apply to" section, a large number of features of the operating system are provided by the dynamic link library (DLL. In addition, when you are in these windows...

Loadtocnode (1, 'summary ');

For Microsoft Windows operating systems listed in the "apply to" section, a large number of features of the operating system are provided by the dynamic link library (DLL)
Provided. In addition, when you run a program on one of these windows operating systems, many functions of the program may be
Provided. For example, some programs may contain many different modules, and each module of the program is included in the DLL and distributed among them.

Use DLL
FacilitatingCodeModular, code reuse, effective use of memory, and reduced disk space. Therefore, the operating system and program can load and run faster, and occupy less disk space in the computer.

When the program uses
DLL, a problem called dependency may cause the program to fail to run. When the program uses DLL
A dependency is created. If other programs rewrite and corrupt the dependency, the original program may not be able to run successfully.

When Microsoft. NET is introduced
After the framework, most dependency problems have been eliminated by using the assembly.


Back to Top More information

What is DLL? DLL is a library that contains code and data that can be used by multiple programs at the same time. For example, in a Windows operating system, comdlg32 DLL runs Common Dialog Box-related operations...

Loadtocnode (1, 'moreidinformation ');

What is DLL?

Loadtocnode (2, 'moreidinformation ');

DLL is a library that contains code and data that can be used by multiple programs at the same time. For example, in windows, comdlg32 DLL
Execute common functions related to the dialog box. Therefore, each program can use the DLL
To enable the "open" dialog box. This helps promote code reuse and effective memory usage.

Use
DLL, the program can be modularized, composed of relatively independent components. For example, an accounting program can be sold by module. Each module can be loaded into the main program at runtime (if the corresponding module is installed ). Because modules are independent from each other, the program loading speed is faster, and the module is loaded only when the corresponding functions are requested.

In addition, it is easier to apply updates to each module without affecting other parts of the program. For example, you may have a salary calculation program, and the tax rate is changed every year. When these changes are isolated
DLL, you do not need to regenerate or install the entire program to update the application.

The following table describes some files implemented as DLL in Windows:

    • ActiveX Control (. ocx) File

      An example of the ActiveX control is the calendar control, which enables you to select a date from the calendar.
    • Control Panel (. CPL) File

      An example of the. Cpl file is an item located in the control panel. Each item is a dedicated DLL.
    • Device Driver (. DRV) File

      An example of a device driver is a printer driver that controls printing to a printer.

Advantages of returning to the top DLL

Loadtocnode (2, 'moreidinformation ');

The following table describes some advantages of using DLL:

    • Use fewer resources

      When multiple programs use the same function library
      This reduces the amount of code that can be loaded in disk and physical memory. This not only can greatly affect the programs running on the foreground, but also can greatly affect other programs running on Windows
      The program running on the operating system.
    • Modular architecture of promotion

      DLL
      It facilitates the development of modular programs. This helps you develop large programs that require multiple language versions or require a modular architecture. An example of a modular program is a program with multiple modules that can be dynamically loaded at runtime.
    • Simplified deployment and Installation

      When the functions in the DLL need to be updated or repaired, you do not need to re-establish the program and
      . In addition, if multiple programs use the same DLL, multiple programs will benefit from the update or repair. When you use a third-party DLL that is regularly updated or repaired
      This problem may occur more frequently.

Return to the top DLL dependency

Loadtocnode (2, 'moreidinformation ');

When a program or DLL uses a DLL in another DLL
When the function is used, the dependency is created. Therefore, the program is no longer independent, and if the dependency is damaged, the program may encounter problems. For example, if one of the following operations occurs, the program may not run:

    • Upgrade the dependency DLL to the new version.
    • Fixed the dependency DLL.
    • The dependent DLL is overwritten by earlier versions.
    • The dependent DLL is deleted from the computer.

These operations are usually called DLL
Conflict. If backward compatibility is not enforced, the program may fail to run.

The following table describes how to minimize dependency issues in Microsoft
Changes introduced in Windows 2000 and later versions:

    • Windows File Protection

      In Windows File Protection, the operating system prohibits unauthorized proxy updates or system deletion.
      DLL. Therefore, when a program installation attempt attempts to delete or update a DLL defined as a system DLL, Windows File Protection will find a valid digital signature.
    • Dedicated DLL

      Dedicated dll can be used to prevent the program from being changed to the shared DLL. Dedicated DLL uses version-specific information or is empty. Local
      File to force the version of the DLL used by the program. To use a dedicated DLL, find the DLL in the program root folder. Then, for new programs
      . For old programs, use the empty. Local file. Each method tells the operating system to use a dedicated DLL located in the program root folder.

Go back to the top DLL troubleshooting Tool

Loadtocnode (2, 'moreidinformation ');

You can use multiple tools to solve the DLL problem. The following are some of the tools.

Dependency Walker

Loadtocnode (3, 'moreidinformation ');

The dependency Walker tool can recursively scan all the dependent DLL used by the program. When you are in the dependency Walker
When the program is opened, dependency Walker performs the following checks:

    • Dependency Walker checks whether the DLL is lost.
    • Dependency Walker checks whether an invalid program file or dll exists.
    • Dependency Walker checks whether the import and export functions match.
    • Dependency Walker checks whether there is a loop dependency error.
    • Dependency Walker checks whether there are modules that are invalid for another different operating system.

By using dependency Walker, you can record all the DLL used by the program. This may help avoid and correct the DLL that may occur in the future.
Problem. When you install Microsoft Visual Studio 6.0, dependency Walker is located in the following directory:

Drive
\ Program Files \ Microsoft Visual Studio \ common \ toolsdll universal problem solver

Loadtocnode (3, 'moreidinformation ');

The DLL universal problem solver (dups) tool is used to review, compare, record, and display DLL information. The following table describes the composition
Dups tool utility:

    • Dlister.exe

      This utility enumerates all DLL files on a computer and records this information to a text file or database file.
    • Dcomp.exe

      The utility compares the DLL listed in two text files and generates a third text file containing the difference.
    • Dtxt2db.exe

      This utility loads text files created by using the dlister.exe utility and dcomp.exe utility to DLLhell
      Database.
    • Dlgdtxt2db.exe

      This utility provides the graphical user interface (GUI) version of dtxt2db.exe.

Related
For more information about the dups tool, clickArticleTo view the articles in the Microsoft Knowledge Base:

247957


Http://support.microsoft.com/kb/247957/
)

Example: Use dups.exe to solve DLL compatibility problems

DLL help Database

Loadtocnode (3, 'moreidinformation ');

DLL helps you find a specific version of DLL installed by Microsoft software products. Related DLL
For more information about the help database, visit the following Microsoft Website:

Http://support.microsoft.com/dllhelp/

Http://support.microsoft.com/dllhelp)

Go back to top DLL Development

Loadtocnode (2, 'moreidinformation ');

This section describes the issues and requirements you should consider when developing your own DLL.

DLL type

Loadtocnode (3, 'moreidinformation ');

When you load a DLL in an application, you can use two link methods to call the exported DLL function. These two link methods are dynamic links during loading and dynamic links during runtime.

Dynamic Link during loading

Loadtocnode (4, 'moreidinformation ');

In the dynamic link during loading, the application calls the exported DLL just like a local function.
The function is called explicitly. To use the dynamic link during loading, provide the header file (. h) and imported file (. Lib) when compiling and linking the application ). When you do this, the linker will provide the system with DLL Loading
The required information, and parse the location of the exported DLL function during loading.

Dynamic Link during running

Loadtocnode (4, 'moreidinformation ');

In the dynamic link at runtime, the application callsLoadlibrary
Function orLoadLibraryEx
Function to load the DLL at runtime. After successfully loading the DLL, you can useGetprocaddress
Function to obtain the exported DLL
The address of the function. When using dynamic links during running, you do not need to use import/export files.

The following list describes the conditions for when to use the dynamic link at loading and when to use the dynamic link at runtime:

    • Startup Performance

      If the Initial Startup Performance of the application is important, use the dynamic link at runtime.
    • Ease of use

      In the dynamic link during loading, the exported DLL function is similar to a local function. This allows you to conveniently call these functions.
    • Application logic

      In the dynamic link during runtime, the application can be split to load different modules as needed. This is important when developing multilingual versions.
DLL entry point

Loadtocnode (3, 'moreidinformation ');

When creating a DLL, you can choose to specify the entry point function. When a process or thread attaches itself to a DLL or
When splitting, the entry point function is called. You can use the entry point function according to the DLL
To initialize or destroy the data structure. In addition, if the application is multi-threaded, you can use the Thread Local Storage (TLS) in the entry point function)
To allocate dedicated memory for each thread. The following code is an example of a DLL entry point function.

Bool apientry dllmain (
Handle hmodule, // handle to DLL module
DWORD ul_reason_for_call, // reason for calling function
Lpvoid lpreserved) // Reserved
{
Switch (ul_reason_for_call)
{
Case dll_process_attached:
// A process is loading the DLL.
Break;
Case dll_thread_attached:
// A process is creating a new thread.
Break;
Case dll_thread_detach:
// A thread Exits normally.
Break;
Case dll_process_detach:
// A process unloads the DLL.
Break;
}
Return true;
}

When the entry point function returnsFalse
If you are using a dynamic link during loading, the application will not start. If you are using a dynamic link during runtime, only a few DLL
Not loaded.

The entry point function should only execute simple initialization tasks and should not call any other DLL to load or terminate functions. For example, the entry point function should not be called directly or indirectly.Loadlibrary
Function orLoadLibraryEx
Function. In addition, it should not be called at Process Termination.Freelibrary
Function.

Note:
: In multi-threaded applications, ensure that the access to global DLL data is synchronized (thread security) to avoid possible data corruption. To do this, use TLS
Provide unique data for each thread.

Export DLL Functions

Loadtocnode (3, 'moreidinformation ');

To export a DLL function, you can add a function keyword to the exported DLL function, or create a module definition file (. Def) to list the exported DLL.
Function.

To use the function keyword, you must use the following keywords to declare the functions to be exported:

_ Declspec (dllexport)

To use the exported DLL function in an application, you must use the following keywords to declare the functions to be imported:

_ Declspec (dllimport)

Generally, you 'd better useDefine
Statement andIfdef
Statement header file to separate the Export Statement and Import Statement.

You can also use the module definition file to declare the exported DLL.
Function. When you use a module definition file, you do not need to add function keywords to the exported DLL function. In the module definition file, you can declareLibrary
Statement andExports
Statement. The following code is an example of a definition file.

 
// Sampledll. Def
//
Library "sampledll"

Exports
Helloworld
Example DLL and Application

Loadtocnode (3, 'moreidinformation ');

In Microsoft Visual C ++ 6.0, you can select the "Win32 dynamic link library" project type or the "MFC Application Wizard"
(DLL) to create a DLL.

The following code is an example of a DLL created using the "Win32 dynamic link library" project type in Visual C ++.

 
// Sampledll. cpp
//

# Include "stdafx. H"
# Define exporting_dll
# Include "sampledll. H"

Bool apientry dllmain (handle hmodule,
DWORD ul_reason_for_call,
Lpvoid lpreserved
)
{
Return true;
}

Void helloworld ()
{
MessageBox (null, text ("Hello World"), text ("in a DLL"), mb_ OK );
}
 
// File: sampledll. h
//
# Ifndef indll_h
# Define indll_h

# Ifdef exporting_dll
Extern _ declspec (dllexport) void helloworld ();
# Else
Extern _ declspec (dllimport) void helloworld ();
# Endif

# Endif

The following code is an example of a "Win32 application" project. This example calls the export DLL function in sampledll.

// Sampleapp. cpp
//

# Include "stdafx. H"
# Include "sampledll. H"

Int apientry winmain (hinstance,
Hinstance hprevinstance,
Lpstr lpcmdline,
Int ncmdshow)
{
Helloworld ();
Return 0;
}

Note:
: In the dynamic link during loading, you must link sampledll. Lib created when the sampledll project is generated.
Import to warehouse.

In the dynamic link during runtime, you should use code similar to the following code to call sampledll. DLL to export the DLL function.

 
...
Typedef void (* dllproc) (lptstr );
...
Hinstance hinstdll;
Dllproc helloworld;
Bool ffreedll;

Hinstdll = loadlibrary ("sampledll. dll ");
If (hinstdll! = NULL)
{
Helloworld = (dllproc) getprocaddress (hinstdll, "helloworld ");
If (helloworld! = NULL)
(Helloworld );

Ffreedll = freelibrary (hinstdll );
}
...

When you compile and link the sampledll application, the Windows operating system searches for sampledll in the following order:

    1. Application folder
    2. Current folder
    3. Windows Folder

      Note:
      :Getsystemdirectory
      The function returns the path of the Windows system folder.

    4. Windows Folder

      Note:
      :Getwindowsdirectory
      The function returns the path of the Windows folder.


Back to the top. NET Framework Assembly

Loadtocnode (2, 'moreidinformation ');

After Microsoft. NET and. NET Framework are introduced, most
The associated problems have been eliminated by using the assembly. An assembly is a logical functional unit that runs under the control of the. NET Common Language Runtime Library (CLR. The Assembly is actually used as a. dll file or
The. exe file exists. However, internally, the Assembly and Microsoft Win32 DLL
Big differences.

The Assembly file contains the Assembly List, type metadata, and Microsoft intermediate language (msil)
Code and other resources. The Assembly List contains Assembly metadata to provide all the information required to make the Assembly a self-describing assembly. The Assembly list contains the following information:

    • Assembly name
    • Version Information
    • Regional information
    • Strong name information
    • Assembly file list
    • Type reference information
    • Reference and dependent assembly information

The msil code contained in the program cannot be directly executed.
. By default, when you create an assembly, the Assembly is proprietary to the application. To create a shared assembly, you must assign a strong name to the Assembly and publish the assembly in the Global Assembly Cache.

The following table describes some functions of the Assembly and
The functions of Win32 DLL are compared:

    • Self-description

      When you create an assembly, all information required to run the Assembly by CLR is included in the assembly list. The Assembly list contains a list of dependent assembly. Therefore, CLR
      You can maintain a set of consistent assemblies used in applications. In Win32 DLL, when you use shared DLL, a group of DLL files used in the application cannot be maintained.
      Consistency.
    • Version Control

      In the Assembly List, version information is recorded and implemented by CLR. In addition, you can use version policies to implement version-specific usage. In Win32 DLL
      Version Control cannot be implemented by the operating system. Instead, you must ensure that the DLL is backward compatible.
    • Parallel deployment

      The Assembly supports parallel deployment. One application can use one version of the Assembly, while another application can use another version of the Assembly. From windows
      From 2000, you can place the DLL in the application folder to support parallel deployment. In addition, Windows File Protection can prevent system DLL
      It is rewritten or replaced by an unauthorized proxy.
    • Independent and isolated

      Applications developed using an assembly can be independent and isolated from other applications running on the computer. This feature helps to create a zero-interference installation.
    • Run

      The Assembly runs under the security permissions provided by the Assembly List and controlled by CLR.
    • Language independence

      You can use any supported. NET language to develop an assembly. For example, in Microsoft Visual C #
      And then use the assembly in the Microsoft Visual Basic. Net project.

Back to Top Reference

For more information about DLL and. NET Framework Assembly, visit the following Microsoft Website: DLL help database http://support.mic...

Loadtocnode (1, 'references ');

For more information about DLL and. NET Framework Assembly, visit the following Microsoft Website:

DLL help Database
Http://support.microsoft.com/dllhelp

Http://support.microsoft.com/dllhelp)

DLL conflict (DLL conflicts)
Http://msdn2.microsoft.com/en-us/library/ms811694.aspx

Http://msdn2.microsoft.com/en-us/library/ms811694.aspx)

Implementing parallel component sharing in applications (implementing side-by-side component sharing in applications)
Http://msdn2.microsoft.com/en-us/library/ms811700.aspx

Http://msdn2.microsoft.com/en-us/library/ms811700.aspx)

How to generate and maintain independent applications and parallel assembly for Windows XP (how to build and service isolated applications and side-by-side assemblies for Windows XP)
Http://msdn2.microsoft.com/en-us/library/ms997620.aspx

Http://msdn2.microsoft.com/en-us/library/ms997620.aspx)

Use. NET Framework to simplify deployment and resolve DLL conflicts (Simplifying deployment and solving DLL conflicts with the. NET Framework)
Http://msdn2.microsoft.com/en-us/netframework/aa497268.aspx

Http://msdn2.microsoft.com/en-us/netframework/aa497268.aspx)

. NET Framework developer guide: Assembly
Http: // msdn2.microsoft.com/en-us/library/hk5f 40ct (vs.71). aspx

(Http://msdn2.microsoft.com/en-us/library/hk5f 40ct (vs.71). aspx)

Dynamic Link during running
Http://msdn2.microsoft.com/en-us/library/ms685090.aspx

Http://msdn2.microsoft.com/en-us/library/ms685090.aspx)

Thread Local Storage
http://msdn2.microsoft.com/en-us/library/ms686749.aspx

(http://msdn2.microsoft.com/en-us/library/ms686749.aspx)

back to the top

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.