views:

181

answers:

1
+1  Q: 

Dll loading order

Hello

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 ?

+5  A: 

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.

JSBangs
On msdn says that I can't call functions from User, Shell, and COM dlls in my DllMain. If it is guaranteed that User, Shell, and COM dlls will be loaded before mine ( like in the example above where B.dll is loaded before A.dll), then it should not be error to call these system dlls in DllMain of my dll. Sure I am not understanding something :( What I a missing ?
That's not the reason you can't call those functions. The real motivation is more complicated: http://blogs.msdn.com/oldnewthing/archive/2004/01/27/63401.aspx
JSBangs
Chris Becke