Microsoft KB Archive/241856

= PRB: Crash in DllMain After FreeLibrary is Called on a Resource DLL =

Article ID: 241856

Article Last Modified on 12/11/2003

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.2 Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q241856



SYMPTOMS
You may receive an access violation in DllMain after unloading a DLL using the FreeLibrary API call.



CAUSE
The DLL was a resource DLL with no entry point. The crash did not occur immediately after the FreeLibrary call, but rather later on. The resource DLL was loaded either by LoadLibrary or with LoadLibraryEx with the last parameter set to 0.



RESOLUTION
The resource DLL should be loaded with LoadLibraryEx instead and with the last parameter set to LOAD_LIBRARY_AS_DATAFILE.



STATUS
This behavior is by design.



MORE INFORMATION
A resource DLL does not have an entry point. You can verify that a DLL is resource-only by viewing the DLL import headers using the dumpbin utility that ships with Visual C++. You can use the following command from a command prompt to generate a text file for examination: dumpbin /headers mydll.dll > examine.txt

After running the above command, the text file Examine.txt is generated. If you open Examine.txt in a text editor, you can verify a DLL is a resource DLL by examining the value of RVA of entry point entry under the Optional Header Values section. If it is set to zero, then the DLL is a resource-only DLL.

Additional query words: Access Violation Win95 localize resources

Keywords: kbdll kbresource kbprb KB241856

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.