Dll loading order

2019-06-07 22:03发布

问题:

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 ?

回答1:

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.