<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx</link><description>The dependent would become the dependee.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9828752</link><pubDate>Fri, 10 Jul 2009 17:21:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9828752</guid><dc:creator>Alexandre Grigoriev</dc:creator><description>&lt;P&gt;I don't get your point about KERNEL32.DLL. It doesn't need to uninitialize anything in PROCESS_DETACH. You can't unload it. When it's time for it to go, the process is on the way down.&lt;/P&gt;
&lt;DIV class=post&gt;[&lt;I&gt;You're getting too caught up in implementation details and missing the point of the article. -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9828756</link><pubDate>Fri, 10 Jul 2009 17:23:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9828756</guid><dc:creator>Tom</dc:creator><description>&lt;P&gt;Editorial note: &amp;nbsp;The sentence fragment 'even if doing so is cannot be proven to be reliable.' has a superfluous 'is' and should be 'even if doing so cannot be proven to be reliable.'.&lt;/P&gt;
&lt;DIV class=post&gt;[&lt;I&gt;Fixed. Thanks. -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9828769</link><pubDate>Fri, 10 Jul 2009 17:44:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9828769</guid><dc:creator>Mark (The other Mark)</dc:creator><description>&lt;p&gt;&amp;quot;If somebody told you, &amp;quot;Hey, we added this feature that isn't reliable,&amp;quot; I suspect your reaction would not be &amp;quot;Awesome, let me start depending on it!&amp;quot;&amp;quot;&lt;/p&gt;
&lt;p&gt;My reaction might not be, but I suspect many people would say exactly that. Check out Raymond Chen's blog, especially the parts about compatibility shims, or people depending on undocumented implementation details... :-)&lt;/p&gt;
&lt;p&gt;Note: The Smiley indicates this is intended to be a &amp;quot;funny&amp;quot; comment, as many entries in your blog point out that yes, people are silly enough to depend on unreliable behavior.&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9828779</link><pubDate>Fri, 10 Jul 2009 17:57:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9828779</guid><dc:creator>Someone You Know</dc:creator><description>&lt;p&gt;&amp;quot;...all the dynamically-loaded DLLs would find themselves in an interesting world where KERNEL32.DLL no longer existed.&amp;quot;&lt;/p&gt;
&lt;p&gt;This reminds me of that supposedly ancient curse that goes: &amp;quot;May you live in interesting times.&amp;quot;&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829046</link><pubDate>Fri, 10 Jul 2009 23:16:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829046</guid><dc:creator>Peter Bindels</dc:creator><description>&lt;p&gt;This is exactly why there is no definite implementation of a singleton in C++ (or any other language for that matter) - you have the same kind of fake dependencies, where the order of destruction is wrong no matter how you construct them.&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829071</link><pubDate>Fri, 10 Jul 2009 23:55:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829071</guid><dc:creator>porter</dc:creator><description>&lt;p&gt;&amp;gt;&amp;gt; shouldn't call anything outside your DLL from your DllMain function (except perhaps a little bit of KERNEL32 but even then, it's still not the best idea). &lt;/p&gt;
&lt;p&gt;What about initializing my DLL's global critical section?&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829169</link><pubDate>Sat, 11 Jul 2009 02:22:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829169</guid><dc:creator>Anonymous Coward</dc:creator><description>&lt;p&gt;&amp;gt;What about initializing my DLL's global critical section?&lt;/p&gt;
&lt;p&gt;It is safe to call other functions in Kernel32.dll, because this DLL is guaranteed to be loaded in the process address space when the entry-point function is called. It is common for the entry-point function to create synchronization objects such as critical sections and mutexes, and use TLS. Do not call the registry functions, because they are located in Advapi32.dll. If you are dynamically linking with the C run-time library, do not call malloc; instead, call HeapAlloc.&lt;/p&gt;
&lt;p&gt;-the Platform SDK&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829247</link><pubDate>Sat, 11 Jul 2009 05:07:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829247</guid><dc:creator>Doug</dc:creator><description>&lt;p&gt;What I find amusing, having been down the Dllmain path many times, from the MSDN reading developer perspective, is the number of rules that are either not written or described in a cryptic manner.&lt;/p&gt;
&lt;p&gt;It wouldn't have been so bad, except that Visual Basic liked to unload DLLs at times other than process death, meaning you HAD to make sure your threads were stopped. &amp;nbsp;No matter what they were doing. &amp;nbsp;Getting that to work correctly is not a simple task.&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829594</link><pubDate>Sat, 11 Jul 2009 17:37:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829594</guid><dc:creator>Karellen</dc:creator><description>&lt;P&gt;"A.DLL loads B.DLL [...] You want the dependency to be that A.DLL depends on B.DLL"&lt;/P&gt;
&lt;P&gt;And that's where things have gotten backwards.&lt;/P&gt;
&lt;P&gt;If RANDOM.DLL depends on CORE.DLL (e.g. kernel32.dll), then CORE.DLL must be loaded and intialised *before* RANDOM.DLL, and CORE.DLL must be around until after RANDOM.DLL has been released/unloaded.&lt;/P&gt;
&lt;P&gt;If RANDOM.DLL dynamically loads MODULE.DLL, then it follows that RANDOM.DLL must have been loaded, initialised and running before MODULE.DLL. It is therefore inherently erroneous to say that RANDOM.DLL "depends on" MODULE.DLL. If anything, you'd want to introduce a fake dependency saying that the dynamically loaded MODULE.DLL depends on RANDOM.DLL.&lt;/P&gt;
&lt;P&gt;That way, if RANDOM.DLL starts to go away, you'd want to unload MODULE.DLL *first*, releasing your resources in the opposite order to that which they were acquired. However, that cannot work in the general case because it's possible in the semantics of that application for RANDOM.DLL to have "transferred ownership/cleanup responsibility" of MODULE.DLL to CORE.DLL, and CORE.DLL might still be using MODULE.DLL.&lt;/P&gt;
&lt;DIV class=post&gt;[&lt;I&gt;And if we followed your rules, then all delay-loads would have backwards dependencies. FANCY.DLL uses WININET.DLL only in certain scenarios, so instead of declaring a load-time dependency, it loads WININET.DLL on demand. According to your logic, this means that WININET.DLL depends on FANCY.DLL and therefore WININET.DLL should be shut down before FANCY.DLL. When FANCY.DLL calls InternetCloseHandle() in its DLL_PROCESS_DETACH, it ends up calling into a DLL that has already been uninitialized. -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829768</link><pubDate>Sun, 12 Jul 2009 02:04:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829768</guid><dc:creator>John</dc:creator><description>&lt;P&gt;&amp;gt;When FANCY.DLL calls InternetCloseHandle() in its DLL_PROCESS_DETACH, it ends up calling into a DLL that has already been uninitialized.&lt;/P&gt;
&lt;P&gt;Good! &amp;nbsp;Serves the bastards right for breaking the DllMain contract. &amp;nbsp;But I guess Microsoft wouldn't know anything about that. &amp;nbsp;Do you guys enjoy being slaves to design/compatibility decisions made 25+ years ago? &amp;nbsp;I bet there is an alternate dimension where Windows 7 only allows 8.3 filenames.&lt;/P&gt;
&lt;DIV class=post&gt;[&lt;I&gt;You missed the underlying counterfactual, which was "If Windows tracked DLL dependencies better, then we wouldn't need these crazy rules about DLL_PROCESS_DETACH." Your argument is therefore circular: "Changing the rules by tracking dependencies better is a bad idea because that would make it possible to change the rules!" -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829820</link><pubDate>Sun, 12 Jul 2009 04:18:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829820</guid><dc:creator>porter</dc:creator><description>&lt;p&gt;&amp;gt;&amp;gt; It wouldn't have been so bad, except that Visual Basic liked to unload DLLs at times other than process death, meaning you HAD to make sure your threads were stopped.&lt;/p&gt;
&lt;p&gt;32bit OS/2 required all threads to terminate before a process ended.&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829864</link><pubDate>Sun, 12 Jul 2009 06:25:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829864</guid><dc:creator>John</dc:creator><description>&lt;p&gt;I understand that, but my comment wasn't specifically aimed at this topic; it was more about (breaking) backward compatibility in general.&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9829928</link><pubDate>Sun, 12 Jul 2009 08:08:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829928</guid><dc:creator>Aaron Margosis</dc:creator><description>&lt;p&gt;@John - yes, compatibility is a bitch. &amp;nbsp;But throwing away compatibility hurts customers (which hurts business). &amp;nbsp;So you just acknowledge it and deal with it.&lt;/p&gt;
&lt;p&gt;It's hardly unique to Microsoft, though, or to the software industry. &amp;nbsp;Look around and you'll see all kinds of decisions based on backward compatibility. &amp;nbsp;E.g., &amp;quot;cigarette lighter&amp;quot; jacks in (American) cars becoming the standard form factor for power outlets.&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9831564</link><pubDate>Mon, 13 Jul 2009 15:45:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9831564</guid><dc:creator>bahbar</dc:creator><description>&lt;p&gt;@Aaron, &lt;/p&gt;
&lt;p&gt;Actually, those jacks are probably one of the best followed de facto standards throughout the world. Try and plug a US standard power plug in Europe, and then try your car-jack plug. Guess which one works...&lt;/p&gt;
</description></item><item><title>re: If dynamic DLL dependencies were tracked, they'd be all backwards</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/07/10/9827869.aspx#9831779</link><pubDate>Mon, 13 Jul 2009 18:16:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9831779</guid><dc:creator>Aaron Margosis</dc:creator><description>&lt;p&gt;@bahbar - I didn't want to assume that what's true in the US is true around the world, but I'm not surprised that this one is. &amp;nbsp;The point is, though, that if you were designing a standard form factor for a power outlet, would your first idea be something that you could easily stick large fingers or thumbs into? &amp;nbsp;Oh - and the English language itself. &amp;nbsp;It's a total mess, but it's what we've got.&lt;/p&gt;
</description></item></channel></rss>