|
-
June 1st, 2005, 07:51 PM
#1
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
-
June 2nd, 2005, 12:59 AM
#2
Re: Problem releasing CWebBrowser2
 Originally Posted by Antonio Rmz-L
Hi code gurus!
free(m_browser);
i think u should use delete
-
June 2nd, 2005, 12:56 PM
#3
Re: Problem releasing CWebBrowser2
Thank you for your answer, but it is the same, the assertion is still raised. What does this mean?
Antonio
-
June 2nd, 2005, 05:37 PM
#4
Re: Problem releasing CWebBrowser2
 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.
-
June 2nd, 2005, 05:45 PM
#5
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.
-
June 3rd, 2005, 03:39 PM
#6
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
-
April 15th, 2007, 04:45 AM
#7
Re: Problem releasing CWebBrowser2
Can you tell me How you slove the problem? Thank you very much!
-
April 15th, 2007, 05:12 AM
#8
Re: Problem releasing CWebBrowser2
Can you tell me How you slove the problem? Thank you very much!
-
December 9th, 2009, 11:11 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|