My team maintained the NT loader (the component that loads DLLs) for about a year or so during Windows XP as we were adding the isolated application features to it so we got quite an interesting perspective on this lovely little piece of technology. Warning to people who find themselves wanting to innovate in technology which has basically been left dormant and untouched for over a decade: be sure you have plenty of time to deal with the anthills you knock over!
We don't own it any more (not sure if it's a blessing or a curse...) but it sure was interesting and enlightening; especially in the tradeoffs of application compatibility, robustness and reliability.
You might notice that the docs for DllMain have grown a lot over the past few years. I like to think that my team's involvement here had a lot to do with it because DLL load order etc. was always a vaguely understood and arcane topic. There were always vague warnings about not doing too much in DLL_PROCESS_ATTACH but nobody could really describe the situation except for a number of anecdotes they had had in the past when somehow mysteriously load orders changed and they were broken during either initialization or shutdown.
I'll take a break from where I'm headed on the reliability front and walk through a summary of the issues which I recently sent to the internal win32 programming email alias. Hopefully I'll fix the incomplete sentances and bad grammar this time.
I'll make a separate post with the beginning - a basic rundown of how things work today. As usual, do not consider this in any way shape or form a contract. One of the reasons that this isn't documented fully is that people have wanted to change/fix it for years and years now. On the other hand, maintaining compatibility with the current behavior is going to constrain the implementation so much that either (a) it won't change after all or (b) the change will have to be compatible with the effects of anything I'm describing here anyways.
You will see aspects of my reliability/robustness series come up here. You'll laugh, you'll cry, you'll see local innocuous bugs in DLL initialization or uninitialization affect the entire process's reliability.