新建一个单文档程序,我想在程序退出时释放一个DLL,我放在
CMainFrame::~CMainFrame()
{
  FreeLibrary(hDll);
}
中,但是释放过程好像没有执行,因为任务管理器中还有这处程序的进程.
但是在单步调试时,执行完FreeLibrary后,可以正常释放(任务管理器中进程立即没有了),
我想问两个问题
一是这是不是关系到编译选项的问题?
二是我如果不在析构函数中释放,是不是有别的地方?
另外,我在析构函数中加一MessageBox("A"),并没有对话框弹出!
疑惑中,希望有人解答,谢谢.

解决方案 »

  1.   

    问题解决了,在主框架的Ondestroy里释放就好了,但还是不明白为什么在析构函数里不行
      

  2.   

    DestroyWindow is a place holder for performing cleanup. Because DestroyWindow is a virtual function, it is shown in any CWnd-derived class in ClassWizard. But even though you override this function in your CWnd-derived class, DestroyWindow is not necessarily called. If DestroyWindow is not called in the MFC code, then you have to explicitly call it in your own code if you want it to be called.Assume, for example, you have overridden DestroyWindow in a CView-derived class. Since MFC source code does not call DestroyWindow in any of its CFrameWnd-derived classes, your overridden DestroyWindow will not be called unless you call it explicitly. If the window is the parent of any windows, these child windows are automatically destroyed when the parent window is destroyed. The DestroyWindow member function destroys child windows first and then the window itself. 
      

  3.   

    你在view的析构里试下FreeLibrary(hDll)你这里已说明它并没有自动调用啊,除非你F5手动去执行它