PRB: Crash in DllMain After FreeLibrary is Called on a Resource DLL (241856)



The information in this article applies to:

  • Microsoft Visual C++ 4.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 4.2
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft Visual C++ .NET (2002)

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.

Modification Type:MajorLast Reviewed:12/11/2003
Keywords:kbDLL kbprb kbResource KB241856