duilib duilib introductory tutorial portion 14. Concise Guide bug 2

On a tutorial mentioned in the ActiveX of Bug, i.e. if the main window is generated directly by a variable, then the window is closed to cause a crash 
     

    if the new generation manner, will not collapse, it is given a temporary quick solution, i.e., primary are used to generate new window, _tWinMain read like the following:

  1. int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
  2. {
  3.     CPaintManagerUI::SetInstance(hInstance);
  4.     HRESULT Hr = ::CoInitialize(NULL);
  5.     if( FAILED(Hr) ) return 0;
  6.     CDuiFrameWnd * pFrame = new CDuiFrameWnd; // here must be new, or when there is an ActiveX control, close the window to cause a crash
  7.     pFrame->Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
  8.     pFrame->CenterWindow();
  9.     pFrame->ShowModal();
  10.     delete pFrame;
  11.     ::CoUninitialize();
  12.     return 0;
  13. }
Copy the code




    The fundamental reason is that the ActiveX control COM uses a similar way, but did not control the scope, resulting in destructor, CActiveXCtrl member variable m_pViewObject at the memory no longer valid, thus creating a crash. The reason why a new way not crash out because new memory, even after the object destruction, its memory is still valid.


    Because it uses a similar COM behavior, there are several delete this, but Alberl do not understand Microsoft's own internal COM and ActiveX is how to deal with, so it could not be evaluated duilib COM and ActiveX, of course, Alberl or debugging and we found that several classes ActiveXUI.cpp inside the COM are analog manner, reference counted, but that several classes of Release chaotic sequence looks like a little, and that each comprise several classes, this has led destructor those problems due Alberl current focus is on writing introductory tutorial, combined with limited, short-term can not solve the problem fundamentally, seating and other friends ~ ~ ~ great God

    in [ 2013 duilib concise Guide to Getting Started - combined with win32 and MFC (16) ] if such use were found in the MFC, there will not be a problem, please let us know the great God ~ (^ o ^) / ~

Guess you like

Origin www.cnblogs.com/blogpro/p/11427093.html