PRB: FreeLibrary() Fails When Called Within DLL_PROCESS_DETACH Code

ID: Q214784


The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), included with:
    • Microsoft Windows 98


SYMPTOMS

In Windows 98, FreeLibrary() will return FALSE if it is called within the DLL_PROCESS_DETACH code of DllMain().


CAUSE

Never call LoadLibrary() or FreeLibrary() within DllMain(). These calls can create dependency loops and result in thread deadlock. This has always been the case and is made clear within the Warning section in the online documentation for DllMain().

In Windows 95, the operating system made no attempt to enforce this DLL serialization rule. Hence, an unsafe call to FreeLibrary() within DllMain() would return TRUE. Windows 98 returns FALSE for such a call in order to more strictly enforce this rule. This may cause problems for pre-existing code that did not heed the warning.


STATUS

This behavior is by design.

Additional query words:

Keywords : kbDLL kbKernBase
Version : winnt:
Platform : winnt
Issue type : kbprb


Last Reviewed: April 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.