Dll加载订单

问题描述:

如果我在A.dll中有全局变量,这取决于B.dll中的全局变量,它是否保证B.dll将在A.dll之前加载?我在Visual Studio中做了两个示例dll项目,并将A.dll与B.dll链接起来,似乎这个B.dll是先加载的。这个行为是否保证?

If i have global variable in A.dll, that depends on global variable in B.dll , is it guaranteed that B.dll will be loaded before A.dll? I made two sample dll projects in Visual Studio, and link A.dll with B.dll , and it seems, that B.dll is loaded first.So is this behavior guaranteed ?

这个行为是由操作系统保证的,因为否则不可能编写正确的dll加载代码。特别是,如果 A.dll 导入 B.dll ,那么当动态链接器尝试加载 A.dll ,它会看到依赖关系,并将$ c> B.dll 加载到该进程中。

This behavior is guaranteed by the OS, because otherwise it would be impossible to write proper dll-loading code. In particular, if A.dll imports B.dll, then when the dynamic linker attempts to load A.dll, it will see that dependency and load B.dll into the process first.