这些文件何时加载DLL:隐式链接VS显式链接 [英] When do these load DLLs : Implicit Linking VS Explicit Linking

查看:275
本文介绍了这些文件何时加载DLL:隐式链接VS显式链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为隐式链接会在应用程序启动后立即加载DLL,因为它也称为加载时动态链接".但是我在下面的链接中找到了一些奇怪的解释( https: //msdn.microsoft.com/zh-CN/library/253b8k2c(VS.80).aspx ).

I thought Implicit linking loads a DLL as soon as the application starts because it is also called "load-time dynamic linking". But I found some strange explanations below from the link here(https://msdn.microsoft.com/en-us/library/253b8k2c(VS.80).aspx).

隐式链接

与程序的其余代码一样,DLL代码也被映射到地址中 进程启动并加载到进程中时的空间 仅在需要时才存储.结果,PRELOAD和LOADONCALL代码 .def文件用于控制以前版本中的加载的属性 Windows不再具有意义.

Like the rest of a program's code, DLL code is mapped into the address space of the process when the process starts up and it is loaded into memory only when needed. As a result, the PRELOAD and LOADONCALL code attributes used by .def files to control loading in previous versions of Windows no longer have meaning.

显式链接

隐式链接到许多DLL的应用程序可能很慢 之所以开始,是因为Windows在应用程序加载时会加载所有DLL. 为了提高启动性能,应用程序可以隐式链接到 加载后立即需要并立即显式等待的那些DLL 需要时链接到其他DLL.

An application that implicitly links to many DLLs can be slow to start because Windows loads all the DLLs when the application loads. To improve startup performance, an application can implicitly link to those DLLs needed immediately after loading and wait to explicitly link to the other DLLs when they are needed.

另外一个关于从此处进行隐式链接的说明( https://msdn.microsoft .com/en-us/library/151kt790.aspx ).

And another explanation for implicit linking from here(https://msdn.microsoft.com/en-us/library/151kt790.aspx).

隐式链接

Visual C ++链接器现在支持DLL的延迟加载.这 无需使用Windows SDK函数LoadLibrary 和GetProcAddress来实现DLL延迟加载.

The Visual C++ linker now supports the delayed loading of DLLs. This relieves you of the need to use the Windows SDK functions LoadLibrary and GetProcAddress to implement DLL delayed loading.

在Visual C ++ 6.0之前,在运行时加载DLL的唯一方法是通过 使用LoadLibrary和GetProcAddress;操作系统将加载 加载可执行文件或使用它的DLL时的DLL.

Before Visual C++ 6.0, the only way to load a DLL at run time was by using LoadLibrary and GetProcAddress; the operating system would load the DLL when the executable or DLL using it was loaded.

从Visual C ++ 6.0开始,与DLL静态链接时, 链接器提供了一些选项来延迟DLL的加载,直到程序调用为止 该DLL中的功能.

Beginning with Visual C++ 6.0, when statically linking with a DLL, the linker provides options to delay load the DLL until the program calls a function in that DLL.

应用程序可以使用/DELAYLOAD(延迟加载)延迟加载DLL. 导入)带有帮助器功能的链接器选项(默认实现) 由Visual C ++提供). helper函数将在运行时加载DLL 通过致电 LoadLibrary GetProcAddress 来实现.

An application can delay load a DLL using the /DELAYLOAD (Delay Load Import) linker option with a helper function (default implementation provided by Visual C++). The helper function will load the DLL at run time by calling LoadLibrary and GetProcAddress for you.

我真的很困惑,不知道该怎么理解.

I'm really confused and don't know how to understand these.

1.隐式链接是在启动时还是仅在调用DLL中的函数时才加载DLL?

2.这意味着两者最终都是相似的,因为LoadLibrary()是在后台调用的?

推荐答案

@ remy-lebeau在他的评论中提供了很好的解释.我会在这里尝试作为答案.

@remy-lebeau provided a good explanation in his comment. I'll try to elaborate here as an answer.

解释了隐式和显式dll加载之间的区别

The difference between implicit and explicit dll loading is explained here. In short:

  • 显式加载中,应用程序通过显式调用LoadLibrary来加载dll.
  • 隐式加载中,应用程序在编译时指定dll,Windows loader在运行时加载它.
  • In explicit loading, the application loads the dll by calling LoadLibrary explicitly.
  • In implicit loading, the application specifies the dll in compile time, and Windows loader loads it in run time.

隐式加载具有许多优点,但是由于在此阶段加载了所有dll,因此减慢了应用程序的加载时间.

Implicit loading has many advantages, but it slows the application loading time because all of the dlls are loaded during this stage.

为解决此问题,Microsoft支持

To solve this issue, Microsoft supports Delayed Loaded Dlls, which is a type of implicit loading.

通过使用它,您可以享受隐式加载的所有好处,但是仅当您的应用程序调用其函数之一时,才会加载dll.

By using it you can enjoy all of the benefits of implicit loading, but the dll will be loaded only when your application will call one of its functions.

对您的问题:

  1. 在隐式加载中,如果您未将dll指定为延迟加载,则它将在应用程序启动时加载.如果您这样做了,它将在首次使用时加载.
  2. 是的.在所有情况下,DLL均已加载并映射到应用程序内存.

这篇关于这些文件何时加载DLL:隐式链接VS显式链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆