CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2002
    Posts
    66

    Problem releasing CWebBrowser2

    Hi code gurus!

    I've been searching for information on how to solve this problem but I don't even have a clue.

    There is a memory leak when I close the mainframe of the application, I've detected when the webBrowser object is not created then this problem doesn't happen so I think maybe I'm not releasing something.

    Dumping objects ->
    C:\SYSTRAY2\Cliente\pantprot.cpp(58) : {124} client block at 0x00C01730, subtype 0, 60 bytes long.
    a CWebBrowser2 object at $00C01730, 60 bytes long
    Object dump complete.

    Some code:
    m_browser = new CWebBrowser2;
    BOOL btw;
    btw=m_browser->Create(NULL,NULL,WS_VISIBLE, rect, this, IDC_WBC);
    BOOL d=m_browser->DestroyWindow();
    free(m_browser);
    m_browser=NULL;

    But when i try to exit application this assertion is raised:

    CMDTARG.CPP

    CCmdTarget::~CCmdTarget()
    {
    #ifndef _AFX_NO_OLE_SUPPORT
    if (m_xDispatch.m_vtbl != 0)
    ((COleDispatchImpl*)&m_xDispatch)->Disconnect();
    ASSERT(m_dwRef <= 1); <------- current value m_dwRef = 2
    #endif
    #ifdef _AFXDLL
    m_pModuleState = NULL;
    #endif
    }

    Please help me because I don't even know what does this assertion means.
    As an additional information the dialog that contains this browser object is called within a thread, I don't know if this has something to do in this case.

    Regards
    Antonio

  2. #2
    Join Date
    Sep 2004
    Location
    A Planet Called Earth... :-)
    Posts
    835

    Re: Problem releasing CWebBrowser2

    Quote Originally Posted by Antonio Rmz-L
    Hi code gurus!
    free(m_browser);
    i think u should use delete

  3. #3
    Join Date
    Jan 2002
    Posts
    66

    Re: Problem releasing CWebBrowser2

    Thank you for your answer, but it is the same, the assertion is still raised. What does this mean?

    Antonio

  4. #4
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Thumbs up Re: Problem releasing CWebBrowser2

    Quote Originally Posted by Antonio Rmz-L
    the assertion is still raised. What does this mean?
    I don't know if creating an instance of CWebBrowser is the best way to do things.

    The Web Browser is available through IWebBrowser2.
    And this is a COM Interface.

    You must not intantiate the Class CWebBrowser2, rather you must create an instance of IWebBrowser2 interface using COM Methods like CoCreateInstance.

    Here is how you would create an Instance of your Web Browser
    Code:
      #include <Exdisp.h>
       
       // Declare a (Smart) Pointer to Interface IWebBrowser2
         CComQIPtr <IWebBrowser2> spMyWebBrowser;
       
       // Now, create an instance of the Web Browser 
         spMyWebBrowser.CoCreateInstance (CLSID_WebBrowser);
       
       // Use Interface pointer spMyWebBrowser to call Web Browser methods
    Hope, this solves your problem.
    Last edited by Siddhartha; June 2nd, 2005 at 05:41 PM.

  5. #5
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: Problem releasing CWebBrowser2

    Okay, now I get the hang of you using CWebBrowser2: Is it an MFC Application?

    If so, this tutorial tells how the Web Browser Control should be used in one.
    You can follow the steps there to create your control correctly.

  6. #6
    Join Date
    Jan 2002
    Posts
    66

    Re: Problem releasing CWebBrowser2

    Thanks for your information. I solved the problem by taking the dialog out of the thread. I still don't know why the assertion was rised but I solved it this way.

    Antonio

  7. #7
    Join Date
    Apr 2007
    Posts
    2

    Re: Problem releasing CWebBrowser2

    Can you tell me How you slove the problem? Thank you very much!

  8. #8
    Join Date
    Apr 2007
    Posts
    2

    Re: Problem releasing CWebBrowser2

    Can you tell me How you slove the problem? Thank you very much!

  9. #9
    Join Date
    Sep 2008
    Posts
    22

    Re: Problem releasing CWebBrowser2

    I have the same problem when I open dialog with WebBrowser control in it. The dialog is NOT in another thread. I don't know is this a very correct sollution, but I solved it with this code in the beginning of my application's ExitInstance() method:

    COleMessageFilter* pFilter = AfxOleGetMessageFilter();
    if ( pFilter )
    {
    ULONG lCount = pFilter->m_xMessageFilter.Release();
    if ( lCount < 1 )
    pFilter->m_xMessageFilter.AddRef();
    }

    The idea came from here:
    http://dotnet.itags.org/dotnet/352628/

    ----
    Edit: this sollution is not reliable. It is OK for the cases when ASSERT fires, but on some systems there is no assert with the same exe file and there my code leads to crash.
    Last edited by hi1; December 18th, 2009 at 06:54 AM. Reason: Not realiable sollution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured