Status:
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
Steps to reproduce the problem:
You can reproduce this problem with the MFC DLL created using the following steps.
1. Start Visual C++ 2008 Service Pack 1.
2. Create a MFC DLL following the steps below:
(1) From the menu, choose File -> New -> Project to open the New Project dialog.
(2) In the Project Types list, do (A) or (B) below, and in the Name field, type a project name.
(A) Choose Visual C++ -> MFC -> MFC DLL Application
(B) Choose Visual C++ -> Win32 -> Win32 Console Application
(3) In the application wizard dialog, click the Application Settings page and set either of the following settings depending on the action you did in the step (2). Click the Finish button.
(A) [Visual C++] - [MFC] - [MFC DLL Application]
You should have chosen either of the following options in the Type of DLL:
- Regular DLL using shared MFC DLL
- Regular DLL with MFC statically linked
(B) [Visual C++] - [Win32] - [Win32 Console Application]
- Application type: Check the DLL checkbox.
- Add common header files for: Check the MFC checkbox.
- Additional options: Check the Precompiled header checkbox.
3. Again, choose File -> New -> Project to open the New Project dialog. In the New Project dialog, choose Visual C++ -> Win32 -> Win32 Console Application to create a new project. In the new project, use the LoadLibrary function to load the MFC DLL that you just created in the step 2 and then use the FreeLibrary function to unload it. This causes a memory leak.
Code Example:
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hinstLib = LoadLibrary(_T("MFCDLL.dll"));
FreeLibrary(hinstLib);
return 0;
}