Larry Osterman's WebLog

Confessions of an Old Fogey
Blog - Title

Things you shouldn't do, part 1 - DllMain is special

Things you shouldn't do, part 1 - DllMain is special

  • Comments 5

A lot of people have written about things not to do in your DllMain.  Like here, and here and here.

One other thing not to do in your DllMain is to call LoadLibraryEx.  As others have written, DllMain’s a really special place to be.  If you do anything more complicated than initializing critical sections, or allocating thread local storage blocks, or calling DisableThreadLibraryCalls, you’re potentially asking for trouble.

Sometimes, however the interaction is much more subtle.  For example, if your DLL uses COM, you might be tempted to call CoInitializeEx in your DllMain.  The problem is that that under certain circumstances, CoInitializeEx can call LoadLibraryEx.  And calling LoadLibraryEx is one of the things that EXPLICITLY is forbidden during DllMain (You must not call LoadLibrary in the entry-point function).

 

Page 1 of 1 (5 items)