Skip to content

Latest commit

 

History

History

dll-best-practices

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

DLL Best Practices

The "DLL Best Practices" whitepaper is Microsoft's original guidance laying out DLL best practices for the Windows platform, namely regarding DllMain.

The document was authored by Microsoft engineers, likely with some cooperation of the product manager (PM), who, at the time, owned the DLL loader. In my opinion, the document was good for its time, except for the main "General Best Practices" section, which throws rules at you without any structure or reasoning. People reading the old DllMain "General Best Practices" today (on Microsoft's documentation website, which has undergone a few updates) tend to come out more confused about DllMain safety than they were before. So, let's rewrite it with the perspective of an ecosystem where DllMain (global constructor/destructor or module initializer/deinitializer) problems don't happen to begin with. Enter... Unix-like operating systems!

Something worth pointing out is that Old New Thing author Raymond Chen didn't condone referencing his work in the official "DLL Best Practices" whitepaper. Many years have passed since this original statement; however, his extensive Windows experience inside Microsoft makes it nearly impossible not to reference his abundance of work in an educational manner, especially for someone outside of Microsoft who knows next to nothing about Windows internals like myself.

Be mindful of the fact that my critiques apply only to the software or company itself and not to the people who contribute to its development. I appreciate and respect the people who put hard work into creating the technologies. Thank you!

Note: This old document states the following about loader lock: "Any function that must read or modify the per-process library-loader data structures must acquire this lock before performing such an operation" (in addition to protecting module initialization/deinitialization). This fact was only true of the legacy Windows loader (e.g. see ReactOS code based on the reverse engineered Windows Server 2003 loader). The modern Windows loader protects library-loader data structures using the LdrpModuleDatatableLock lock. The age of this document also makes it inapplicable to the modern Windows loader in other ways (this amendment is by no means comprehensive).

Current official Microsoft download | Legacy download page archived